NetBurner 3.5.7
PDF Version
nbWifiMsgStructs.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
9#ifndef __NBWICEDMSGSTRUCTS_H
10#define __NBWICEDMSGSTRUCTS_H
11
12#include <nettypes.h>
13#include <string.h>
14#include <wifi/nbWifiConstants.h>
15
16// #define HTONS(x) (x)
17// #define HTONL(x) (x)
18// #define htons(x) (x)
19// #define htonl(x) (x)
20
21#define BufferToObjPtr(buffer, objType) ((objType *)((uint8_t *)((buffer)->pData) + (buffer)->usedsize))
22#define AddToBuffLen(buffer, msgPtr) (buffer)->usedsize += sizeof(*msgPtr)
23#define GetSafeLength(val, max) ((val) <= (max)) ? (val) : (max)
24
25#define MESSAGE_TYPE_BIT_OFFSET 4
26#define TYPELEN_FIELD_LEN (sizeof(NB::NBWifiAPIMessage::Header::lenType))
27#define _STRUCT_PACKED __attribute__((__packed__))
28#define MAX_HARDWARE_TYPE_LENGTH 64
29
31//
32// Enum Definitions
33//
35namespace NB
36{
37namespace NBWifiAPIMessage
38{
39namespace Header
40{
41typedef enum
42{
43 Type_API_Request = 0x0,
44 Type_API_Response = 0x1,
45 Type_Credit_Report = 0x2,
46 Type_Data_Raw = 0x3,
47 Type_Data_CompressedIP = 0x4,
48 Type_Internal = 0x7,
49} ApiMessageTypes;
50}
51namespace Request
52{
53typedef enum
54{
55 Type_Config = 0x0,
56 Type_Connect_Start = 0x1,
57 Type_Disconnect_Stop = 0x2,
58 Type_Scan = 0x3,
59 Type_SetMAC = 0x4,
60 Type_SaveConfig = 0x5,
61 Type_GetCredits = 0x6,
62 Type_SetBusSpeed = 0x7,
63 Type_ReadyFirmware = 0x8,
64 Type_FirmwareChunk = 0x9,
65 Type_VerifyAndProgFirm = 0xA,
66 Type_AddRemoveMulticast = 0xB,
67 Type_SetITUCountry = 0xC,
68 Type_GetStatus = 0xFD,
69 Type_GetDeviceInfo = 0xFE,
70 Type_GetOptionTable = 0xFF
71} RequestTypes;
72}
73namespace Response
74{
75typedef enum
76{
77 Type_Scan_Result = 0x0,
78 Type_Status = 0x1,
79 Type_DeviceInfo = 0x2,
80 Type_OptionTableResp = 0x3,
81} ResponseTypes;
82}
83namespace Internal
84{
85typedef enum
86{
87 Type_Internal_JoinAP = 0x0,
88 Type_Internal_SendStatus = 0x1,
89 Type_Internal_Reconnect = 0x2,
90} InternalTypes;
91}
92
93} // namespace NBWifiAPIMessage
94} // namespace NB
95
97//
98// Structure Definitions
99//
101namespace NB
102{
103namespace NBWifiAPIMessage
104{
105// Header structures
106namespace Header
107{
108struct _STRUCT_PACKED lenType
109{
110 beuint16_t val;
111 beuint16_t xorVal;
112};
113struct _STRUCT_PACKED APIRequest
114{
115 lenType lengthAndType;
116 uint8_t requestType;
117 uint8_t commandID;
118 uint8_t pData[];
119};
120struct _STRUCT_PACKED APIResponse
121{
122 lenType lengthAndType;
123 uint8_t responseType;
124 uint8_t commandID;
125 int32_t returnCode;
126 // beint32_t returnCode;
127 // uint8_t returnCode;
128 uint8_t pData[];
129};
130struct _STRUCT_PACKED CreditReport
131{
132 lenType lengthAndType;
133 uint8_t availableCredits;
134};
135struct _STRUCT_PACKED Data_Raw
136{
137 lenType lengthAndType;
138 uint8_t availableCredits;
139 uint8_t pData[];
140};
141struct _STRUCT_PACKED Data_CompressedIP
142{
143 lenType lengthAndType;
144 uint8_t connectionID;
145 uint8_t availableCredits;
146 uint8_t pData[];
147};
148struct _STRUCT_PACKED Internal
149{
150 lenType lengthAndType;
151 uint8_t messageType;
152 uint8_t commandID;
153};
154} // namespace Header
155
156// Request structures
157namespace Request
158{
159struct _STRUCT_PACKED ConfigReq
160{
161 uint8_t optionCount;
162 uint8_t ssidLength;
163 uint8_t passwdLength;
164 uint8_t padding;
165 char options[]; // Placeholder for char array pobe_inter
166};
167struct _STRUCT_PACKED ConnectStart
168{
169 uint8_t configNum;
170 uint8_t flags;
171 uint8_t retryCount;
172};
173struct _STRUCT_PACKED Scan
174{
175 uint8_t optionCount;
176 uint8_t ssidLength;
177 char options[]; // Placeholder for char array pobe_inter
178};
179struct _STRUCT_PACKED SetMAC
180{
181 MACADR newMAC;
182};
183struct _STRUCT_PACKED SaveConfig
184{
185 uint8_t configNum;
186};
187struct _STRUCT_PACKED SetBusSpeed
188{
189 beuint32_t busSpeed;
190};
191struct _STRUCT_PACKED FirmwareChunk
192{
193 beuint32_t offset;
194 beuint16_t length;
195 beuint16_t checksum;
196 uint8_t pData[];
197};
198struct _STRUCT_PACKED VerifyAndProgFirm
199{
200 beuint32_t imageLength;
201 beuint32_t checksum[4];
202};
203struct _STRUCT_PACKED AddRemoveMulticast
204{
205 uint8_t flags;
206 MACADR theMac;
207};
208struct _STRUCT_PACKED SetITUCountry
209{
210 uint8_t length;
211 uint8_t pData[];
212};
213struct _STRUCT_PACKED GetTableReq
214{
215 uint8_t tableNum;
216};
217} // namespace Request
218
219// Response structures
220namespace Response
221{
222struct _STRUCT_PACKED ScanResult
223{
224 uint8_t lastAndBand;
225 uint8_t bssType;
226 uint8_t channel;
227 uint8_t security;
228 uint8_t cipher;
229 uint8_t ssidLength;
230 beint16_t rssi;
231 MACADR bssid;
232 char ssid[]; // Placeholder for char array pobe_inter
233};
234struct _STRUCT_PACKED Status
235{
236 uint8_t connected;
237 uint8_t bssType;
238 uint8_t security;
239 uint8_t cipher;
240 beuint32_t maxTxRate;
241 beuint16_t rssi;
242 uint8_t band;
243 uint8_t channel;
244 beuint16_t txPower;
245 MACADR bssid;
246 uint8_t ssidLength;
247 char ssid[]; // Placeholder for char array pobe_inter
248};
249struct _STRUCT_PACKED DeviceInfo
250{
251 uint8_t hardwareMajorRev;
252 uint8_t hardwareMinorRev;
253 uint8_t softwareMajorRev;
254 uint8_t softwareMinorRev;
255 MACADR hardwareID;
256 uint8_t hardwareTypeLength;
257 char hardwareType[MAX_HARDWARE_TYPE_LENGTH + 1]; // allow extra space for null terminating char
258};
259struct _STRUCT_PACKED OptionTable
260{
261 struct Entry
262 {
263 uint8_t value;
264 uint8_t labelLength;
265 char label[]; // Placeholder for char array
266 };
267 beuint16_t flagsAndEntryCount;
268 uint8_t tableNum;
269 Entry entries[];
270};
271} // namespace Response
272} // namespace NBWifiAPIMessage
273} // namespace NB
274
276//
277// Function declarations
278//
280namespace NB
281{
282namespace NBWifiAPIMessage
283{
284namespace Header
285{
286void WriteHeader_APIRequest(PoolPtr messageBuffer,
287 bool additionalFlag,
288 NB::NBWifiAPIMessage::Request::RequestTypes requestType,
289 uint8_t commandID);
290void WriteHeader_APIResponse(PoolPtr messageBuffer,
291 bool additionalFlag,
292 NB::NBWifiAPIMessage::Response::ResponseTypes responseType,
293 uint8_t commandID,
294 int32_t returnCode);
295void FixHeader_Length(PoolPtr messageBuffer);
296void WriteHeader_Data_Raw(PoolPtr messageBuffer, bool additionalFlag, uint16_t length);
297void WriteHeader_Data_CompressedIP(PoolPtr messageBuffer, bool additionalFlag, uint16_t length, uint8_t connectionID);
298void WriteCreditReport(PoolPtr messageBuffer, bool additionalFlag, uint16_t length, uint8_t availableCredits);
299bool VerifyChecksum(NB::NBWifiAPIMessage::Header::lenType lengthAndType);
300} // namespace Header
301namespace Request
302{
303void WriteMsg_ConfigReq(PoolPtr messageBuffer,
304 const char *ssid,
305 uint8_t ssidLength,
306 const char *passwd,
307 uint8_t passwdLength,
308 uint16_t *optionList,
309 uint8_t optionCount);
310void WriteMsg_ConnectStart(PoolPtr messageBuffer, uint8_t configNumber, bool scan, uint8_t retryCount);
311void WriteMsg_SetMAC(PoolPtr messageBuffer, const MACADR *newMAC);
312void WriteMsg_SetITUCountry(PoolPtr messageBuffer, NB::ITU_Country::CountryCode_t country);
313void WriteMsg_SetBusSpeed(PoolPtr messageBuffer, uint32_t busSpeed);
314void WriteMsg_SaveConfig(PoolPtr messageBuffer, uint32_t busSpeed);
315void WriteMsg_FirmwareChunk(PoolPtr messageBuffer, uint32_t offset, uint16_t dataLen, uint16_t checksum, const uint8_t *data);
316void WriteMsg_VerifyAndProgFirm(PoolPtr messageBuffer, uint32_t imageLen, const uint32_t *checksum);
317void WriteMsg_AddRemoveMulticast(PoolPtr messageBuffer, bool AddNotRemove, const MACADR *mac);
318void WriteMsg_Scan(PoolPtr messageBuffer, uint8_t optionCount, uint16_t *optionList, uint8_t ssidLength, const char *ssid);
319} // namespace Request
320namespace Response
321{
322void WriteMsg_ScanResult(PoolPtr messageBuffer,
323 bool last,
324 Constants::RadioBand band,
325 Constants::BssType bssType,
326 uint8_t channel,
327 uint8_t security,
328 uint8_t cipher,
329 int16_t rssi,
330 const MACADR *pBssid,
331 const char *ssid,
332 int ssidLength);
333void WriteMsg_Status(PoolPtr messageBuffer,
334 uint8_t connected,
335 int16_t txPower,
336 int16_t rssi,
337 uint16_t channel,
338 uint32_t maxTxRate,
339 uint32_t security,
340 const MACADR *pBssid,
341 uint8_t bssType,
342 const char *ssid,
343 uint8_t ssidLength);
344void WriteMsg_DeviceInfo(PoolPtr messageBuffer,
345 uint8_t hardwareMajorRev,
346 uint8_t hardwareMinorRev,
347 uint8_t softwareMajorRev,
348 uint8_t softwareMinorRev,
349 const MACADR *pHardwareID,
350 const char *hardwareType,
351 uint8_t hardwareTypeLength);
352} // namespace Response
353} // namespace NBWifiAPIMessage
354} // namespace NB
355
356#endif /* ----- #ifndef __NBWICEDMSGSTRUCTS_H ----- */
Used to store and manipulate MAC addresses.
Definition nettypes.h:69
Main buffer structure for network and serial communication.
Definition buffers.h:90