-
Notifications
You must be signed in to change notification settings - Fork 39
/
WTPBinding.c
759 lines (613 loc) · 22.6 KB
/
WTPBinding.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
/************************************************************************************************
* Copyright (c) 2006-2009 Laboratorio di Sistemi di Elaborazione e Bioingegneria Informatica *
* Universita' Campus BioMedico - Italy *
* *
* This program is free software; you can redistribute it and/or modify it under the terms *
* of the GNU General Public License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with this *
* program; if not, write to the: *
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, *
* MA 02111-1307, USA. *
* *
* -------------------------------------------------------------------------------------------- *
* Project: Capwap *
* *
* Authors : Ludovico Rossi ([email protected]) *
* Del Moro Andrea ([email protected]) *
* Giovannini Federica ([email protected]) *
* Massimo Vellucci ([email protected]) *
* Mauro Bisson ([email protected]) *
* Antonio Davoli ([email protected]) *
************************************************************************************************/
#include "wireless_copy.h"
#include "CWWTP.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <signal.h>
#ifdef DMALLOC
#include "../dmalloc-5.5.0/dmalloc.h"
#endif
int CWTranslateQueueIndex(int j)
{
if (j == VOICE_QUEUE_INDEX)
return 3;
if (j == VIDEO_QUEUE_INDEX)
return 2;
if (j == BACKGROUND_QUEUE_INDEX)
return 1;
return 0;
}
#ifdef SOFTMAC
CWBool CWWTPInitBinding(int radioIndex)
{
bindingValues *aux;
int i;
CW_CREATE_OBJECT_ERR(aux, bindingValues, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
);
gRadiosInfo.radiosInfo[radioIndex].bindingValuesPtr = (void *)aux;
CW_CREATE_ARRAY_ERR(aux->qosValues, NUM_QOS_PROFILES, WTPQosValues,
return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
);
for (i = 0; i < NUM_QOS_PROFILES; i++) {
/* TODO: Get info from Hostapd UNIX DOMAIN SOCKET */
aux->qosValues[i].cwMin = 3;
aux->qosValues[i].cwMax = 15;
aux->qosValues[i].AIFS = 2;
}
return CW_TRUE;
}
#else
#ifndef BCM
CWBool CWWTPInitBinding(int radioIndex)
{
bindingValues *aux;
int i, sock;
struct iwreq wrq;
/*** Inizializzazione socket ***/
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0) {
CWLog("Error Creating Socket for ioctl");
return CW_FALSE;
}
/*** Inizializzazione struttura iwreq ***/
memset(&wrq, 0, sizeof(wrq));
strncpy(wrq.ifr_name, gInterfaceName, IFNAMSIZ);
CWLog("wrq.ifr_name %s ", wrq.ifr_name);
CW_CREATE_OBJECT_ERR(aux, bindingValues, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
);
gRadiosInfo.radiosInfo[radioIndex].bindingValuesPtr = (void *)aux;
CW_CREATE_ARRAY_ERR(aux->qosValues, NUM_QOS_PROFILES, WTPQosValues,
return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
);
for (i = 0; i < NUM_QOS_PROFILES; i++) {
/*
* Donato Capitella - TO_REMOVE_DEVELOP
* Commented the following lines just to make the WTP work in a test machine.
*/
//if(!get_cwmin(sock, &wrq, CWTranslateQueueIndex(i), 0)){return CW_FALSE;}
//aux->qosValues[i].cwMin = wrq.u.param.value;
//if(!get_cwmax(sock, &wrq, CWTranslateQueueIndex(i), 0)){return CW_FALSE;}
//aux->qosValues[i].cwMax = wrq.u.param.value;
//if(!get_aifs(sock, &wrq, CWTranslateQueueIndex(i), 0)){return CW_FALSE;}
//aux->qosValues[i].AIFS = wrq.u.param.value;
/*## aux->qosValues[i].cwMin = 2;
aux->qosValues[i].cwMax = 4;
aux->qosValues[i].AIFS = 3;
*/
}
return CW_TRUE;
}
#else
CWBool CWWTPInitBinding(int radioIndex)
{
bindingValues *aux;
int i;
CW_CREATE_OBJECT_ERR(aux, bindingValues, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
);
gRadiosInfo.radiosInfo[radioIndex].bindingValuesPtr = (void *)aux;
CW_CREATE_ARRAY_ERR(aux->qosValues, NUM_QOS_PROFILES, WTPQosValues,
return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
);
for (i = 0; i < NUM_QOS_PROFILES; i++) {
/*Daniele: i driver Broadcom non permettono get sulle WME: setto i parametri del Qos a valori costanti */
aux->qosValues[i].cwMin = 2;
aux->qosValues[i].cwMax = 4;
aux->qosValues[i].AIFS = 3;
}
return CW_TRUE;
}
#endif
#endif
#ifdef SOFTMAC
CWBool CWBindingSetQosValues(int qosCount, RadioQosValues * radioQosValues, CWProtocolResultCode * resultCode)
{
if (qosCount <= 0) {
return CW_TRUE;
}
if (radioQosValues == NULL) {
return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
}
*resultCode = CW_PROTOCOL_SUCCESS;
int i, k, j;
for (i = 0; i < qosCount; i++) {
for (k = 0; k < gRadiosInfo.radioCount; k++) {
if (radioQosValues[i].radioID == gRadiosInfo.radiosInfo[k].radioID) {
bindingValues *auxPtr = (bindingValues *) gRadiosInfo.radiosInfo[k].bindingValuesPtr;
for (j = 0; j < NUM_QOS_PROFILES; j++) {
CWLog("AIFS: %d %d", auxPtr->qosValues[j].AIFS,
radioQosValues[i].qosValues[j].AIFS);
int aifs = (int)radioQosValues[i].qosValues[j].AIFS;
int burst_time = 0;
if (j == 0)
burst_time = 15;
else if (j == 1)
burst_time = 30;
if (set_txq
(j, radioQosValues[i].qosValues[j].cwMin,
radioQosValues[i].qosValues[j].cwMax, aifs, burst_time)) {
auxPtr->qosValues[j].cwMin = radioQosValues[i].qosValues[j].cwMin;
auxPtr->qosValues[j].cwMax = radioQosValues[i].qosValues[j].cwMax;
auxPtr->qosValues[j].AIFS = radioQosValues[i].qosValues[j].AIFS;
} else {
*resultCode = CW_PROTOCOL_FAILURE;
}
/*
if(auxPtr->qosValues[j].cwMin!=radioQosValues[i].qosValues[j].cwMin)
{
if (set_wme_cwmin(CWTranslateQueueIndex(j), radioQosValues[i].qosValues[j].cwMin))
{auxPtr->qosValues[j].cwMin=radioQosValues[i].qosValues[j].cwMin;}
else {*resultCode=CW_PROTOCOL_FAILURE;}
}
if(auxPtr->qosValues[j].cwMax!=radioQosValues[i].qosValues[j].cwMax)
{
if (set_wme_cwmax(CWTranslateQueueIndex(j), radioQosValues[i].qosValues[j].cwMax))
{auxPtr->qosValues[j].cwMax=radioQosValues[i].qosValues[j].cwMax;}
else {*resultCode=CW_PROTOCOL_FAILURE;}
}
if(auxPtr->qosValues[j].AIFS!=radioQosValues[i].qosValues[j].AIFS)
{
if (set_wme_aifsn(CWTranslateQueueIndex(j), radioQosValues[i].qosValues[j].AIFS))
{auxPtr->qosValues[j].AIFS=radioQosValues[i].qosValues[j].AIFS;}
else {*resultCode=CW_PROTOCOL_FAILURE;}
}
*/
}
break;
}
}
}
return CW_TRUE;
}
#else
#ifndef BCM
CWBool CWBindingSetQosValues(int qosCount, RadioQosValues * radioQosValues, CWProtocolResultCode * resultCode)
{
struct iwreq wrq;
int sock;
if (qosCount <= 0) {
return CW_TRUE;
}
if (radioQosValues == NULL) {
return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
}
*resultCode = CW_PROTOCOL_SUCCESS;
/*** Inizializzazione socket ***/
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0) {
CWLog("Error Creating Socket for ioctl");
return CWErrorRaise(CW_ERROR_GENERAL, NULL);;
}
/*** Inizializzazione struttura iwreq ***/
memset(&wrq, 0, sizeof(wrq));
strncpy(wrq.ifr_name, gInterfaceName, IFNAMSIZ);
int i, k, j;
for (i = 0; i < qosCount; i++) {
for (k = 0; k < gRadiosInfo.radioCount; k++) {
if (radioQosValues[i].radioID == gRadiosInfo.radiosInfo[k].radioID) {
bindingValues *auxPtr = (bindingValues *) gRadiosInfo.radiosInfo[k].bindingValuesPtr;
for (j = 0; j < NUM_QOS_PROFILES; j++) {
if (auxPtr->qosValues[j].cwMin != radioQosValues[i].qosValues[j].cwMin) {
if (set_cwmin
(sock, wrq, CWTranslateQueueIndex(j), 0,
radioQosValues[i].qosValues[j].cwMin)) {
auxPtr->qosValues[j].cwMin =
radioQosValues[i].qosValues[j].cwMin;
} else {
*resultCode = CW_PROTOCOL_FAILURE;
}
}
if (auxPtr->qosValues[j].cwMax != radioQosValues[i].qosValues[j].cwMax) {
if (set_cwmax
(sock, wrq, CWTranslateQueueIndex(j), 0,
radioQosValues[i].qosValues[j].cwMax)) {
auxPtr->qosValues[j].cwMax =
radioQosValues[i].qosValues[j].cwMax;
} else {
*resultCode = CW_PROTOCOL_FAILURE;
}
}
if (auxPtr->qosValues[j].AIFS != radioQosValues[i].qosValues[j].AIFS) {
if (set_aifs
(sock, wrq, CWTranslateQueueIndex(j), 0,
radioQosValues[i].qosValues[j].AIFS)) {
auxPtr->qosValues[j].AIFS = radioQosValues[i].qosValues[j].AIFS;
} else {
*resultCode = CW_PROTOCOL_FAILURE;
}
}
}
break;
}
}
}
//WTPQosValues* aux=radioQosValues;
close(sock);
return CW_TRUE;
}
#else
CWBool CWBindingSetQosValues(int qosCount, RadioQosValues * radioQosValues, CWProtocolResultCode * resultCode)
{
if (qosCount <= 0) {
return CW_TRUE;
}
if (radioQosValues == NULL) {
return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
}
*resultCode = CW_PROTOCOL_SUCCESS;
int i, k, j;
for (i = 0; i < qosCount; i++) {
for (k = 0; k < gRadiosInfo.radioCount; k++) {
if (radioQosValues[i].radioID == gRadiosInfo.radiosInfo[k].radioID) {
bindingValues *auxPtr = (bindingValues *) gRadiosInfo.radiosInfo[k].bindingValuesPtr;
for (j = 0; j < NUM_QOS_PROFILES; j++) {
if (auxPtr->qosValues[j].cwMin != radioQosValues[i].qosValues[j].cwMin) {
if (set_wme_cwmin
(CWTranslateQueueIndex(j), radioQosValues[i].qosValues[j].cwMin)) {
auxPtr->qosValues[j].cwMin =
radioQosValues[i].qosValues[j].cwMin;
} else {
*resultCode = CW_PROTOCOL_FAILURE;
}
}
if (auxPtr->qosValues[j].cwMax != radioQosValues[i].qosValues[j].cwMax) {
if (set_wme_cwmax
(CWTranslateQueueIndex(j), radioQosValues[i].qosValues[j].cwMax)) {
auxPtr->qosValues[j].cwMax =
radioQosValues[i].qosValues[j].cwMax;
} else {
*resultCode = CW_PROTOCOL_FAILURE;
}
}
if (auxPtr->qosValues[j].AIFS != radioQosValues[i].qosValues[j].AIFS) {
if (set_wme_aifsn
(CWTranslateQueueIndex(j), radioQosValues[i].qosValues[j].AIFS)) {
auxPtr->qosValues[j].AIFS = radioQosValues[i].qosValues[j].AIFS;
} else {
*resultCode = CW_PROTOCOL_FAILURE;
}
}
}
break;
}
}
}
return CW_TRUE;
}
#endif
#endif
/**************************************************************
* Update 2009: OFDM Message Element Management *
**************************************************************/
CWBool CWManageOFDMValues(CWBindingConfigurationUpdateRequestValuesOFDM * ofdmValues, CWProtocolResultCode * resultCode)
{
if (ofdmValues == NULL) {
return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
}
*resultCode = CW_PROTOCOL_SUCCESS;
OFDMControlValues *radioValues = ofdmValues->radioOFDMValues;
//unsigned char radioID = ofdmValues->radioID;
struct sockaddr_in serv_addr;
int sendSock, slen = sizeof(serv_addr);
if ((sendSock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
CWLog("[FreqAnalyzer]: Error on creation of socket.");
return CWErrorRaise(CW_ERROR_GENERAL, NULL);
}
memset(&serv_addr, 0, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(FREQ_SERVER_PORT);
if (inet_aton(FREQ_SERVER_ADDR, &serv_addr.sin_addr) == 0) {
CWLog("[CWManageOFDMValue]: Error on aton function.");
close(sendSock);
return CWErrorRaise(CW_ERROR_GENERAL, NULL);
}
/********************************************************************
* Update 2009: OFDM Management *
* *
* Send a OFDMControlValues to wtpFreqManager. *
* In this function there is the control switch for the different *
* type of commands. *
********************************************************************/
if (sendto(sendSock, radioValues, sizeof(OFDMControlValues), 0, (struct sockaddr *)&serv_addr, slen) < 0) {
CWLog("[CWManageOFDMValue]: Error on sendto function.");
close(sendSock);
return CWErrorRaise(CW_ERROR_GENERAL, NULL);
}
close(sendSock);
return CW_TRUE;
}
CWBool CWParseWTPOFDM(CWProtocolMessage * msgPtr, int len, unsigned char *radioID, OFDMControlValues * valPtr)
{
CWParseMessageElementStart();
*radioID = CWProtocolRetrieve8(msgPtr);
valPtr->currentChan = CWProtocolRetrieve32(msgPtr);
valPtr->BandSupport = (unsigned char)CWProtocolRetrieve8(msgPtr);
valPtr->TIThreshold = (unsigned int)CWProtocolRetrieve32(msgPtr);
CWParseMessageElementEnd();
}
CWBool CWParseWTPQoS(CWProtocolMessage * msgPtr, int len, unsigned char *radioID, unsigned char *tagPackets,
WTPQosValues * valPtr)
{
int i;
CWParseMessageElementStart();
*radioID = CWProtocolRetrieve8(msgPtr);
*tagPackets = CWProtocolRetrieve8(msgPtr);
for (i = 0; i < NUM_QOS_PROFILES; i++) {
valPtr[i].queueDepth = (unsigned char)CWProtocolRetrieve8(msgPtr);
valPtr[i].cwMin = CWProtocolRetrieve16(msgPtr);
valPtr[i].cwMax = CWProtocolRetrieve16(msgPtr);
valPtr[i].AIFS = (unsigned char)CWProtocolRetrieve8(msgPtr);
valPtr[i].dot1PTag = (unsigned char)CWProtocolRetrieve8(msgPtr);
valPtr[i].DSCPTag = (unsigned char)CWProtocolRetrieve8(msgPtr);
}
CWParseMessageElementEnd();
}
CWBool CWBindingSaveConfigurationUpdateRequest(void *bindingValuesPtr, CWProtocolResultCode * resultCode,
int *updateRequestType)
{
if (bindingValuesPtr == NULL) {
return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
}
*resultCode = CW_PROTOCOL_SUCCESS;
switch (*updateRequestType) {
case BINDING_MSG_ELEMENT_TYPE_WTP_QOS:{
CWBindingConfigurationUpdateRequestValues *bindingPtr =
(CWBindingConfigurationUpdateRequestValues *) bindingValuesPtr;
if (bindingPtr->qosCount > 0) {
if (!CWBindingSetQosValues
(bindingPtr->qosCount, bindingPtr->radioQosValues, resultCode)) {
CW_FREE_OBJECT(bindingPtr->radioQosValues);
CW_FREE_OBJECT(bindingPtr);
return CW_FALSE;
}
CW_FREE_OBJECT(bindingPtr->radioQosValues);
CW_FREE_OBJECT(bindingPtr);
}
return CW_TRUE;
break;
}
case BINDING_MSG_ELEMENT_TYPE_OFDM_CONTROL:{
CWBindingConfigurationUpdateRequestValuesOFDM *bindingPtr =
(CWBindingConfigurationUpdateRequestValuesOFDM *) bindingValuesPtr;
if (!CWManageOFDMValues(bindingPtr, resultCode)) {
CW_FREE_OBJECT(bindingPtr->radioOFDMValues);
CW_FREE_OBJECT(bindingPtr);
return CW_FALSE;
}
return CW_TRUE;
break;
}
}
return CW_TRUE;
}
CWBool CWBindingParseConfigurationUpdateRequest(unsigned char *msg, int len, void **valuesPtr)
{
int i;
CWProtocolMessage completeMsg;
unsigned short int GlobalElemType = 0; // = CWProtocolRetrieve32(&completeMsg);
int qosCount = 0;
if (msg == NULL || valuesPtr == NULL)
return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
CWLog("Parsing Binding Configuration Update Request...");
completeMsg.msg = msg;
completeMsg.offset = 0;
CWBindingConfigurationUpdateRequestValues *auxBindingPtr;
CWBindingConfigurationUpdateRequestValuesOFDM *ofdmBindingPtr;
CW_CREATE_OBJECT_ERR(auxBindingPtr, CWBindingConfigurationUpdateRequestValues,
return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
);
CW_CREATE_OBJECT_ERR(ofdmBindingPtr, CWBindingConfigurationUpdateRequestValuesOFDM,
return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
);
// parse message elements
while (completeMsg.offset < len) {
unsigned short int elemType = 0; // = CWProtocolRetrieve32(&completeMsg);
unsigned short int elemLen = 0; // = CWProtocolRetrieve16(&completeMsg);
CWParseFormatMsgElem(&completeMsg, &elemType, &elemLen);
GlobalElemType = elemType;
//CWDebugLog("Parsing Message Element: %u, elemLen: %u", elemType, elemLen);
switch (elemType) {
case BINDING_MSG_ELEMENT_TYPE_WTP_QOS:
qosCount++;
//(auxBindingPtr->qosCount)++; // just count
completeMsg.offset += elemLen;
break;
case BINDING_MSG_ELEMENT_TYPE_OFDM_CONTROL:
completeMsg.offset += elemLen;
break;
default:
if (CWBindingCheckType(elemType)) {
CW_FREE_OBJECT(valuesPtr);
CW_FREE_OBJECT(auxBindingPtr);
CW_FREE_OBJECT(ofdmBindingPtr);
return CWErrorRaise(CW_ERROR_INVALID_FORMAT, "Unrecognized Message Element");
} else {
completeMsg.offset += elemLen;
break;
}
}
}
if (completeMsg.offset != len){
CW_FREE_OBJECT(auxBindingPtr);
CW_FREE_OBJECT(ofdmBindingPtr);
return CWErrorRaise(CW_ERROR_INVALID_FORMAT, "Garbage at the End of the Message");
}
switch (GlobalElemType) {
case BINDING_MSG_ELEMENT_TYPE_WTP_QOS:{
CW_FREE_OBJECT(ofdmBindingPtr);
*valuesPtr = (void *)auxBindingPtr;
auxBindingPtr->qosCount = qosCount;
auxBindingPtr->radioQosValues = NULL;
CW_CREATE_ARRAY_ERR(auxBindingPtr->radioQosValues, auxBindingPtr->qosCount, RadioQosValues,
return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
);
break;
}
case BINDING_MSG_ELEMENT_TYPE_OFDM_CONTROL:
CW_FREE_OBJECT(auxBindingPtr);
*valuesPtr = (void *)ofdmBindingPtr;
CW_CREATE_OBJECT_ERR(ofdmBindingPtr->radioOFDMValues, OFDMControlValues,
return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
);
break;
default:
return CWErrorRaise(CW_ERROR_INVALID_FORMAT,"Message elemet type unrecognized");
}
i = 0;
completeMsg.offset = 0;
while (completeMsg.offset < len) {
unsigned short int type = 0;
unsigned short int elemLen = 0;
CWParseFormatMsgElem(&completeMsg, &type, &elemLen);
switch (type) {
case BINDING_MSG_ELEMENT_TYPE_WTP_QOS:{
unsigned char tagPackets;
if (!
(CWParseWTPQoS
(&completeMsg, elemLen, &(auxBindingPtr->radioQosValues[i].radioID), &tagPackets,
auxBindingPtr->radioQosValues[i].qosValues))) {
CW_FREE_OBJECT(auxBindingPtr->radioQosValues);
CW_FREE_OBJECT(valuesPtr);
return CW_FALSE; // will be handled by the caller
}
i++;
break;
}
case BINDING_MSG_ELEMENT_TYPE_OFDM_CONTROL:{
/* 2009: New case */
if (!
(CWParseWTPOFDM
(&completeMsg, elemLen, &(ofdmBindingPtr->radioID),
ofdmBindingPtr->radioOFDMValues))) {
CW_FREE_OBJECT(ofdmBindingPtr->radioOFDMValues);
CW_FREE_OBJECT(valuesPtr);
return CW_FALSE; // will be handled by the caller
}
break;
}
default:
completeMsg.offset += elemLen;
break;
}
}
CWLog("Binding Configure Update Request Parsed");
return CW_TRUE;
}
CWBool CWBindingSaveConfigureResponse(void *bindingValuesPtr, CWProtocolResultCode * resultCode)
{
if (bindingValuesPtr == NULL) {
return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
}
*resultCode = CW_PROTOCOL_SUCCESS;
CWBindingConfigurationRequestValues *bindingPtr = (CWBindingConfigurationRequestValues *) bindingValuesPtr;
if (bindingPtr->qosCount > 0) {
if (!CWBindingSetQosValues(bindingPtr->qosCount, bindingPtr->radioQosValues, resultCode)) {
CW_FREE_OBJECT(bindingPtr->radioQosValues);
return CW_FALSE;
}
CW_FREE_OBJECT(bindingPtr->radioQosValues);
}
return CW_TRUE;
}
CWBool CWBindingParseConfigureResponse(unsigned char *msg, int len, void **valuesPtr)
{
int i;
CWProtocolMessage completeMsg;
if (msg == NULL || valuesPtr == NULL)
return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
CWLog("Parsing Binding Configuration Request...");
completeMsg.msg = msg;
completeMsg.offset = 0;
CWBindingConfigurationRequestValues *auxBindingPtr;
CW_CREATE_OBJECT_ERR(auxBindingPtr, CWBindingConfigurationRequestValues,
return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
);
*valuesPtr = (void *)auxBindingPtr;
auxBindingPtr->qosCount = 0;
auxBindingPtr->radioQosValues = NULL;
// parse message elements
while (completeMsg.offset < len) {
unsigned short int elemType = 0; // = CWProtocolRetrieve32(&completeMsg);
unsigned short int elemLen = 0; // = CWProtocolRetrieve16(&completeMsg);
CWParseFormatMsgElem(&completeMsg, &elemType, &elemLen);
CWDebugLog("Parsing Message Element: %d, elemLen: %d", elemType, elemLen);
switch (elemType) {
case BINDING_MSG_ELEMENT_TYPE_WTP_QOS:
(auxBindingPtr->qosCount)++; // just count
completeMsg.offset += elemLen;
break;
default:
if (CWBindingCheckType(elemType)) {
CW_FREE_OBJECT(valuesPtr);
return CWErrorRaise(CW_ERROR_INVALID_FORMAT, "Unrecognized Message Element");
} else {
completeMsg.offset += elemLen;
break;
}
}
}
if (completeMsg.offset != len)
return CWErrorRaise(CW_ERROR_INVALID_FORMAT, "Garbage at the End of the Message");
// actually read each radio info
CW_CREATE_ARRAY_ERR(auxBindingPtr->radioQosValues, auxBindingPtr->qosCount, RadioQosValues,
return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
);
i = 0;
completeMsg.offset = 0;
while (completeMsg.offset < len) {
unsigned short int type = 0;
unsigned short int elemLen = 0;
CWParseFormatMsgElem(&completeMsg, &type, &elemLen);
switch (type) {
case BINDING_MSG_ELEMENT_TYPE_WTP_QOS:{
unsigned char tagPackets;
if (!
(CWParseWTPQoS
(&completeMsg, elemLen, &(auxBindingPtr->radioQosValues[i].radioID), &tagPackets,
auxBindingPtr->radioQosValues[i].qosValues))) {
CW_FREE_OBJECT(auxBindingPtr->radioQosValues);
CW_FREE_OBJECT(valuesPtr);
return CW_FALSE; // will be handled by the caller
}
i++;
break;
}
default:
completeMsg.offset += elemLen;
break;
}
}
CWLog("Binding Configuration Request Parsed");
return CW_TRUE;
}