From 6ba2a6764de2021e65d4d42a593371d3a3b49315 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Sun, 11 May 2008 20:07:11 +0000 Subject: [PATCH] * Reset the connection state and speed when the underlaying device is removed. * Notify the stack of this by releasing the link state change sem (if present). * Also check for a removed device in the notify callback to prevent accessing a device that is going down. Removing the device under Haiku with an active link will now report the loss of connection. Still left to implement is to reuse a still existing device if the same device (based on its MAC) is replugged. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25459 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/drivers/network/usb_ecm/ECMDevice.cpp | 16 ++++++++++++++-- .../kernel/drivers/network/usb_ecm/ECMDevice.h | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/add-ons/kernel/drivers/network/usb_ecm/ECMDevice.cpp b/src/add-ons/kernel/drivers/network/usb_ecm/ECMDevice.cpp index fda5bb21aa..3490d58467 100644 --- a/src/add-ons/kernel/drivers/network/usb_ecm/ECMDevice.cpp +++ b/src/add-ons/kernel/drivers/network/usb_ecm/ECMDevice.cpp @@ -372,6 +372,18 @@ ECMDevice::Control(uint32 op, void *buffer, size_t length) } +void +ECMDevice::Removed() +{ + fRemoved = true; + fHasConnection = false; + fDownstreamSpeed = fUpstreamSpeed = 0; + + if (fLinkStateChangeSem >= B_OK) + release_sem_etc(fLinkStateChangeSem, 1, B_DO_NOT_RESCHEDULE); +} + + status_t ECMDevice::_ReadMACAddress() { @@ -432,10 +444,10 @@ void ECMDevice::_NotifyCallback(void *cookie, int32 status, void *data, uint32 actualLength) { - if (status == B_CANCELED) + ECMDevice *device = (ECMDevice *)cookie; + if (status == B_CANCELED || device->fRemoved) return; - ECMDevice *device = (ECMDevice *)cookie; if (status == B_OK && actualLength >= sizeof(cdc_notification)) { bool linkStateChange = false; cdc_notification *notification diff --git a/src/add-ons/kernel/drivers/network/usb_ecm/ECMDevice.h b/src/add-ons/kernel/drivers/network/usb_ecm/ECMDevice.h index 12e50d37e6..991d4b1712 100644 --- a/src/add-ons/kernel/drivers/network/usb_ecm/ECMDevice.h +++ b/src/add-ons/kernel/drivers/network/usb_ecm/ECMDevice.h @@ -25,7 +25,7 @@ public: status_t Write(const uint8 *buffer, size_t *numBytes); status_t Control(uint32 op, void *buffer, size_t length); - void Removed() { fRemoved = true; }; + void Removed(); bool IsRemoved() { return fRemoved; }; private: