Author: colin Date: 2010-02-22 22:07:49 +0100 (Mon, 22 Feb 2010) New Revision: 35576 Changeset: http://dev.haiku-os.org/changeset/35576/haiku Added: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/ieee80211_request.h Removed: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/DeviceContext.h Modified: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/ieee80211.cpp haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/ieee80211_control.cpp haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/ieee80211_control.h haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/ieee80211_device.h haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Device.h haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Stack.cpp haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Stack.h Log: * Refactored stack to be a per device instance. - In the long run this makes it easier to introduce the state pattern, where the stack can change behaviour on the fly (acting in ad-hoc, client or access point mode) by changing its implementation. - Also getting rid of the need for a per device context. This allows for cleaner method calls, as the parameter count can be reduced. Modified: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/ieee80211.cpp =================================================================== --- haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/ieee80211.cpp 2010-02-22 19:03:34 UTC (rev 35575) +++ haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/ieee80211.cpp 2010-02-22 21:07:49 UTC (rev 35576) @@ -30,12 +30,9 @@ #include <ieee80211_control.h> #include <ieee80211_device.h> -#include <Stack.h> - net_buffer_module_info* gBufferModule; static net_stack_module_info* sStackModule; -Ieee80211::Stack gIeee80211Stack; // #pragma mark - @@ -60,8 +57,7 @@ memset(device, 0, sizeof(ieee80211_device)); - status = gIeee80211Stack.CreateDevice(name, - &device->genericDevice); + status = device->stack.InitCheck(); if (status != B_OK) { delete device; put_module(NET_BUFFER_MODULE_NAME); @@ -86,7 +82,6 @@ ieee80211_device* device = reinterpret_cast<ieee80211_device*>(_device); - gIeee80211Stack.DeleteDevice(device->genericDevice); delete device; put_module(NET_BUFFER_MODULE_NAME); @@ -97,20 +92,20 @@ status_t ieee80211_up(net_device* _device) { - Ieee80211::Device* device - = reinterpret_cast<ieee80211_device*>(_device)->genericDevice; + Ieee80211::Stack& stack + = reinterpret_cast<ieee80211_device*>(_device)->stack; - return gIeee80211Stack.ActivateDevice(device); + return stack.Activate(); } void ieee80211_down(net_device* _device) { - Ieee80211::Device* device - = reinterpret_cast<ieee80211_device*>(_device)->genericDevice; + Ieee80211::Stack& stack + = reinterpret_cast<ieee80211_device*>(_device)->stack; - gIeee80211Stack.DeactivateDevice(device); + stack.Deactivate(); } @@ -197,12 +192,6 @@ if (status < B_OK) return status; - status = gIeee80211Stack.InitCheck(); - if (status != B_OK) { - put_module(NET_STACK_MODULE_NAME); - return status; - } - return B_OK; } Modified: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/ieee80211_control.cpp =================================================================== --- haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/ieee80211_control.cpp 2010-02-22 19:03:34 UTC (rev 35575) +++ haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/ieee80211_control.cpp 2010-02-22 21:07:49 UTC (rev 35576) @@ -10,16 +10,13 @@ #include <ieee80211_control.h> #include <ieee80211_device.h> -#include <stack/Stack.h> +#include <Stack.h> using namespace Ieee80211; using namespace StationManagement; -extern Stack gIeee80211Stack; - - /*! Handles flow of information from the Station Management Entity. For retrieving data from the Station Management Entity (SME), like getting properties or detected wireless networks. @@ -52,18 +49,17 @@ if (_device == NULL || _request == NULL) return B_BAD_VALUE; - Device* device = _device->genericDevice; + Stack& stack = _device->stack; Request<RequestResult>* request = NULL; - gIeee80211Stack.SetupRequestConverter(device, _request); - status_t status = gIeee80211Stack.ConvertToStationManagementRequest( + status_t status = stack.ConvertToStationManagementRequest(_request, &request); if (status != B_OK) return status; switch (_request->type) { case IEEE80211_IOC_CONNECT: - status = gIeee80211Stack.ConnectToNetwork( + status = stack.ConnectToNetwork( reinterpret_cast<ConnectRequest*>(request)); break; default: Modified: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/ieee80211_control.h =================================================================== --- haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/ieee80211_control.h 2010-02-22 19:03:34 UTC (rev 35575) +++ haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/ieee80211_control.h 2010-02-22 21:07:49 UTC (rev 35576) @@ -9,34 +9,9 @@ #include <SupportDefs.h> #include <ieee80211_device.h> +#include <ieee80211_request.h> -/* #pragma mark - request types */ - - -enum request_t { - IEEE80211_IOC_CHANNEL, /* get/set channel number */ - IEEE80211_IOC_BSSID, /* get/set BSSID of desired WLAN */ - IEEE80211_IOC_CONNECT /* connect to a specific WLAN */ -}; - - -/* #pragma mark - request structures */ - - -struct request_data { - uint16 lengthInByte; - void* data; -}; -typedef struct request_data request_data_t; - -struct ieee80211req { - request_t type; - request_data_t data; -}; -typedef struct ieee80211req ieee80211req_t; - - status_t ieee80211_from_management(ieee80211_device*, ieee80211req_t*); status_t ieee80211_to_management(ieee80211_device*, ieee80211req_t*); Modified: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/ieee80211_device.h =================================================================== --- haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/ieee80211_device.h 2010-02-22 19:03:34 UTC (rev 35575) +++ haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/ieee80211_device.h 2010-02-22 21:07:49 UTC (rev 35576) @@ -10,12 +10,12 @@ #include <util/DoublyLinkedList.h> -#include <stack/Device.h> +#include <Stack.h> -struct ieee80211_device : net_device, +struct ieee80211_device : net_device, DoublyLinkedListLinkImpl<ieee80211_device> { - Ieee80211::Device* genericDevice; + Ieee80211::Stack stack; }; #endif /* IEEE80211_DEVICE_H_ */ Added: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/ieee80211_request.h =================================================================== --- haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/ieee80211_request.h (rev 0) +++ haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/ieee80211_request.h 2010-02-22 21:07:49 UTC (rev 35576) @@ -0,0 +1,34 @@ +/* + * Copyright 2010 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef IEEE80211_IEEE80211_REQUEST_H_ +#define IEEE80211_IEEE80211_REQUEST_H_ + + +/* #pragma mark - request types */ + + +enum request_t { + IEEE80211_IOC_CHANNEL, /* get/set channel number */ + IEEE80211_IOC_BSSID, /* get/set BSSID of desired WLAN */ + IEEE80211_IOC_CONNECT /* connect to a specific WLAN */ +}; + + +/* #pragma mark - request structures */ + + +struct request_data { + uint16 lengthInByte; + void* data; +}; +typedef struct request_data request_data_t; + +struct ieee80211req { + request_t type; + request_data_t data; +}; +typedef struct ieee80211req ieee80211req_t; + +#endif /* IEEE80211_IEEE80211_REQUEST_H_ */ Modified: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Device.h =================================================================== --- haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Device.h 2010-02-22 19:03:34 UTC (rev 35575) +++ haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Device.h 2010-02-22 21:07:49 UTC (rev 35576) @@ -8,9 +8,7 @@ #include <SupportDefs.h> -#include <DeviceContext.h> - namespace Ieee80211 { class Device { @@ -22,7 +20,6 @@ private: int fFileDescriptor; - DeviceContext fDeviceContext; }; } /* namespace Ieee80211 */ Modified: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Stack.cpp =================================================================== --- haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Stack.cpp 2010-02-22 19:03:34 UTC (rev 35575) +++ haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Stack.cpp 2010-02-22 21:07:49 UTC (rev 35576) @@ -37,57 +37,13 @@ } -/*! Create an Ieee80211::Device. - - \param haikuDeviceName is the name used by Haiku to identify this device. - \param devicePointer used to return the pointer to the created - Ieee80211::Device. - \return B_OK Ieee80211::Device created successfully and is safe to use. - \return B_BAD_VALUE At least on of the parameters is a NULL pointer. - \return B_NO_MEMORY Not enough memory to create a Ieee80211::Device; - \sa Ieee80211::Device::InitCheck() for more error reasons. - */ -status_t -Stack::CreateDevice(const char* haikuDeviceName, - Device** devicePointer) -{ - if (haikuDeviceName == NULL || devicePointer == NULL) - return B_BAD_VALUE; - - *devicePointer = new(std::nothrow) Device(); - if (*devicePointer == NULL) - return B_NO_MEMORY; - - status_t status = (*devicePointer)->InitCheck(); - if (status != B_OK) { - delete *devicePointer; - *devicePointer = NULL; - } - - return status; -} - - -/*! Frees all resources occupied by the Ieee80211::Device. - - \param device used to identify the resources to be freed. - */ -void -Stack::DeleteDevice(Device* device) -{ - delete(device); - return; -} - - /*! Activates processing of management and data frames. - \param device to be enabled for processing of management and data frames. - \return B_OK Ieee80211::Device successfully enabled. - \return B_ERROR Ieee80211::Device still disabled. + \return B_OK Stack successfully enabled. + \return B_ERROR Stack still disabled, due to an unrecoverable error. */ status_t -Stack::ActivateDevice(Device* device) +Stack::Activate() { return B_OK; } @@ -97,30 +53,18 @@ When this method returns all queued frames were processed and processing of new ones is disabled. - \param device to be disabled for processing of management and data frames. + \return B_OK Stack successfully disabled. + \return B_ERROR Stack still enabled, due to an unrecoverable error. */ -void -Stack::DeactivateDevice(Device* device) +status_t +Stack::Deactivate() { - return; + return B_OK; } -/*! Initializes the request converter with the data it needs for converting. +/*! Converts a system request into a request as needed by station management. - \param device delivers device specific data. - \param request to be converted. - */ -void -Stack::SetupRequestConverter(Device* device, ieee80211req_t* request) -{ - return; -} - - -/*! Utilizes the request converter to convert a system request into a request as - needed by the station management. - \param request only used to return the converted request. Memory allocation is carried out by this method. \return B_OK Request was successfully converted and is safe for further @@ -128,7 +72,8 @@ \return B_ERROR Request couldn't be converted. */ status_t -Stack::ConvertToStationManagementRequest(Request<RequestResult>** request) +Stack::ConvertToStationManagementRequest(ieee80211req_t* _request, + Request<RequestResult>** request) { return B_OK; } Modified: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Stack.h =================================================================== --- haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Stack.h 2010-02-22 19:03:34 UTC (rev 35575) +++ haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Stack.h 2010-02-22 21:07:49 UTC (rev 35576) @@ -8,9 +8,8 @@ #include <SupportDefs.h> -#include <ieee80211_control.h> +#include <ieee80211_request.h> -#include <Device.h> #include <interfaces/Request.h> #include <station_management/Roster.h> #include <station_management/requests/ConnectRequest.h> @@ -23,13 +22,10 @@ public: status_t InitCheck(); - status_t CreateDevice(const char*, Device**); - void DeleteDevice(Device*); - status_t ActivateDevice(Device*); - void DeactivateDevice(Device*); + status_t Activate(); + status_t Deactivate(); - void SetupRequestConverter(Device*, ieee80211req_t*); - status_t ConvertToStationManagementRequest( + status_t ConvertToStationManagementRequest(ieee80211req_t*, Request<StationManagement::RequestResult>**); status_t ConnectToNetwork(StationManagement::ConnectRequest*);