NetBurner 3.1
netDevice.h
1 /*NB_REVISION*/
2 
3 /*NB_COPYRIGHT*/
4 
5 #ifndef _NETDEVICE_H_
6 #define _NETDEVICE_H_
7 
8 #include <device.h>
9 
10 /*
11  ******************************************************************************
12  *
13  * Include Files
14  *
15  ******************************************************************************
16  */
17 
18 /*
19  ******************************************************************************
20  *
21  * Debugging
22  *
23  ******************************************************************************
24  */
25 /* Library debugging switch */
26 #define NETDEVICE_DEVICE_DEBUG (1)
27 
28 /*
29  ******************************************************************************
30  *
31  * Constants
32  *
33  ******************************************************************************
34  */
35 /* Maximum Network Devices */
36 #define NETDEVICE_DEVICE_MAXIMUM (5)
37 
38 /*
39  NetworkAddInterface Returns
40 
41  NETDEVICE_REQUEST_FAILED - Was not added by the system
42  NETDEVICE_MODULE_NOT_FOUND - Module not detected
43  NETDEVICE_ALREADY_EXISTS - Already exists
44  NETDEVICE_SUPPORT_TASK_FAILED - Driver task not created
45 
46 */
47 
48 #define NETDEVICE_REQUEST_FAILED (0)
49 #define NETDEVICE_MODULE_NOT_FOUND (-1)
50 #define NETDEVICE_ALREADY_EXISTS (-2)
51 #define NETDEVICE_SUPPORT_TASK_FAILED (-3)
52 #define NETDEVICE_MODULE_NOT_SUPPORTED (-4)
53 
54 /* List requests */
55 #define NETDEVICE_SITE_COUNT (1)
56 #define NETDEVICE_SITE_LIST (2)
57 
58 /*
59  Security supplicant actions
60 
61  NETDEVICE_INITIALIZE - Initialize
62  NETDEVICE_UPDATE_KEY - Update key
63 
64 */
65 #define NETDEVICE_INITIALIZE (0)
66 #define NETDEVICE_UPDATE_PASSPHRASE (1)
67 #define NETDEVICE_GET_TEMPORAL_KEY (2)
68 
69 /*
70  ******************************************************************************
71  *
72  * Enumerations
73  *
74  ******************************************************************************
75  */
76 /*
77  Network interface controller (NIC)
78 
79  ControllerNone - No controller
80  ControllerPointToPoint - Point-to-Point data link protocol
81  ControllerRealtekRtl8711 - Realtek IEEE 802.11g
82 
83  */
84 typedef enum _NetDeviceController
85 {
86  ControllerNone,
87  ControllerPointToPoint,
88  ControllerRealtekRtl8711
89 
90 } NetDeviceController;
91 
92 /*
93  Network interface controller (NIC) bus type used
94 
95  BusTypeNone - No bus
96  BusTypeMemoryMapped - External data bus access
97  BusTypeSdioBusType - Secure Digital Input Output (SDIO)
98  BusTypeSdioBusSpiMode - SDIO using SPI mode
99  BusTypeSpiBus - Serial Peripheral Interface (SPI)
100 
101  */
102 typedef enum _NetDeviceBusType
103 {
104  BusTypeNone,
105  BusTypeMemoryMapped,
106  BusTypeSdioBusType,
107  BusTypeSdioBusSpiMode,
108  BusTypeSpiBus
109 
110 } NetDeviceBusType;
111 
112 /*
113  Select details (chip select)
114 
115  Chip select are either managed (asserted/deasserted by the processor
116  module (e.g. (Q)SPI module) or unmanaged and handled by the driver.
117 
118  The (Q)SPI module supports connecting additional hardware that using
119  the (Q)SPI chip selects can select several devices (multiplex) up to 15.
120 
121  SelectDetailNone - No chip select
122  SelectDetailSpiUnmanaged - Single signal unmanaged chip select
123  SelectDetailSpiUnmanagedMultiplex - Multiplexed unmanaged chip select
124  SelectDetailSpiManaged - Single signal managed chip select
125  SelectDetailSpiManagedMultiplex - Multiplexed managed chip select
126  SelectDetailGpioUnmanaged - Single signal unmanaged chip select
127 
128  Changing the ordering of these parameters require complete system and platform
129  rebuilds.
130 
131 */
132 
133 typedef enum _NetDeviceSelectDetail
134 {
135  SelectDetailNone,
136  SelectDetailSpiUnmanaged,
137  SelectDetailSpiUnmanagedMultiplex,
138  SelectDetailSpiManaged,
139  SelectDetailSpiManagedMultiplex,
140  SelectDetailGpioUnmanaged,
141 
142 } NetDeviceSelectDetail;
143 
144 /*
145  ******************************************************************************
146  *
147  * C++ definitions
148  *
149  ******************************************************************************
150  */
151 
152 /*
153  ******************************************************************************
154  *
155  * Routine Prototypes
156  *
157  ******************************************************************************
158  */
159 /* Device management */
160 typedef void(NetDeviceProgressFn)(int activity, int progress, const char *detail);
161 typedef NetDeviceProgressFn *NetDeviceProgressFnPtr;
162 
163 /* Security supplicant */
164 typedef BOOL(NetDeviceSupplicantFn)(int action, void *buffer);
165 typedef NetDeviceSupplicantFn *NetDeviceSupplicantFnPtr;
166 
167 /*
168  ******************************************************************************
169  *
170  * Classes
171  *
172  ******************************************************************************
173  */
174 /*
175  ******************************************************************************
176  * Network Device Base Class
177  ******************************************************************************
178  */
179 class NetDevice
180 {
181  public:
182  /*** Constructor ***/
183  NetDevice(int irq, NetDeviceController controller, NetDeviceBusType busType, int select, NetDeviceSelectDetail selectDetails);
184 
185  /*** Destructor ***/
186  virtual ~NetDevice();
187 
188  /*** Copy Constructor ***/
189  /* Default */
190 
191  /*** Static Methods ***/
192  /* Verify platform support, create controller object */
193  static int add(int irq, NetDeviceController controller, NetDeviceBusType busType, int select, NetDeviceSelectDetail selectDetails);
194 
195  /* Get network device */
196  static NetDevice *getNetDevice(int deviceIndex);
197 
198  /*** Methods ***/
199  /* Setup bus for controller */
200  virtual BOOL setupBus(void);
201 
202  /* Setup ISR */
203  virtual BOOL setupIsr(DeviceIsrFnPtr isrFunction, int irq);
204 
205  /* Determine existence of controller on bus */
206  virtual BOOL probe(void);
207 
208  /* Initialize controller in idle state, add to network stack */
209  virtual BOOL open(void);
210 
211  /* Reset controller to quiescent idle state */
212  virtual BOOL close(void);
213 
214  /* Remove controller from network stack */
215  virtual BOOL remove(void);
216 
217  /* Configure and retrieve settings */
218  virtual BOOL configure(int request, ssize_t parameterSize, void *parameterPtr);
219  virtual BOOL retrieveSetting(int setting, ssize_t settingSize, void *settingPtr);
220 
221  /* List */
222  virtual BOOL list(int request, ssize_t &listSize, void *listPtr);
223 
224  /* Network name */
225  virtual void getNetworkName(char *name, ssize_t maximumBytes);
226 
227  /* Survey network */
228  virtual BOOL surveyNetwork(char *site);
229 
230  /* Connect */
231  virtual BOOL connect(const char *identifier = NULL, const char *securityKey = NULL, int securityDetail = 0, int mode = 0);
232 
233  /* Disconnect */
234  virtual BOOL disconnect(void);
235 
236  /*** Network stack routines ***/
237  /* Transmit packet */
238  virtual BOOL transmitPacket(PoolPtr poolPtr);
239 
240  /* Set/Reset multicast */
241  virtual void resetMulticast(MACADDRESS_48 macAddress, BOOL addAddress);
242 
243  /*** Accessors ***/
244  /* Access stack interface number */
245  void setInterfaceNumber(int interfaceNumber);
246  int getInterfaceNumber(void) const;
247 
248  /* Get number */
249  int getNumber(void) const;
250 
251  /* Get name */
252  char *getName(void);
253 
254  /* Get unit */
255  int getUnit(void) const;
256 
257  /* Get controller */
258  NetDeviceController getController(void) const;
259 
260  /* Get bus type */
261  NetDeviceBusType getBusType(void) const;
262 
263  /* Get select */
264  int getSelect(void) const;
265 
266  /* Get select */
267  NetDeviceSelectDetail getSelectDetail(void) const;
268 
269  /* Get MAC address */
270  virtual BOOL getMacAddress(MACADDRESS_48 &macAddress);
271 
272  /* Connected? */
273  virtual BOOL isConnected(void);
274 
275  /* Progress routine */
276  virtual void setProgressRoutine(NetDeviceProgressFnPtr routinePtr);
277 
278  /* Security supplicant routine */
279  virtual void setSupplicant(NetDeviceSupplicantFnPtr routinePtr);
280 
281  /* Set/Get ticks per second */
282  void setTicksPerSecond(unsigned short ticksPerSecond);
283  unsigned int getTicksPerSecond(void) const;
284 
285  /* Signal interrupt */
286  virtual void signalInterrupt(void);
287 
288  /* Valid? */
289  BOOL isValid(void) const;
290 
291  protected:
292  /* Set name */
293  void setName(const char *namePtr);
294 
295  /* Set unit */
296  void setUnit(int unit);
297 
298  /* Set valid */
299  void setValid(BOOL valid) const;
300 
301  private:
302  /*** Methods ***/
303  /* None */
304 
305  /*** Data Members ***/
306  /* Index in __device */
307  int __index;
308 
309  /* Name */
310  char *__namePtr;
311 
312  /* Unit */
313  int __unit;
314 
315  /* IRQ */
316  int __irq;
317 
318  /* Controller */
319  NetDeviceController __controller;
320 
321  /* Bus */
322  NetDeviceBusType __busType;
323 
324  /* Select */
325  int __select;
326 
327  /* Select */
328  NetDeviceSelectDetail __selectDetail;
329 
330  /* Interface number */
331  int __interfaceNumber;
332 
333  /* Ticks per second (Can be modified by developer) */
334  unsigned short __ticksPerSecond;
335 
336  /* Valid */
337  BOOL __valid;
338 
339  /*** Static Data Members ***/
340  /* One time initialization */
341  static BOOL __isInitialized;
342 
343  /* Critical section for mutex */
344  static OS_CRIT __criticalSection;
345 
346  /* Interface objects */
347  static NetDevice *__device[NETDEVICE_DEVICE_MAXIMUM];
348 };
349 
350 /*
351  ******************************************************************************
352 
353  Verify availability and support for device.
354 
355 
356  Parameters:
357  irq - Fixed level interrupt source
358  controller - IEEE 802.11g controller
359  busType - Bus used by the controller
360 
361 
362  Return:
363  TRUE - Support and available on module, FALSE option not supported
364 
365  Note:
366  Does not verify controller is attached and operational.
367 
368  ******************************************************************************
369  */
370 BOOL NetDeviceIsValid(int irq, NetDeviceController controller, NetDeviceBusType busType);
371 
372 /*
373  ******************************************************************************
374 
375  Get device handle
376 
377 
378  Parameters:
379  irq - Fixed level interrupt source
380  controller - IEEE 802.11g controller
381  busType - Bus used by the controller
382  select - Chip select is bus specific
383  SDIO using SPI mode (BusTypeSdioBusSpiMode)
384  0 - 3 (Q)SPI chip select lines QSPI_CS[0:3]
385 
386  Return:
387  Handle - Supported and available on module,
388  NULL interface not supported
389 
390  Note:
391  Verify parameters and platform support for device.
392  Does not verify controller is attached and operational.
393 
394  ******************************************************************************
395  */
396 NetDevice *NetDeviceGetDevice(int irq,
397  NetDeviceController controller,
398  NetDeviceBusType busType,
399  int select,
400  NetDeviceSelectDetail selectDetails);
401 
402 /* Device Realtek RTL8711 Controller on SDIO bus in SPI mode */
403 NetDevice *NetDeviceGetDeviceRtl8711SdioSpi(int irq, int select, NetDeviceSelectDetail selectDetails);
404 
405 #endif /* _NETDEVICE_H_ */
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, unsigned long timeout)
This function waits for events to occur on one or more I/O resources associated with a set of file de...
Definition: iosys.cpp:362
int close(int fd)
This function closes the resources associated with a file descriptor (fd). This can be a TCP socket o...
Definition: fileio.cpp:99
An OS_CRIT object is used to establish critical sections of code that can only be run by one task at ...
Definition: nbrtos.h:893
#define NULL
Definition: nm_bsp.h:76