Debian Codegraph @

gobi-api/Gobi_2012-06-18-1054/Gobi3000Translation/Gobi3000TranslationWDS.cpp

raw
1 /*===========================================================================
2 FILE:
3 Gobi3000TranslationWDS.cpp
4
5 DESCRIPTION:
6 QUALCOMM Translation for Gobi 3000 (WDS Service)
7
8 Copyright (c) 2012, Code Aurora Forum. All rights reserved.
9
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
14 * Redistributions in binary form must reproduce the above copyright
15 notice, this list of conditions and the following disclaimer in the
16 documentation and/or other materials provided with the distribution.
17 * Neither the name of Code Aurora Forum nor
18 the names of its contributors may be used to endorse or promote
19 products derived from this software without specific prior written
20 permission.
21
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 POSSIBILITY OF SUCH DAMAGE.
34 ==========================================================================*/
35
36 //---------------------------------------------------------------------------
37 // Include Files
38 //---------------------------------------------------------------------------
39 #include "Gobi3000Translation.h"
40
41 /*===========================================================================
42 METHOD:
43 ParseGetSessionState
44
45 DESCRIPTION:
46 This function returns the state of the current packet data session
47
48 PARAMETERS:
49 inLen [ I ] - Length of input buffer
50 pIn [ I ] - Input buffer
51 pState [ O ] - State of the current packet session
52
53 RETURN VALUE:
54 ULONG - Return code
55 ===========================================================================*/
56 ULONG ParseGetSessionState(
57 ULONG inLen,
58 const BYTE * pIn,
59 ULONG * pState )
60 {
61 // Validate arguments
62 if (pIn == 0 || pState == 0)
63 {
64 return eGOBI_ERR_INVALID_ARG;
65 }
66
67 // Find the TLV
68 const sWDSGetPacketServiceStatusResponse_Status * pTLVx01;
69 ULONG outLenx01;
70 ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 );
71 if (rc != eGOBI_ERR_NONE)
72 {
73 return rc;
74 }
75
76 // Is the TLV large enough?
77 if (outLenx01 < sizeof( sWDSGetPacketServiceStatusResponse_Status ))
78 {
79 return eGOBI_ERR_MALFORMED_RSP;
80 }
81
82 *pState = pTLVx01->mConnectionStatus;
83
84 return eGOBI_ERR_NONE;
85 }
86
87 /*===========================================================================
88 METHOD:
89 ParseGetSessionDuration
90
91 DESCRIPTION:
92 This function returns the duration of the current packet data session
93
94 PARAMETERS:
95 inLen [ I ] - Length of input buffer
96 pIn [ I ] - Input buffer
97 pDuration [ O ] - Duration of the current packet session
98
99 RETURN VALUE:
100 ULONG - Return code
101 ===========================================================================*/
102 ULONG ParseGetSessionDuration(
103 ULONG inLen,
104 const BYTE * pIn,
105 ULONGLONG * pDuration )
106 {
107 // Validate arguments
108 if (pIn == 0 || pDuration == 0)
109 {
110 return eGOBI_ERR_INVALID_ARG;
111 }
112
113 // Find the TLV
114 const sWDSGetDataSessionDurationResponse_Duration * pTLVx01;
115 ULONG outLenx01;
116 ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 );
117 if (rc != eGOBI_ERR_NONE)
118 {
119 return rc;
120 }
121
122 // Is the TLV large enough?
123 if (outLenx01 < sizeof( sWDSGetDataSessionDurationResponse_Duration ))
124 {
125 return eGOBI_ERR_MALFORMED_RSP;
126 }
127
128 *pDuration = pTLVx01->mDataSessionDuration;
129 return eGOBI_ERR_NONE;
130 }
131
132 /*===========================================================================
133 METHOD:
134 ParseGetDormancyState
135
136 DESCRIPTION:
137 This function returns the dormancy state of the current packet
138 data session (when connected)
139
140 PARAMETERS:
141 inLen [ I ] - Length of input buffer
142 pIn [ I ] - Input buffer
143 pState [ O ] - Dormancy state of the current packet session
144
145 RETURN VALUE:
146 ULONG - Return code
147 ===========================================================================*/
148 ULONG ParseGetDormancyState(
149 ULONG inLen,
150 const BYTE * pIn,
151 ULONG * pState )
152 {
153 // Validate arguments
154 if (pIn == 0 || pState == 0)
155 {
156 return eGOBI_ERR_INVALID_ARG;
157 }
158
159 // Find the TLV
160 const sWDSGetDormancyResponse_DormancyStatus * pTLVx01;
161 ULONG outLenx01;
162 ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 );
163 if (rc != eGOBI_ERR_NONE)
164 {
165 return rc;
166 }
167
168 // Is the TLV large enough?
169 if (outLenx01 < sizeof( sWDSGetDormancyResponse_DormancyStatus ))
170 {
171 return eGOBI_ERR_MALFORMED_RSP;
172 }
173
174 *pState = pTLVx01->mDormancyStatus;
175 return eGOBI_ERR_NONE;
176 }
177
178 /*===========================================================================
179 METHOD:
180 ParseGetEnhancedAutoconnect
181
182 DESCRIPTION:
183 This function returns the current autoconnect data session setting
184
185 PARAMETERS:
186 inLen [ I ] - Length of input buffer
187 pIn [ I ] - Input buffer
188 pSetting [ O ] - NDIS autoconnect setting
189 pRoamSetting [ O ] - NDIS autoconnect roam setting
190
191 RETURN VALUE:
192 ULONG - Return code
193 ===========================================================================*/
194 ULONG ParseGetEnhancedAutoconnect(
195 ULONG inLen,
196 const BYTE * pIn,
197 ULONG * pSetting,
198 ULONG * pRoamSetting )
199 {
200 // Validate arguments
201 if (pIn == 0 || pSetting == 0 || pRoamSetting == 0)
202 {
203 return eGOBI_ERR_INVALID_ARG;
204 }
205
206 *pSetting = 0xffffffff;
207 *pRoamSetting = 0xffffffff;
208
209 // Find the first TLV
210 const sWDSGetAutoconnectSettingResponse_Autoconnect * pTLVx01;
211 ULONG outLenx01;
212 ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 );
213 if (rc != eGOBI_ERR_NONE)
214 {
215 return rc;
216 }
217
218 // Is the TLV large enough?
219 if (outLenx01 < sizeof( sWDSGetAutoconnectSettingResponse_Autoconnect ))
220 {
221 return eGOBI_ERR_MALFORMED_RSP;
222 }
223
224 *pSetting = pTLVx01->mAutoconnectSetting;
225
226 // Find the second TLV (optional)
227 const sWDSGetAutoconnectSettingResponse_Roam * pTLVx10;
228 ULONG outLenx10;
229 rc = GetTLV( inLen, pIn, 0x10, &outLenx10, (const BYTE **)&pTLVx10 );
230 if (rc == eGOBI_ERR_NONE)
231 {
232 // Is the TLV large enough?
233 if (outLenx10 < sizeof( sWDSGetAutoconnectSettingResponse_Roam ))
234 {
235 return eGOBI_ERR_MALFORMED_RSP;
236 }
237
238 *pRoamSetting = pTLVx10->mAutoconnectRoamSetting;
239 }
240
241 return eGOBI_ERR_NONE;
242 }
243
244 /*===========================================================================
245 METHOD:
246 PackSetEnhancedAutoconnect
247
248 DESCRIPTION:
249 This function sets the autoconnect data session setting
250
251 PARAMETERS:
252 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
253 contain, upon output the number of BYTEs copied
254 to pOut
255 pOut [ O ] - Output buffer
256 setting [ I ] - NDIS autoconnect setting
257 pRoamSetting [ I ] - (Optional) NDIS autoconnect roam setting
258
259
260 RETURN VALUE:
261 ULONG - Return code
262 ===========================================================================*/
263 ULONG PackSetEnhancedAutoconnect(
264 ULONG * pOutLen,
265 BYTE * pOut,
266 ULONG setting,
267 ULONG * pRoamSetting )
268 {
269 // Validate arguments
270 if (pOut == 0)
271 {
272 return eGOBI_ERR_INVALID_ARG;
273 }
274
275 // Add setting
276
277 // Check size
278 WORD tlvx01Sz = sizeof( sWDSSetAutoconnectSettingRequest_Autoconnect );
279 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz)
280 {
281 return eGOBI_ERR_BUFFER_SZ;
282 }
283
284 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut;
285 pHeader->mTypeID = 0x01;
286 pHeader->mLength = tlvx01Sz;
287
288 ULONG offset = sizeof( sQMIRawContentHeader );
289
290 sWDSSetAutoconnectSettingRequest_Autoconnect * pTLVx01;
291 pTLVx01 = (sWDSSetAutoconnectSettingRequest_Autoconnect*)(pOut + offset);
292 memset( pTLVx01, 0, tlvx01Sz );
293
294 // Set the value
295 pTLVx01->mAutoconnectSetting = (eQMIWDSAutoconnectSettings)setting;
296
297 offset += tlvx01Sz;
298
299 // Add roam setting, if specified
300 if (pRoamSetting != 0)
301 {
302 // Check size
303 WORD tlvx10Sz = sizeof( sWDSSetAutoconnectSettingRequest_Roam );
304 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx10Sz)
305 {
306 return eGOBI_ERR_BUFFER_SZ;
307 }
308
309 pHeader = (sQMIRawContentHeader*)(pOut + offset);
310 pHeader->mTypeID = 0x10;
311 pHeader->mLength = tlvx10Sz;
312
313 offset += sizeof( sQMIRawContentHeader );
314
315 sWDSSetAutoconnectSettingRequest_Roam * pTLVx10;
316 pTLVx10 = (sWDSSetAutoconnectSettingRequest_Roam*)(pOut + offset);
317 memset( pTLVx10, 0, tlvx10Sz );
318
319 // Set the value
320 pTLVx10->mAutoconnectRoamSetting = (eQMIWDSAutoconnectRoamSettings)*pRoamSetting;
321
322 offset += tlvx10Sz;
323 }
324
325 *pOutLen = offset;
326
327 return eGOBI_ERR_NONE;
328 }
329
330 /*===========================================================================
331 METHOD:
332 PackSetDefaultProfile
333
334 DESCRIPTION:
335 This function writes the default profile settings to the device, the
336 default profile is used during autoconnect
337
338 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
339 contain, upon output the number of BYTEs copied
340 to pOut
341 pOut [ O ] - Output buffer
342 profileType [ I ] - Profile type being written
343 pPDPType [ I ] - (Optional) PDP type
344 pIPAddress [ I ] - (Optional) Preferred assigned IPv4 address
345 pPrimaryDNS [ I ] - (Optional) Primary DNS IPv4 address
346 pSecondaryDNS [ I ] - (Optional) Secondary DNS IPv4 address
347 pAuthentication [ I ] - (Optional) Authentication algorithm bitmap
348 pName [ I ] - (Optional) The profile name or description
349 pAPNName [ I ] - (Optional) Access point name
350 pUsername [ I ] - (Optional) Username used during authentication
351 pPassword [ I ] - (Optional) Password used during authentication
352
353 RETURN VALUE:
354 ULONG - Return code
355 ===========================================================================*/
356 ULONG PackSetDefaultProfile(
357 ULONG * pOutLen,
358 BYTE * pOut,
359 ULONG profileType,
360 ULONG * pPDPType,
361 ULONG * pIPAddress,
362 ULONG * pPrimaryDNS,
363 ULONG * pSecondaryDNS,
364 ULONG * pAuthentication,
365 CHAR * pName,
366 CHAR * pAPNName,
367 CHAR * pUsername,
368 CHAR * pPassword )
369 {
370 // Validate arguments
371 if (pOut == 0)
372 {
373 return eGOBI_ERR_INVALID_ARG;
374 }
375
376 // Add profileType
377
378 // Check size
379 WORD tlvx01Sz = sizeof( sWDSModifyProfileRequest_ProfileIdentifier );
380 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz)
381 {
382 return eGOBI_ERR_BUFFER_SZ;
383 }
384
385 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut;
386 pHeader->mTypeID = 0x01;
387 pHeader->mLength = tlvx01Sz;
388
389 ULONG offset = sizeof( sQMIRawContentHeader );
390
391 sWDSModifyProfileRequest_ProfileIdentifier * pTLVx01;
392 pTLVx01 = (sWDSModifyProfileRequest_ProfileIdentifier*)(pOut + offset);
393 memset( pTLVx01, 0, tlvx01Sz );
394
395 // Set the value
396 pTLVx01->mProfileType = (eQMIProfileTypes)profileType;
397 pTLVx01->mProfileIndex = 1;
398
399 offset += tlvx01Sz;
400
401 // Add name, if specified
402 if (pName != 0)
403 {
404 std::string name( pName );
405
406 // Check size
407 WORD tlvx10Sz = (WORD)name.size();
408 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx10Sz)
409 {
410 return eGOBI_ERR_BUFFER_SZ;
411 }
412
413 pHeader = (sQMIRawContentHeader*)(pOut + offset);
414 pHeader->mTypeID = 0x10;
415 pHeader->mLength = tlvx10Sz;
416
417 offset += sizeof( sQMIRawContentHeader );
418
419 // Set the value
420 memcpy( pOut + offset, name.c_str(), name.size() );
421
422 offset += tlvx10Sz;
423 }
424
425 // Add PDP type, if specified
426 if (pPDPType != 0)
427 {
428 // Check size
429 WORD tlvx11Sz = sizeof( sWDSModifyProfileRequest_PDPType );
430 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx11Sz)
431 {
432 return eGOBI_ERR_BUFFER_SZ;
433 }
434
435 pHeader = (sQMIRawContentHeader*)(pOut + offset);
436 pHeader->mTypeID = 0x11;
437 pHeader->mLength = tlvx11Sz;
438
439 offset += sizeof( sQMIRawContentHeader );
440
441 sWDSModifyProfileRequest_PDPType * pTLVx11;
442 pTLVx11 = (sWDSModifyProfileRequest_PDPType*)(pOut + offset);
443 memset( pTLVx11, 0, tlvx11Sz );
444
445 // Set the value
446 pTLVx11->mPDPType = (eQMIPDPTypes)*pPDPType;
447
448 offset += tlvx11Sz;
449 }
450
451 // Add APN Name, if specified
452 if (pAPNName != 0)
453 {
454 std::string apnName( pAPNName );
455
456 // Check size
457 WORD tlvx14Sz = (WORD)apnName.size();
458 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx14Sz)
459 {
460 return eGOBI_ERR_BUFFER_SZ;
461 }
462
463 pHeader = (sQMIRawContentHeader*)(pOut + offset);
464 pHeader->mTypeID = 0x14;
465 pHeader->mLength = tlvx14Sz;
466
467 offset += sizeof( sQMIRawContentHeader );
468
469 // Set the value
470 memcpy( (pOut + offset), apnName.c_str(), apnName.size() );
471
472 offset += tlvx14Sz;
473 }
474
475 // Add Primary DNS, if specified
476 if (pPrimaryDNS != 0)
477 {
478 // Check size
479 WORD tlvx15Sz = sizeof( sWDSModifyProfileRequest_PrimaryDNS );
480 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx15Sz)
481 {
482 return eGOBI_ERR_BUFFER_SZ;
483 }
484
485 pHeader = (sQMIRawContentHeader*)(pOut + offset);
486 pHeader->mTypeID = 0x15;
487 pHeader->mLength = tlvx15Sz;
488
489 offset += sizeof( sQMIRawContentHeader );
490
491 sWDSModifyProfileRequest_PrimaryDNS * pTLVx15;
492 pTLVx15 = (sWDSModifyProfileRequest_PrimaryDNS*)(pOut + offset);
493 memset( pTLVx15, 0, tlvx15Sz );
494
495 ULONG ip0 = (*pPrimaryDNS & 0x000000FF);
496 ULONG ip1 = (*pPrimaryDNS & 0x0000FF00) >> 8;
497 ULONG ip2 = (*pPrimaryDNS & 0x00FF0000) >> 16;
498 ULONG ip3 = (*pPrimaryDNS & 0xFF000000) >> 24;
499
500 // Set the value
501 pTLVx15->mIPV4Address[0] = (INT8)ip0;
502 pTLVx15->mIPV4Address[1] = (INT8)ip1;
503 pTLVx15->mIPV4Address[2] = (INT8)ip2;
504 pTLVx15->mIPV4Address[3] = (INT8)ip3;
505
506 offset += tlvx15Sz;
507 }
508
509 // Add Secondary DNS, if specified
510 if (pSecondaryDNS != 0)
511 {
512 // Check size
513 WORD tlvx16Sz = sizeof( sWDSModifyProfileRequest_SecondaryDNS );
514 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx16Sz)
515 {
516 return eGOBI_ERR_BUFFER_SZ;
517 }
518
519 pHeader = (sQMIRawContentHeader*)(pOut + offset);
520 pHeader->mTypeID = 0x16;
521 pHeader->mLength = tlvx16Sz;
522
523 offset += sizeof( sQMIRawContentHeader );
524
525 sWDSModifyProfileRequest_SecondaryDNS * pTLVx16;
526 pTLVx16 = (sWDSModifyProfileRequest_SecondaryDNS*)(pOut + offset);
527 memset( pTLVx16, 0, tlvx16Sz );
528
529 ULONG ip0 = (*pSecondaryDNS & 0x000000FF);
530 ULONG ip1 = (*pSecondaryDNS & 0x0000FF00) >> 8;
531 ULONG ip2 = (*pSecondaryDNS & 0x00FF0000) >> 16;
532 ULONG ip3 = (*pSecondaryDNS & 0xFF000000) >> 24;
533
534 // Set the value
535 pTLVx16->mIPV4Address[0] = (INT8)ip0;
536 pTLVx16->mIPV4Address[1] = (INT8)ip1;
537 pTLVx16->mIPV4Address[2] = (INT8)ip2;
538 pTLVx16->mIPV4Address[3] = (INT8)ip3;
539
540 offset += tlvx16Sz;
541 }
542
543 // Add Username, if specified
544 if (pUsername != 0)
545 {
546 std::string username( pUsername );
547
548 // Check size
549 WORD tlvx1BSz = (WORD)username.size();
550 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx1BSz)
551 {
552 return eGOBI_ERR_BUFFER_SZ;
553 }
554
555 pHeader = (sQMIRawContentHeader*)(pOut + offset);
556 pHeader->mTypeID = 0x1B;
557 pHeader->mLength = tlvx1BSz;
558
559 offset += sizeof( sQMIRawContentHeader );
560
561 // Set the value
562 memcpy( (pOut + offset), username.c_str(), username.size() );
563
564 offset += tlvx1BSz;
565 }
566
567 // Add Password, if specified
568 if (pPassword != 0)
569 {
570 std::string password( pPassword );
571
572 // Check size
573 WORD tlvx1CSz = (WORD)password.size();
574 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx1CSz)
575 {
576 return eGOBI_ERR_BUFFER_SZ;
577 }
578
579 pHeader = (sQMIRawContentHeader*)(pOut + offset);
580 pHeader->mTypeID = 0x1C;
581 pHeader->mLength = tlvx1CSz;
582
583 offset += sizeof( sQMIRawContentHeader );
584
585 // Set the value
586 memcpy( (pOut + offset), password.c_str(), password.size() );
587
588 offset += tlvx1CSz;
589 }
590
591 // Add Authentication, if specified
592 if (pAuthentication != 0)
593 {
594 // Check size
595 WORD tlvx1DSz = sizeof( sWDSModifyProfileRequest_Authentication );
596 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx1DSz)
597 {
598 return eGOBI_ERR_BUFFER_SZ;
599 }
600
601 pHeader = (sQMIRawContentHeader*)(pOut + offset);
602 pHeader->mTypeID = 0x1D;
603 pHeader->mLength = tlvx1DSz;
604
605 offset += sizeof( sQMIRawContentHeader );
606
607 sWDSModifyProfileRequest_Authentication * pTLVx1D;
608 pTLVx1D = (sWDSModifyProfileRequest_Authentication*)(pOut + offset);
609 memset( pTLVx1D, 0, tlvx1DSz );
610
611 // Set the value
612 pTLVx1D->mEnablePAP = ((*pAuthentication & 0x00000001) != 0);
613 pTLVx1D->mEnableCHAP = ((*pAuthentication & 0x00000002) != 0);
614
615 offset += tlvx1DSz;
616 }
617
618 // Add IP Address, if specified
619 if (pIPAddress != 0)
620 {
621 // Check size
622 WORD tlvx1ESz = sizeof( sWDSModifyProfileRequest_IPAddress );
623 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx1ESz)
624 {
625 return eGOBI_ERR_BUFFER_SZ;
626 }
627
628 pHeader = (sQMIRawContentHeader*)(pOut + offset);
629 pHeader->mTypeID = 0x1E;
630 pHeader->mLength = tlvx1ESz;
631
632 offset += sizeof( sQMIRawContentHeader );
633
634 sWDSModifyProfileRequest_IPAddress * pTLVx1E;
635 pTLVx1E = (sWDSModifyProfileRequest_IPAddress*)(pOut + offset);
636 memset( pTLVx1E, 0, tlvx1ESz );
637
638 ULONG ip0 = (*pIPAddress & 0x000000FF);
639 ULONG ip1 = (*pIPAddress & 0x0000FF00) >> 8;
640 ULONG ip2 = (*pIPAddress & 0x00FF0000) >> 16;
641 ULONG ip3 = (*pIPAddress & 0xFF000000) >> 24;
642
643 // Set the value
644 pTLVx1E->mIPV4Address[0] = (INT8)ip0;
645 pTLVx1E->mIPV4Address[1] = (INT8)ip1;
646 pTLVx1E->mIPV4Address[2] = (INT8)ip2;
647 pTLVx1E->mIPV4Address[3] = (INT8)ip3;
648
649 offset += tlvx1ESz;
650 }
651
652 // At least one of the optional parameters must have been set
653 if (offset <= sizeof( sQMIRawContentHeader ) + tlvx01Sz)
654 {
655 return eGOBI_ERR_INVALID_ARG;
656 }
657
658 *pOutLen = offset;
659
660 return eGOBI_ERR_NONE;
661 }
662
663 /*===========================================================================
664 METHOD:
665 PackGetDefaultProfile
666
667 DESCRIPTION:
668 This function reads the default profile settings from the device, the
669 default profile is used during autoconnect
670
671 PARAMETERS:
672 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
673 contain, upon output the number of BYTEs copied
674 to pOut
675 pOut [ O ] - Output buffer
676 profileType [ I ] - Profile type being read
677
678 RETURN VALUE:
679 ULONG - Return code
680 ===========================================================================*/
681 ULONG PackGetDefaultProfile(
682 ULONG * pOutLen,
683 BYTE * pOut,
684 ULONG profileType )
685 {
686 // Validate arguments
687 if (pOut == 0)
688 {
689 return eGOBI_ERR_INVALID_ARG;
690 }
691
692 // Add profileType
693
694 // Check size
695 WORD tlvx01Sz = sizeof( sWDSGetDefaultSettingsRequest_ProfileType );
696 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz)
697 {
698 return eGOBI_ERR_BUFFER_SZ;
699 }
700
701 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut;
702 pHeader->mTypeID = 0x01;
703 pHeader->mLength = tlvx01Sz;
704
705 ULONG offset = sizeof( sQMIRawContentHeader );
706
707 sWDSGetDefaultSettingsRequest_ProfileType * pTLVx01;
708 pTLVx01 = (sWDSGetDefaultSettingsRequest_ProfileType*)(pOut + offset);
709 memset( pTLVx01, 0, tlvx01Sz );
710
711 // Set the value
712 pTLVx01->mProfileType = (eQMIProfileTypes)profileType;
713
714 offset += tlvx01Sz;
715
716 *pOutLen = offset;
717 return eGOBI_ERR_NONE;
718 }
719
720 /*===========================================================================
721 METHOD:
722 ParseGetDefaultProfile
723
724 DESCRIPTION:
725 This function reads the default profile settings from the device, the
726 default profile is used during autoconnect
727
728 PARAMETERS:
729 inLen [ I ] - Length of input buffer
730 pIn [ I ] - Input buffer
731 pPDPType [ O ] - PDP type
732 pIPAddress [ O ] - Preferred assigned IPv4 address
733 pPrimaryDNS [ O ] - Primary DNS IPv4 address
734 pSecondaryDNS [ O ] - Secondary DNS IPv4 address
735 pAuthentication [ O ] - Authentication algorithm bitmap
736 nameSize [ I ] - The maximum number of characters (including
737 NULL terminator) that the profile name array
738 can contain
739 pName [ O ] - The profile name or description
740 apnSize [ I ] - The maximum number of characters (including
741 NULL terminator) that the APN name array
742 can contain
743 pAPNName [ O ] - Access point name represented as a NULL
744 terminated string (empty string returned when
745 unknown)
746 userSize [ I ] - The maximum number of characters (including
747 NULL terminator) that the username array
748 can contain
749 pUsername [ O ] - Username used during authentication
750
751 RETURN VALUE:
752 ULONG - Return code
753 ===========================================================================*/
754 ULONG ParseGetDefaultProfile(
755 ULONG inLen,
756 const BYTE * pIn,
757 ULONG * pPDPType,
758 ULONG * pIPAddress,
759 ULONG * pPrimaryDNS,
760 ULONG * pSecondaryDNS,
761 ULONG * pAuthentication,
762 BYTE nameSize,
763 CHAR * pName,
764 BYTE apnSize,
765 CHAR * pAPNName,
766 BYTE userSize,
767 CHAR * pUsername )
768 {
769 // Validate arguments
770 if (pIn == 0
771 || pPDPType == 0
772 || pIPAddress == 0
773 || pPrimaryDNS == 0
774 || pSecondaryDNS == 0
775 || pAuthentication == 0
776 || nameSize == 0
777 || pName == 0
778 || apnSize == 0
779 || pAPNName == 0
780 || userSize == 0
781 || pUsername == 0)
782 {
783 return eGOBI_ERR_INVALID_ARG;
784 }
785
786 // Set defaults
787 *pPDPType = 0xffffffff;
788 *pIPAddress = 0xffffffff;
789 *pPrimaryDNS = 0xffffffff;
790 *pSecondaryDNS = 0xffffffff;
791 *pAuthentication = 0xffffffff;
792 pName[0] = 0;
793 pAPNName[0] = 0;
794 pUsername[0] = 0;
795
796 // Find the name
797 const sWDSGetDefaultSettingsResponse_ProfileName * pTLVx10;
798 ULONG outLenx10;
799 ULONG rc = GetTLV( inLen, pIn, 0x10, &outLenx10, (const BYTE **)&pTLVx10 );
800 if (rc == eGOBI_ERR_NONE)
801 {
802 if (nameSize < outLenx10 + 1)
803 {
804 return eGOBI_ERR_BUFFER_SZ;
805 }
806
807 memcpy( pName, (const BYTE *)pTLVx10, outLenx10 );
808
809 // Null terminate
810 pName[outLenx10] = 0;
811 }
812
813 // Find the PDP type
814 const sWDSGetDefaultSettingsResponse_PDPType * pTLVx11;
815 ULONG outLenx11;
816 rc = GetTLV( inLen, pIn, 0x11, &outLenx11, (const BYTE **)&pTLVx11 );
817 if (rc == eGOBI_ERR_NONE)
818 {
819 if (outLenx11 < sizeof( sWDSGetDefaultSettingsResponse_PDPType ))
820 {
821 return eGOBI_ERR_MALFORMED_RSP;
822 }
823
824 *pPDPType = pTLVx11->mPDPType;
825 }
826
827 // Find the APN name
828 const sWDSGetDefaultSettingsResponse_APNName * pTLVx14;
829 ULONG outLenx14;
830 rc = GetTLV( inLen, pIn, 0x14, &outLenx14, (const BYTE **)&pTLVx14 );
831 if (rc == eGOBI_ERR_NONE)
832 {
833 if (apnSize < outLenx14 + 1)
834 {
835 return eGOBI_ERR_BUFFER_SZ;
836 }
837
838 memcpy( pAPNName, (const BYTE *)pTLVx14, outLenx14 );
839
840 // Null terminate
841 pAPNName[outLenx14] = 0;
842 }
843
844 // Find the Primary DNS
845 const sWDSGetDefaultSettingsResponse_PrimaryDNS * pTLVx15;
846 ULONG outLenx15;
847 rc = GetTLV( inLen, pIn, 0x15, &outLenx15, (const BYTE **)&pTLVx15 );
848 if (rc == eGOBI_ERR_NONE)
849 {
850 if (outLenx15 < sizeof( sWDSGetDefaultSettingsResponse_PrimaryDNS ))
851 {
852 return eGOBI_ERR_MALFORMED_RSP;
853 }
854
855 ULONG ip0 = pTLVx15->mIPV4Address[0];
856 ULONG ip1 = pTLVx15->mIPV4Address[1] << 8;
857 ULONG ip2 = pTLVx15->mIPV4Address[2] << 16;
858 ULONG ip3 = pTLVx15->mIPV4Address[3] << 24;
859
860 *pPrimaryDNS = (ip0 | ip1 | ip2 | ip3);
861 }
862
863 // Find the Secondary DNS
864 const sWDSGetDefaultSettingsResponse_SecondaryDNS * pTLVx16;
865 ULONG outLenx16;
866 rc = GetTLV( inLen, pIn, 0x16, &outLenx16, (const BYTE **)&pTLVx16 );
867 if (rc == eGOBI_ERR_NONE)
868 {
869 if (outLenx16 < sizeof( sWDSGetDefaultSettingsResponse_SecondaryDNS ))
870 {
871 return eGOBI_ERR_MALFORMED_RSP;
872 }
873
874 ULONG ip0 = pTLVx16->mIPV4Address[0];
875 ULONG ip1 = pTLVx16->mIPV4Address[1] << 8;
876 ULONG ip2 = pTLVx16->mIPV4Address[2] << 16;
877 ULONG ip3 = pTLVx16->mIPV4Address[3] << 24;
878
879 *pSecondaryDNS = (ip0 | ip1 | ip2 | ip3);
880 }
881
882 // Find the Username
883 const sWDSGetDefaultSettingsResponse_APNName * pTLVx1B;
884 ULONG outLenx1B;
885 rc = GetTLV( inLen, pIn, 0x1B, &outLenx1B, (const BYTE **)&pTLVx1B );
886 if (rc == eGOBI_ERR_NONE)
887 {
888 if (userSize < outLenx1B + 1)
889 {
890 return eGOBI_ERR_BUFFER_SZ;
891 }
892
893 memcpy( pAPNName, (const BYTE *)pTLVx1B, outLenx1B );
894
895 // Null terminate
896 pAPNName[outLenx1B] = 0;
897 }
898
899 // Find the Authentication
900 const sWDSGetDefaultSettingsResponse_Authentication * pTLVx1D;
901 ULONG outLenx1D;
902 rc = GetTLV( inLen, pIn, 0x1D, &outLenx1D, (const BYTE **)&pTLVx1D );
903 if (rc == eGOBI_ERR_NONE)
904 {
905 if (outLenx1D < sizeof( sWDSGetDefaultSettingsResponse_Authentication ))
906 {
907 return eGOBI_ERR_MALFORMED_RSP;
908 }
909
910 ULONG pap = pTLVx1D->mEnablePAP;
911 ULONG chap = pTLVx1D->mEnableCHAP << 1;
912
913 *pAuthentication = (pap | chap);
914 }
915
916 // Find the IP Address
917 const sWDSGetDefaultSettingsResponse_IPAddress * pTLVx1E;
918 ULONG outLenx1E;
919 rc = GetTLV( inLen, pIn, 0x1E, &outLenx1E, (const BYTE **)&pTLVx1E );
920 if (rc == eGOBI_ERR_NONE)
921 {
922 if (outLenx1E < sizeof( sWDSGetDefaultSettingsResponse_IPAddress ))
923 {
924 return eGOBI_ERR_MALFORMED_RSP;
925 }
926
927 ULONG ip0 = pTLVx1E->mIPV4Address[0];
928 ULONG ip1 = pTLVx1E->mIPV4Address[1] << 8;
929 ULONG ip2 = pTLVx1E->mIPV4Address[2] << 16;
930 ULONG ip3 = pTLVx1E->mIPV4Address[3] << 24;
931
932 *pIPAddress = (ip0 | ip1 | ip2 | ip3);
933 }
934
935 return eGOBI_ERR_NONE;
936 }
937
938 /*===========================================================================
939 METHOD:
940 PackStartDataSession
941
942 DESCRIPTION:
943 This function activates a packet data session
944
945 PARAMETERS:
946 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
947 contain, upon output the number of BYTEs copied
948 to pOut
949 pOut [ O ] - Output buffer
950 pTechnology [ I ] - (Optional) Technology bitmap
951 pPrimaryDNS [ I ] - (Optional) Primary DNS IPv4 address
952 pSecondaryDNS [ I ] - (Optional) Secondary DNS IPv4 address
953 pPrimaryNBNS [ I ] - (Optional) Primary NetBIOS NS IPv4 address
954 pSecondaryNBNS [ I ] - (Optional) Secondary NetBIOS NS IPv4 address
955 pAPNName [ I ] - (Optional) Access point name
956 pIPAddress [ I ] - (Optional) Preferred assigned IPv4 address
957 pAuthentication [ I ] - (Optional) Authentication algorithm bitmap
958 pUsername [ I ] - (Optional) Username used during authentication
959 pPassword [ I ] - (Optional) Password used during authentication
960
961 RETURN VALUE:
962 ULONG - Return code
963 ===========================================================================*/
964 ULONG PackStartDataSession(
965 ULONG * pOutLen,
966 BYTE * pOut,
967 ULONG * pTechnology,
968 ULONG * pPrimaryDNS,
969 ULONG * pSecondaryDNS,
970 ULONG * pPrimaryNBNS,
971 ULONG * pSecondaryNBNS,
972 CHAR * pAPNName,
973 ULONG * pIPAddress,
974 ULONG * pAuthentication,
975 CHAR * pUsername,
976 CHAR * pPassword )
977 {
978 // Validate arguments
979 if (pOut == 0)
980 {
981 return eGOBI_ERR_INVALID_ARG;
982 }
983
984 sQMIRawContentHeader * pHeader;
985 ULONG offset = 0;
986
987 // Add technology, if specified
988 if (pTechnology != 0)
989 {
990 // Check size
991 WORD tlvx30Sz = sizeof( sWDSStartNetworkInterfaceRequest_TechnologyPreference );
992 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx30Sz)
993 {
994 return eGOBI_ERR_BUFFER_SZ;
995 }
996
997 pHeader = (sQMIRawContentHeader*)(pOut + offset);
998 pHeader->mTypeID = 0x30;
999 pHeader->mLength = tlvx30Sz;
1000
1001 offset += sizeof( sQMIRawContentHeader );
1002
1003 sWDSStartNetworkInterfaceRequest_TechnologyPreference * pTLVx30;
1004 pTLVx30 = (sWDSStartNetworkInterfaceRequest_TechnologyPreference*)(pOut + offset);
1005 memset( pTLVx30, 0, tlvx30Sz );
1006
1007 // Set the value
1008 pTLVx30->mEnable3GPP = ((*pTechnology & 0x00000001) != 0);
1009 pTLVx30->mEnable3GPP2 = ((*pTechnology & 0x00000002) != 0);
1010
1011 offset += tlvx30Sz;
1012 }
1013
1014 // Add Primary DNS, if specified
1015 if (pPrimaryDNS != 0)
1016 {
1017 // Check size
1018 WORD tlvx10Sz = sizeof( sWDSStartNetworkInterfaceRequest_PrimaryDNS );
1019 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx10Sz)
1020 {
1021 return eGOBI_ERR_BUFFER_SZ;
1022 }
1023
1024 pHeader = (sQMIRawContentHeader*)(pOut + offset);
1025 pHeader->mTypeID = 0x10;
1026 pHeader->mLength = tlvx10Sz;
1027
1028 offset += sizeof( sQMIRawContentHeader );
1029
1030 sWDSStartNetworkInterfaceRequest_PrimaryDNS * pTLVx10;
1031 pTLVx10 = (sWDSStartNetworkInterfaceRequest_PrimaryDNS*)(pOut + offset);
1032 memset( pTLVx10, 0, tlvx10Sz );
1033
1034 ULONG ip0 = (*pPrimaryDNS & 0x000000FF);
1035 ULONG ip1 = (*pPrimaryDNS & 0x0000FF00) >> 8;
1036 ULONG ip2 = (*pPrimaryDNS & 0x00FF0000) >> 16;
1037 ULONG ip3 = (*pPrimaryDNS & 0xFF000000) >> 24;
1038
1039 // Set the value
1040 pTLVx10->mIPV4Address[0] = (INT8)ip0;
1041 pTLVx10->mIPV4Address[1] = (INT8)ip1;
1042 pTLVx10->mIPV4Address[2] = (INT8)ip2;
1043 pTLVx10->mIPV4Address[3] = (INT8)ip3;
1044
1045 offset += tlvx10Sz;
1046 }
1047
1048 // Add Secondary DNS, if specified
1049 if (pSecondaryDNS != 0)
1050 {
1051 // Check size
1052 WORD tlvx11Sz = sizeof( sWDSStartNetworkInterfaceRequest_SecondaryDNS );
1053 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx11Sz)
1054 {
1055 return eGOBI_ERR_BUFFER_SZ;
1056 }
1057
1058 pHeader = (sQMIRawContentHeader*)(pOut + offset);
1059 pHeader->mTypeID = 0x11;
1060 pHeader->mLength = tlvx11Sz;
1061
1062 offset += sizeof( sQMIRawContentHeader );
1063
1064 sWDSStartNetworkInterfaceRequest_SecondaryDNS * pTLVx11;
1065 pTLVx11 = (sWDSStartNetworkInterfaceRequest_SecondaryDNS*)(pOut + offset);
1066 memset( pTLVx11, 0, tlvx11Sz );
1067
1068 ULONG ip0 = (*pSecondaryDNS & 0x000000FF);
1069 ULONG ip1 = (*pSecondaryDNS & 0x0000FF00) >> 8;
1070 ULONG ip2 = (*pSecondaryDNS & 0x00FF0000) >> 16;
1071 ULONG ip3 = (*pSecondaryDNS & 0xFF000000) >> 24;
1072
1073 // Set the value
1074 pTLVx11->mIPV4Address[0] = (INT8)ip0;
1075 pTLVx11->mIPV4Address[1] = (INT8)ip1;
1076 pTLVx11->mIPV4Address[2] = (INT8)ip2;
1077 pTLVx11->mIPV4Address[3] = (INT8)ip3;
1078
1079 offset += tlvx11Sz;
1080 }
1081
1082 // Add Primary NBNS, if specified
1083 if (pPrimaryNBNS != 0)
1084 {
1085 // Check size
1086 WORD tlvx12Sz = sizeof( sWDSStartNetworkInterfaceRequest_PrimaryNBNS );
1087 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx12Sz)
1088 {
1089 return eGOBI_ERR_BUFFER_SZ;
1090 }
1091
1092 pHeader = (sQMIRawContentHeader*)(pOut + offset);
1093 pHeader->mTypeID = 0x12;
1094 pHeader->mLength = tlvx12Sz;
1095
1096 offset += sizeof( sQMIRawContentHeader );
1097
1098 sWDSStartNetworkInterfaceRequest_PrimaryNBNS * pTLVx12;
1099 pTLVx12 = (sWDSStartNetworkInterfaceRequest_PrimaryNBNS*)(pOut + offset);
1100 memset( pTLVx12, 0, tlvx12Sz );
1101
1102 ULONG ip0 = (*pPrimaryNBNS & 0x000000FF);
1103 ULONG ip1 = (*pPrimaryNBNS & 0x0000FF00) >> 8;
1104 ULONG ip2 = (*pPrimaryNBNS & 0x00FF0000) >> 16;
1105 ULONG ip3 = (*pPrimaryNBNS & 0xFF000000) >> 24;
1106
1107 // Set the value
1108 pTLVx12->mIPV4Address[0] = (INT8)ip0;
1109 pTLVx12->mIPV4Address[1] = (INT8)ip1;
1110 pTLVx12->mIPV4Address[2] = (INT8)ip2;
1111 pTLVx12->mIPV4Address[3] = (INT8)ip3;
1112
1113 offset += tlvx12Sz;
1114 }
1115
1116 // Add Secondary NBNS, if specified
1117 if (pSecondaryNBNS != 0)
1118 {
1119 // Check size
1120 WORD tlvx13Sz = sizeof( sWDSStartNetworkInterfaceRequest_SecondaryNBNS );
1121 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx13Sz)
1122 {
1123 return eGOBI_ERR_BUFFER_SZ;
1124 }
1125
1126 pHeader = (sQMIRawContentHeader*)(pOut + offset);
1127 pHeader->mTypeID = 0x13;
1128 pHeader->mLength = tlvx13Sz;
1129
1130 offset += sizeof( sQMIRawContentHeader );
1131
1132 sWDSStartNetworkInterfaceRequest_SecondaryNBNS * pTLVx13;
1133 pTLVx13 = (sWDSStartNetworkInterfaceRequest_SecondaryNBNS*)(pOut + offset);
1134 memset( pTLVx13, 0, tlvx13Sz );
1135
1136 ULONG ip0 = (*pSecondaryNBNS & 0x000000FF);
1137 ULONG ip1 = (*pSecondaryNBNS & 0x0000FF00) >> 8;
1138 ULONG ip2 = (*pSecondaryNBNS & 0x00FF0000) >> 16;
1139 ULONG ip3 = (*pSecondaryNBNS & 0xFF000000) >> 24;
1140
1141 // Set the value
1142 pTLVx13->mIPV4Address[0] = (INT8)ip0;
1143 pTLVx13->mIPV4Address[1] = (INT8)ip1;
1144 pTLVx13->mIPV4Address[2] = (INT8)ip2;
1145 pTLVx13->mIPV4Address[3] = (INT8)ip3;
1146
1147 offset += tlvx13Sz;
1148 }
1149
1150 // Add APN Name, if specified
1151 if (pAPNName != 0)
1152 {
1153 std::string apnName( pAPNName );
1154
1155 // Check size
1156 WORD tlvx14Sz = (WORD)apnName.size();
1157 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx14Sz)
1158 {
1159 return eGOBI_ERR_BUFFER_SZ;
1160 }
1161
1162 pHeader = (sQMIRawContentHeader*)(pOut + offset);
1163 pHeader->mTypeID = 0x14;
1164 pHeader->mLength = tlvx14Sz;
1165
1166 offset += sizeof( sQMIRawContentHeader );
1167
1168 // Set the value
1169 memcpy( (pOut + offset), apnName.c_str(), apnName.size() );
1170
1171 offset += tlvx14Sz;
1172 }
1173
1174 // Add IP Address, if specified
1175 if (pIPAddress != 0)
1176 {
1177 // Check size
1178 WORD tlvx15Sz = sizeof( sWDSStartNetworkInterfaceRequest_IPAddress );
1179 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx15Sz)
1180 {
1181 return eGOBI_ERR_BUFFER_SZ;
1182 }
1183
1184 pHeader = (sQMIRawContentHeader*)(pOut + offset);
1185 pHeader->mTypeID = 0x15;
1186 pHeader->mLength = tlvx15Sz;
1187
1188 offset += sizeof( sQMIRawContentHeader );
1189
1190 sWDSStartNetworkInterfaceRequest_IPAddress * pTLVx15;
1191 pTLVx15 = (sWDSStartNetworkInterfaceRequest_IPAddress*)(pOut + offset);
1192 memset( pTLVx15, 0, tlvx15Sz );
1193
1194 ULONG ip0 = (*pIPAddress & 0x000000FF);
1195 ULONG ip1 = (*pIPAddress & 0x0000FF00) >> 8;
1196 ULONG ip2 = (*pIPAddress & 0x00FF0000) >> 16;
1197 ULONG ip3 = (*pIPAddress & 0xFF000000) >> 24;
1198
1199 // Set the value
1200 pTLVx15->mIPV4Address[0] = (INT8)ip0;
1201 pTLVx15->mIPV4Address[1] = (INT8)ip1;
1202 pTLVx15->mIPV4Address[2] = (INT8)ip2;
1203 pTLVx15->mIPV4Address[3] = (INT8)ip3;
1204
1205 offset += tlvx15Sz;
1206 }
1207
1208 // Add Authentication, if specified
1209 if (pAuthentication != 0)
1210 {
1211 // Check size
1212 WORD tlvx16Sz = sizeof( sWDSStartNetworkInterfaceRequest_Authentication );
1213 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx16Sz)
1214 {
1215 return eGOBI_ERR_BUFFER_SZ;
1216 }
1217
1218 pHeader = (sQMIRawContentHeader*)(pOut + offset);
1219 pHeader->mTypeID = 0x16;
1220 pHeader->mLength = tlvx16Sz;
1221
1222 offset += sizeof( sQMIRawContentHeader );
1223
1224 sWDSStartNetworkInterfaceRequest_Authentication * pTLVx16;
1225 pTLVx16 = (sWDSStartNetworkInterfaceRequest_Authentication*)(pOut + offset);
1226 memset( pTLVx16, 0, tlvx16Sz );
1227
1228 // Set the value
1229 pTLVx16->mEnablePAP = ((*pAuthentication & 0x00000001) != 0);
1230 pTLVx16->mEnableCHAP = ((*pAuthentication & 0x00000002) != 0);
1231
1232 offset += tlvx16Sz;
1233 }
1234
1235 // Add Username, if specified
1236 if (pUsername != 0)
1237 {
1238 std::string username( pUsername );
1239
1240 // Check size
1241 WORD tlvx17Sz = (WORD)username.size();
1242 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx17Sz)
1243 {
1244 return eGOBI_ERR_BUFFER_SZ;
1245 }
1246
1247 pHeader = (sQMIRawContentHeader*)(pOut + offset);
1248 pHeader->mTypeID = 0x17;
1249 pHeader->mLength = tlvx17Sz;
1250
1251 offset += sizeof( sQMIRawContentHeader );
1252
1253 // Set the value
1254 memcpy( (pOut + offset), username.c_str(), username.size() );
1255
1256 offset += tlvx17Sz;
1257 }
1258
1259 // Add Password, if specified
1260 if (pPassword != 0)
1261 {
1262 std::string password( pPassword );
1263
1264 // Check size
1265 WORD tlvx18Sz = (WORD)password.size();
1266 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx18Sz)
1267 {
1268 return eGOBI_ERR_BUFFER_SZ;
1269 }
1270
1271 pHeader = (sQMIRawContentHeader*)(pOut + offset);
1272 pHeader->mTypeID = 0x18;
1273 pHeader->mLength = tlvx18Sz;
1274
1275 offset += sizeof( sQMIRawContentHeader );
1276
1277 // Set the value
1278 memcpy( (pOut + offset), password.c_str(), password.size() );
1279
1280 offset += tlvx18Sz;
1281 }
1282
1283 *pOutLen = offset;
1284
1285 return eGOBI_ERR_NONE;
1286 }
1287
1288 /*===========================================================================
1289 METHOD:
1290 ParseStartDataSession
1291
1292 DESCRIPTION:
1293 This function activates a packet data session
1294
1295 PARAMETERS:
1296 inLen [ I ] - Length of input buffer
1297 pIn [ I ] - Input buffer
1298 pSessionId [ O ] - The assigned session ID
1299 pFailureReason [ O ] - Upon call failure the failure reason provided
1300
1301 RETURN VALUE:
1302 ULONG - Return code
1303 ===========================================================================*/
1304 ULONG ParseStartDataSession(
1305 ULONG inLen,
1306 const BYTE * pIn,
1307 ULONG * pSessionId,
1308 ULONG * pFailureReason )
1309 {
1310 // Validate arguments
1311 if (pIn == 0
1312 || pSessionId == 0
1313 || pFailureReason == 0)
1314 {
1315 return eGOBI_ERR_INVALID_ARG;
1316 }
1317
1318 // Check mandatory response
1319 const sResultCode * pTLVx02;
1320 ULONG outLenx02;
1321 ULONG rc = GetTLV( inLen, pIn, 0x02, &outLenx02, (const BYTE **)&pTLVx02 );
1322 if (rc != eGOBI_ERR_NONE)
1323 {
1324 return rc;
1325 }
1326
1327 if (outLenx02 < sizeof( sResultCode ))
1328 {
1329 return eGOBI_ERR_MALFORMED_RSP;
1330 }
1331
1332 if (pTLVx02->mQMIResult != eQMIResults_Success)
1333 {
1334 rc = pTLVx02->mQMIError + eGOBI_ERR_QMI_OFFSET;
1335 }
1336
1337 if (rc != eGOBI_ERR_NONE)
1338 {
1339 // Still parse call end reason, if present
1340 const sWDSStartNetworkInterfaceResponse_CallEndReason * pTLVx10;
1341 ULONG outLenx10;
1342 ULONG rc2 = GetTLV( inLen, pIn, 0x10, &outLenx10, (const BYTE **)&pTLVx10 );
1343 if (rc2 == eGOBI_ERR_NONE)
1344 {
1345 if (outLenx10 >= sizeof( sWDSStartNetworkInterfaceResponse_CallEndReason ))
1346 {
1347 *pFailureReason = pTLVx10->mCallEnd;
1348 }
1349 }
1350
1351 return rc;
1352 }
1353
1354 // Find the Session ID
1355 const sWDSStartNetworkInterfaceResponse_PacketDataHandle * pTLVx01;
1356 ULONG outLenx01;
1357 rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 );
1358 if (rc == eGOBI_ERR_NONE)
1359 {
1360 if (outLenx01 < sizeof( sWDSStartNetworkInterfaceResponse_PacketDataHandle ))
1361 {
1362 return eGOBI_ERR_MALFORMED_RSP;
1363 }
1364
1365 *pSessionId = pTLVx01->mPacketDataHandle;
1366 }
1367
1368 // Session ID is mandatory, if it failed return that error
1369 return rc;
1370 }
1371
1372 /*===========================================================================
1373 METHOD:
1374 PackStopDataSession
1375
1376 DESCRIPTION:
1377 This function stops the current data session
1378
1379 PARAMETERS:
1380 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
1381 contain, upon output the number of BYTEs copied
1382 to pOut
1383 pOut [ O ] - Output buffer
1384 sessionId [ I ] - The ID of the session to terminate
1385
1386 RETURN VALUE:
1387 ULONG - Return code
1388 ===========================================================================*/
1389 ULONG PackStopDataSession(
1390 ULONG * pOutLen,
1391 BYTE * pOut,
1392 ULONG sessionId )
1393 {
1394 // Validate arguments
1395 if (pOut == 0)
1396 {
1397 return eGOBI_ERR_INVALID_ARG;
1398 }
1399
1400 // Add session ID
1401
1402 // Check size
1403 WORD tlvx01Sz = sizeof( sWDSStopNetworkInterfaceRequest_PacketDataHandle );
1404 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz)
1405 {
1406 return eGOBI_ERR_BUFFER_SZ;
1407 }
1408
1409 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut;
1410 pHeader->mTypeID = 0x01;
1411 pHeader->mLength = tlvx01Sz;
1412
1413 ULONG offset = sizeof( sQMIRawContentHeader );
1414
1415 sWDSStopNetworkInterfaceRequest_PacketDataHandle * pTLVx01;
1416 pTLVx01 = (sWDSStopNetworkInterfaceRequest_PacketDataHandle*)(pOut + offset);
1417 memset( pTLVx01, 0, tlvx01Sz );
1418
1419 // Set the value
1420 pTLVx01->mPacketDataHandle = sessionId;
1421
1422 offset += tlvx01Sz;
1423 *pOutLen = offset;
1424
1425 return eGOBI_ERR_NONE;
1426 }
1427
1428 /*===========================================================================
1429 METHOD:
1430 PackGetIPAddress
1431
1432 DESCRIPTION:
1433 This function returns the current packet data session IP address
1434
1435 PARAMETERS:
1436 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
1437 contain, upon output the number of BYTEs copied
1438 to pOut
1439 pOut [ O ] - Output buffer
1440
1441 RETURN VALUE:
1442 ULONG - Return code
1443 ===========================================================================*/
1444 ULONG PackGetIPAddress(
1445 ULONG * pOutLen,
1446 BYTE * pOut )
1447 {
1448 // Validate arguments
1449 if (pOut == 0)
1450 {
1451 return eGOBI_ERR_INVALID_ARG;
1452 }
1453
1454 // Request the settings
1455
1456 // Check size
1457 WORD tlvx10Sz = sizeof( sWDSGetCurrentSettingsRequest_RequestedSettings );
1458 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx10Sz)
1459 {
1460 return eGOBI_ERR_BUFFER_SZ;
1461 }
1462
1463 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut;
1464 pHeader->mTypeID = 0x10;
1465 pHeader->mLength = tlvx10Sz;
1466
1467 ULONG offset = sizeof( sQMIRawContentHeader );
1468
1469 sWDSGetCurrentSettingsRequest_RequestedSettings * pTLVx10;
1470 pTLVx10 = (sWDSGetCurrentSettingsRequest_RequestedSettings*)(pOut + offset);
1471 memset( pTLVx10, 0, tlvx10Sz );
1472
1473 // Set the value
1474 pTLVx10->mIPAddress = true;
1475
1476 offset += tlvx10Sz;
1477 *pOutLen = offset;
1478
1479 return eGOBI_ERR_NONE;
1480 }
1481
1482 /*===========================================================================
1483 METHOD:
1484 ParseGetIPAddress
1485
1486 DESCRIPTION:
1487 This function returns the current packet data session IP address
1488
1489 PARAMETERS:
1490 inLen [ I ] - Length of input buffer
1491 pIn [ I ] - Input buffer
1492 pIPAddress [ O ] - Assigned IPv4 address
1493
1494 RETURN VALUE:
1495 ULONG - Return code
1496 ===========================================================================*/
1497 ULONG ParseGetIPAddress(
1498 ULONG inLen,
1499 const BYTE * pIn,
1500 ULONG * pIPAddress )
1501 {
1502 // Validate arguments
1503 if (pIn == 0 || pIPAddress == 0)
1504 {
1505 return eGOBI_ERR_INVALID_ARG;
1506 }
1507
1508 // Find the IP Address
1509 const sWDSGetDefaultSettingsResponse_IPAddress * pTLVx1E;
1510 ULONG outLenx1E;
1511 ULONG rc = GetTLV( inLen, pIn, 0x1E, &outLenx1E, (const BYTE **)&pTLVx1E );
1512 if (rc == eGOBI_ERR_NONE)
1513 {
1514 if (outLenx1E < sizeof( sWDSGetDefaultSettingsResponse_IPAddress ))
1515 {
1516 return eGOBI_ERR_MALFORMED_RSP;
1517 }
1518
1519 ULONG ip0 = pTLVx1E->mIPV4Address[0];
1520 ULONG ip1 = pTLVx1E->mIPV4Address[1] << 8;
1521 ULONG ip2 = pTLVx1E->mIPV4Address[2] << 16;
1522 ULONG ip3 = pTLVx1E->mIPV4Address[3] << 24;
1523
1524 *pIPAddress = (ip0 | ip1 | ip2 | ip3);
1525 }
1526
1527 // If no IP address is found, fail
1528 return rc;
1529 }
1530
1531 /*===========================================================================
1532 METHOD:
1533 ParseGetConnectionRate
1534
1535 DESCRIPTION:
1536 This function returns connection rate information for the packet data
1537 connection
1538
1539 PARAMETERS:
1540 inLen [ I ] - Length of input buffer
1541 pIn [ I ] - Input buffer
1542 pCurrentChannelTXRate [ O ] - Current channel TX rate (bps)
1543 pCurrentChannelRXRate [ O ] - Current channel RX rate (bps)
1544 pMaxChannelTXRate [ O ] - Maximum channel TX rate (bps)
1545 pMaxChannelRXRate [ O ] - Maximum channel RX rate (bps)
1546
1547 RETURN VALUE:
1548 ULONG - Return code
1549 ===========================================================================*/
1550 ULONG ParseGetConnectionRate(
1551 ULONG inLen,
1552 const BYTE * pIn,
1553 ULONG * pCurrentChannelTXRate,
1554 ULONG * pCurrentChannelRXRate,
1555 ULONG * pMaxChannelTXRate,
1556 ULONG * pMaxChannelRXRate )
1557 {
1558 // Validate arguments
1559 if (pIn == 0
1560 || pCurrentChannelTXRate == 0
1561 || pCurrentChannelRXRate == 0
1562 || pMaxChannelTXRate == 0
1563 || pMaxChannelRXRate == 0)
1564 {
1565 return eGOBI_ERR_INVALID_ARG;
1566 }
1567
1568 // Find the rates
1569 const sWDSGetChannelRatesResponse_ChannelRates * pTLVx01;
1570 ULONG outLenx01;
1571 ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 );
1572 if (rc == eGOBI_ERR_NONE)
1573 {
1574 if (outLenx01 < sizeof( sWDSGetChannelRatesResponse_ChannelRates ))
1575 {
1576 return eGOBI_ERR_MALFORMED_RSP;
1577 }
1578
1579 // Get the values
1580 *pCurrentChannelTXRate = pTLVx01->mChannelTXRatebps;
1581 *pCurrentChannelRXRate = pTLVx01->mChannelRXRatebps;
1582 *pMaxChannelTXRate = pTLVx01->mMaxChannelTXRatebps;
1583 *pMaxChannelRXRate = pTLVx01->mMaxChannelRXRatebps;
1584 }
1585
1586 // If no rates are found, fail
1587 return rc;
1588 }
1589
1590 /*===========================================================================
1591 METHOD:
1592 PackGetPacketStatus
1593
1594 DESCRIPTION:
1595 This function returns the packet data transfer statistics since the start
1596 of the current packet data session
1597
1598 PARAMETERS:
1599 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
1600 contain, upon output the number of BYTEs copied
1601 to pOut
1602 pOut [ O ] - Output buffer
1603
1604 RETURN VALUE:
1605 ULONG - Return code
1606 ===========================================================================*/
1607 ULONG PackGetPacketStatus(
1608 ULONG * pOutLen,
1609 BYTE * pOut )
1610 {
1611 // Validate arguments
1612 if (pOut == 0)
1613 {
1614 return eGOBI_ERR_INVALID_ARG;
1615 }
1616
1617 // Request the settings
1618
1619 // Check size
1620 WORD tlvx01Sz = sizeof( sWDSGetPacketStatisticsRequest_PacketStatsMask );
1621 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz)
1622 {
1623 return eGOBI_ERR_BUFFER_SZ;
1624 }
1625
1626 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut;
1627 pHeader->mTypeID = 0x01;
1628 pHeader->mLength = tlvx01Sz;
1629
1630 ULONG offset = sizeof( sQMIRawContentHeader );
1631
1632 sWDSGetPacketStatisticsRequest_PacketStatsMask * pTLVx01;
1633 pTLVx01 = (sWDSGetPacketStatisticsRequest_PacketStatsMask*)(pOut + offset);
1634 memset( pTLVx01, 0, tlvx01Sz );
1635
1636 // Set the values
1637 pTLVx01->mReportTXPacketSuccesses = true;
1638 pTLVx01->mReportRXPacketSuccesses = true;
1639 pTLVx01->mReportTXPacketErrors = true;
1640 pTLVx01->mReportRXPacketErrors = true;
1641 pTLVx01->mReportTXOverflows = true;
1642 pTLVx01->mReportRXOverflows = true;
1643
1644 offset += tlvx01Sz;
1645 *pOutLen = offset;
1646
1647 return eGOBI_ERR_NONE;
1648 }
1649
1650 /*===========================================================================
1651 METHOD:
1652 ParseGetPacketStatus
1653
1654 DESCRIPTION:
1655 This function returns the packet data transfer statistics since the start
1656 of the current packet data session
1657
1658 PARAMETERS:
1659 inLen [ I ] - Length of input buffer
1660 pIn [ I ] - Input buffer
1661 pTXPacketSuccesses [ O ] - Packets transmitted without error
1662 pRXPacketSuccesses [ O ] - Packets received without error
1663 pTXPacketErrors [ O ] - Outgoing packets with framing errors
1664 pRXPacketErrors [ O ] - Incoming packets with framing errors
1665 pTXPacketOverflows [ O ] - Packets dropped because TX buffer overflowed
1666 pRXPacketOverflows [ O ] - Packets dropped because RX buffer overflowed
1667
1668 RETURN VALUE:
1669 ULONG - Return code
1670 ===========================================================================*/
1671 ULONG ParseGetPacketStatus(
1672 ULONG inLen,
1673 const BYTE * pIn,
1674 ULONG * pTXPacketSuccesses,
1675 ULONG * pRXPacketSuccesses,
1676 ULONG * pTXPacketErrors,
1677 ULONG * pRXPacketErrors,
1678 ULONG * pTXPacketOverflows,
1679 ULONG * pRXPacketOverflows )
1680 {
1681 // Validate arguments
1682 if (pIn == 0
1683 || pTXPacketSuccesses == 0
1684 || pRXPacketSuccesses == 0
1685 || pTXPacketErrors == 0
1686 || pRXPacketErrors == 0
1687 || pTXPacketOverflows == 0
1688 || pRXPacketOverflows == 0)
1689 {
1690 return eGOBI_ERR_INVALID_ARG;
1691 }
1692
1693 // NOTE: All TLVs are required. If any fail then all fail
1694
1695 // Find the TX packet sucesses
1696 const sWDSGetPacketStatisticsResponse_TXPacketSuccesses * pTLVx10;
1697 ULONG outLenx10;
1698 ULONG rc = GetTLV( inLen, pIn, 0x10, &outLenx10, (const BYTE **)&pTLVx10 );
1699 if (rc == eGOBI_ERR_NONE)
1700 {
1701 if (outLenx10 < sizeof( sWDSGetPacketStatisticsResponse_TXPacketSuccesses ))
1702 {
1703 return eGOBI_ERR_MALFORMED_RSP;
1704 }
1705 }
1706 else
1707 {
1708 return rc;
1709 }
1710
1711 // Find the RX packet sucesses
1712 const sWDSGetPacketStatisticsResponse_RXPacketSuccesses * pTLVx11;
1713 ULONG outLenx11;
1714 rc = GetTLV( inLen, pIn, 0x11, &outLenx11, (const BYTE **)&pTLVx11 );
1715 if (rc == eGOBI_ERR_NONE)
1716 {
1717 if (outLenx11 < sizeof( sWDSGetPacketStatisticsResponse_RXPacketSuccesses ))
1718 {
1719 return eGOBI_ERR_MALFORMED_RSP;
1720 }
1721 }
1722 else
1723 {
1724 return rc;
1725 }
1726
1727 // Find the TX packet errors
1728 const sWDSGetPacketStatisticsResponse_TXPacketErrors * pTLVx12;
1729 ULONG outLenx12;
1730 rc = GetTLV( inLen, pIn, 0x12, &outLenx12, (const BYTE **)&pTLVx12 );
1731 if (rc == eGOBI_ERR_NONE)
1732 {
1733 if (outLenx12 < sizeof( sWDSGetPacketStatisticsResponse_TXPacketErrors ))
1734 {
1735 return eGOBI_ERR_MALFORMED_RSP;
1736 }
1737 }
1738 else
1739 {
1740 return rc;
1741 }
1742
1743 // Find the RX packet errors
1744 const sWDSGetPacketStatisticsResponse_RXPacketErrors * pTLVx13;
1745 ULONG outLenx13;
1746 rc = GetTLV( inLen, pIn, 0x13, &outLenx13, (const BYTE **)&pTLVx13 );
1747 if (rc == eGOBI_ERR_NONE)
1748 {
1749 if (outLenx13 < sizeof( sWDSGetPacketStatisticsResponse_RXPacketErrors ))
1750 {
1751 return eGOBI_ERR_MALFORMED_RSP;
1752 }
1753 }
1754 else
1755 {
1756 return rc;
1757 }
1758
1759 // Find the TX packet overflows
1760 const sWDSGetPacketStatisticsResponse_TXOverflows * pTLVx14;
1761 ULONG outLenx14;
1762 rc = GetTLV( inLen, pIn, 0x14, &outLenx14, (const BYTE **)&pTLVx14 );
1763 if (rc == eGOBI_ERR_NONE)
1764 {
1765 if (outLenx14 < sizeof( sWDSGetPacketStatisticsResponse_TXOverflows ))
1766 {
1767 return eGOBI_ERR_MALFORMED_RSP;
1768 }
1769 }
1770 else
1771 {
1772 return rc;
1773 }
1774
1775 // Find the RX packet overflows
1776 const sWDSGetPacketStatisticsResponse_RXOverflows * pTLVx15;
1777 ULONG outLenx15;
1778 rc = GetTLV( inLen, pIn, 0x15, &outLenx15, (const BYTE **)&pTLVx15 );
1779 if (rc == eGOBI_ERR_NONE)
1780 {
1781 if (outLenx15 < sizeof( sWDSGetPacketStatisticsResponse_RXOverflows ))
1782 {
1783 return eGOBI_ERR_MALFORMED_RSP;
1784 }
1785 }
1786 else
1787 {
1788 return rc;
1789 }
1790
1791 // Populate the statistics
1792 *pTXPacketSuccesses = pTLVx10->mTXPacketSuccesses;
1793 *pRXPacketSuccesses = pTLVx11->mRXPacketSuccesses;
1794 *pTXPacketErrors = pTLVx12->mTXPacketErrors;
1795 *pRXPacketErrors = pTLVx13->mRXPacketErrors;
1796 *pTXPacketOverflows = pTLVx14->mTXOverflows;
1797 *pRXPacketOverflows = pTLVx15->mRXOverflows;
1798
1799 return eGOBI_ERR_NONE;
1800 }
1801
1802 /*===========================================================================
1803 METHOD:
1804 PackGetByteTotals
1805
1806 DESCRIPTION:
1807 This function returns the RX/TX byte counts since the start of the
1808 current packet data session
1809
1810 PARAMETERS:
1811 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
1812 contain, upon output the number of BYTEs copied
1813 to pOut
1814 pOut [ O ] - Output buffer
1815
1816 RETURN VALUE:
1817 ULONG - Return code
1818 ===========================================================================*/
1819 ULONG PackGetByteTotals(
1820 ULONG * pOutLen,
1821 BYTE * pOut )
1822 {
1823 // Validate arguments
1824 if (pOut == 0)
1825 {
1826 return eGOBI_ERR_INVALID_ARG;
1827 }
1828
1829 // Request the settings
1830
1831 // Check size
1832 WORD tlvx01Sz = sizeof( sWDSGetPacketStatisticsRequest_PacketStatsMask );
1833 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz)
1834 {
1835 return eGOBI_ERR_BUFFER_SZ;
1836 }
1837
1838 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut;
1839 pHeader->mTypeID = 0x01;
1840 pHeader->mLength = tlvx01Sz;
1841
1842 ULONG offset = sizeof( sQMIRawContentHeader );
1843
1844 sWDSGetPacketStatisticsRequest_PacketStatsMask * pTLVx01;
1845 pTLVx01 = (sWDSGetPacketStatisticsRequest_PacketStatsMask*)(pOut + offset);
1846 memset( pTLVx01, 0, tlvx01Sz );
1847
1848 // Set the values
1849 pTLVx01->mTXByteTotal = true;
1850 pTLVx01->mRXByteTotal = true;
1851
1852 offset += tlvx01Sz;
1853 *pOutLen = offset;
1854
1855 return eGOBI_ERR_NONE;
1856 }
1857
1858 /*===========================================================================
1859 METHOD:
1860 ParseGetByteTotals
1861
1862 DESCRIPTION:
1863 This function returns the RX/TX byte counts since the start of the
1864 current packet data session
1865
1866 PARAMETERS:
1867 inLen [ I ] - Length of input buffer
1868 pIn [ I ] - Input buffer
1869 pTXTotalBytes [ O ] - Bytes transmitted without error
1870 pRXTotalBytes [ O ] - Bytes received without error
1871
1872 RETURN VALUE:
1873 ULONG - Return code
1874 ===========================================================================*/
1875 ULONG ParseGetByteTotals(
1876 ULONG inLen,
1877 const BYTE * pIn,
1878 ULONGLONG * pTXTotalBytes,
1879 ULONGLONG * pRXTotalBytes )
1880 {
1881 // Validate arguments
1882 if (pIn == 0
1883 || pTXTotalBytes == 0
1884 || pRXTotalBytes == 0)
1885 {
1886 return eGOBI_ERR_INVALID_ARG;
1887 }
1888
1889 // NOTE: All TLVs are required. If any fail then all fail
1890
1891 // Find the TX bytes
1892 const sWDSGetPacketStatisticsResponse_TXBytes * pTLVx19;
1893 ULONG outLenx19;
1894 ULONG rc = GetTLV( inLen, pIn, 0x19, &outLenx19, (const BYTE **)&pTLVx19 );
1895 if (rc == eGOBI_ERR_NONE)
1896 {
1897 if (outLenx19 < sizeof( sWDSGetPacketStatisticsResponse_TXBytes ))
1898 {
1899 return eGOBI_ERR_MALFORMED_RSP;
1900 }
1901 }
1902 else
1903 {
1904 return rc;
1905 }
1906
1907 // Find the RX bytes
1908 const sWDSGetPacketStatisticsResponse_RXBytes * pTLVx1A;
1909 ULONG outLenx1A;
1910 rc = GetTLV( inLen, pIn, 0x1A, &outLenx1A, (const BYTE **)&pTLVx1A );
1911 if (rc == eGOBI_ERR_NONE)
1912 {
1913 if (outLenx1A < sizeof( sWDSGetPacketStatisticsResponse_RXBytes ))
1914 {
1915 return eGOBI_ERR_MALFORMED_RSP;
1916 }
1917 }
1918 else
1919 {
1920 return rc;
1921 }
1922
1923 // Populate the statistics
1924 *pTXTotalBytes = pTLVx19->mTXByteTotal;
1925 *pRXTotalBytes = pTLVx1A->mRXByteTotal;
1926
1927 return eGOBI_ERR_NONE;
1928 }
1929
1930 /*===========================================================================
1931 METHOD:
1932 PackSetMobileIP
1933
1934 DESCRIPTION:
1935 This function sets the current mobile IP setting
1936
1937 PARAMETERS:
1938 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
1939 contain, upon output the number of BYTEs copied
1940 to pOut
1941 pOut [ O ] - Output buffer
1942 mode [ I ] - Desired mobile IP setting
1943
1944 RETURN VALUE:
1945 ULONG - Return code
1946 ===========================================================================*/
1947 ULONG PackSetMobileIP(
1948 ULONG * pOutLen,
1949 BYTE * pOut,
1950 ULONG mode )
1951 {
1952 // Validate arguments
1953 if (pOut == 0)
1954 {
1955 return eGOBI_ERR_INVALID_ARG;
1956 }
1957
1958 // Set the mode
1959
1960 // Check size
1961 WORD tlvx01Sz = sizeof( sWDSSetMIPModeRequest_MobileIPMode );
1962 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz)
1963 {
1964 return eGOBI_ERR_BUFFER_SZ;
1965 }
1966
1967 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut;
1968 pHeader->mTypeID = 0x01;
1969 pHeader->mLength = tlvx01Sz;
1970
1971 ULONG offset = sizeof( sQMIRawContentHeader );
1972
1973 sWDSSetMIPModeRequest_MobileIPMode * pTLVx01;
1974 pTLVx01 = (sWDSSetMIPModeRequest_MobileIPMode*)(pOut + offset);
1975 memset( pTLVx01, 0, tlvx01Sz );
1976
1977 // Set the values
1978 pTLVx01->mMIPMode = (eQMIMobileIPModes)mode;
1979
1980 offset += tlvx01Sz;
1981 *pOutLen = offset;
1982
1983 return eGOBI_ERR_NONE;
1984 }
1985
1986 /*===========================================================================
1987 METHOD:
1988 ParseGetMobileIP
1989
1990 DESCRIPTION:
1991 This function gets the current mobile IP setting
1992
1993 PARAMETERS:
1994 inLen [ I ] - Length of input buffer
1995 pIn [ I ] - Input buffer
1996 pMode [ O ] - Current mobile IP setting
1997
1998 RETURN VALUE:
1999 ULONG - Return code
2000 ===========================================================================*/
2001 ULONG ParseGetMobileIP(
2002 ULONG inLen,
2003 const BYTE * pIn,
2004 ULONG * pMode )
2005 {
2006 // Validate arguments
2007 if (pIn == 0 || pMode == 0)
2008 {
2009 return eGOBI_ERR_INVALID_ARG;
2010 }
2011
2012 // Find the mode
2013 const sWDSGetMIPModeResponse_MobileIPMode * pTLVx01;
2014 ULONG outLenx01;
2015 ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 );
2016 if (rc == eGOBI_ERR_NONE)
2017 {
2018 if (outLenx01 < sizeof( sWDSGetMIPModeResponse_MobileIPMode ))
2019 {
2020 return eGOBI_ERR_MALFORMED_RSP;
2021 }
2022
2023 *pMode = pTLVx01->mMIPMode;
2024 }
2025
2026 return rc;
2027 }
2028
2029 /*===========================================================================
2030 METHOD:
2031 PackSetActiveMobileIPProfile
2032
2033 DESCRIPTION:
2034 This function sets the active mobile IP profile index
2035
2036 PARAMETERS:
2037 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
2038 contain, upon output the number of BYTEs copied
2039 to pOut
2040 pOut [ O ] - Output buffer
2041 pSPC [ I ] - Six digit service programming code
2042 index [ I ] - Desired mobile IP profile index
2043
2044 RETURN VALUE:
2045 ULONG - Return code
2046 ===========================================================================*/
2047 ULONG PackSetActiveMobileIPProfile(
2048 ULONG * pOutLen,
2049 BYTE * pOut,
2050 CHAR * pSPC,
2051 BYTE index )
2052 {
2053 // Validate arguments
2054 if (pOut == 0 || pSPC == 0 || pSPC[0] == 0)
2055 {
2056 return eGOBI_ERR_INVALID_ARG;
2057 }
2058
2059 std::string spc( pSPC );
2060 if (spc.size() > 6)
2061 {
2062 return eGOBI_ERR_INVALID_ARG;
2063 }
2064
2065 if (spc.find_first_not_of( "0123456789" ) != std::string::npos )
2066 {
2067 return eGOBI_ERR_INVALID_ARG;
2068 }
2069
2070 // Check size
2071 WORD tlvx01Sz = sizeof( sWDSSetActiveMIPProfileRequest_Index );
2072 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz)
2073 {
2074 return eGOBI_ERR_BUFFER_SZ;
2075 }
2076
2077 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut;
2078 pHeader->mTypeID = 0x01;
2079 pHeader->mLength = tlvx01Sz;
2080
2081 ULONG offset = sizeof( sQMIRawContentHeader );
2082
2083 sWDSSetActiveMIPProfileRequest_Index * pTLVx01;
2084 pTLVx01 = (sWDSSetActiveMIPProfileRequest_Index*)(pOut + offset);
2085 memset( pTLVx01, 0, tlvx01Sz );
2086
2087 // Set the values
2088 memcpy( &pTLVx01->mSPC[0], spc.c_str(), spc.size() );
2089 pTLVx01->mProfileIndex = index;
2090
2091 offset += tlvx01Sz;
2092 *pOutLen = offset;
2093
2094 return eGOBI_ERR_NONE;
2095 }
2096
2097 /*===========================================================================
2098 METHOD:
2099 ParseGetActiveMobileIPProfile
2100
2101 DESCRIPTION:
2102 This function gets the the active mobile IP profile index
2103
2104 PARAMETERS:
2105 inLen [ I ] - Length of input buffer
2106 pIn [ I ] - Input buffer
2107 pIndex [ O ] - Active mobile IP profile index
2108
2109 RETURN VALUE:
2110 ULONG - Return code
2111 ===========================================================================*/
2112 ULONG ParseGetActiveMobileIPProfile(
2113 ULONG inLen,
2114 const BYTE * pIn,
2115 BYTE * pIndex )
2116 {
2117 // Validate arguments
2118 if (pIn == 0 || pIndex == 0)
2119 {
2120 return eGOBI_ERR_INVALID_ARG;
2121 }
2122
2123 // Find the mode
2124 const sWDSGetActiveMIPProfileResponse_Index * pTLVx01;
2125 ULONG outLenx01;
2126 ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 );
2127 if (rc == eGOBI_ERR_NONE)
2128 {
2129 if (outLenx01 < sizeof( sWDSGetActiveMIPProfileResponse_Index ))
2130 {
2131 return eGOBI_ERR_MALFORMED_RSP;
2132 }
2133
2134 *pIndex = pTLVx01->mProfileIndex;
2135 }
2136
2137 return rc;
2138 }
2139
2140 /*===========================================================================
2141 METHOD:
2142 PackSetMobileIPProfile
2143
2144 DESCRIPTION:
2145 This function sets the specified mobile IP profile settings
2146
2147 PARAMETERS:
2148 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
2149 contain, upon output the number of BYTEs copied
2150 to pOut
2151 pOut [ O ] - Output buffer
2152 pSPC [ I ] - Six digit service programming code
2153 index [ I ] - Mobile IP profile ID
2154 pEnabled [ I ] - (Optional) Enable MIP profile?
2155 pAddress [ I ] - (Optional) Home IPv4 address
2156 pPrimaryHA [ I ] - (Optional) Primary home agent IPv4 address
2157 pSecondaryHA [ I ] - (Optional) Secondary home agent IPv4 address
2158 bRevTunneling [ I ] - (Optional) Enable reverse tunneling?
2159 pNAI [ I ] - (Optional) Network access identifier string
2160 pHASPI [ I ] - (Optional) HA security parameter index
2161 pAAASPI [ I ] - (Optional) AAA security parameter index
2162 pMNHA [ I ] - (Optional) MN-HA string
2163 pMNAAA [ I ] - (Optional) MN-AAA string
2164
2165 RETURN VALUE:
2166 ULONG - Return code
2167 ===========================================================================*/
2168 ULONG PackSetMobileIPProfile(
2169 ULONG * pOutLen,
2170 BYTE * pOut,
2171 CHAR * pSPC,
2172 BYTE index,
2173 BYTE * pEnabled,
2174 ULONG * pAddress,
2175 ULONG * pPrimaryHA,
2176 ULONG * pSecondaryHA,
2177 BYTE * pRevTunneling,
2178 CHAR * pNAI,
2179 ULONG * pHASPI,
2180 ULONG * pAAASPI,
2181 CHAR * pMNHA,
2182 CHAR * pMNAAA )
2183 {
2184 // Validate arguments
2185 if (pOut == 0 || pSPC == 0 || pSPC[0] == 0)
2186 {
2187 return eGOBI_ERR_INVALID_ARG;
2188 }
2189
2190 std::string spc( pSPC );
2191 if (spc.size() > 6)
2192 {
2193 return eGOBI_ERR_INVALID_ARG;
2194 }
2195
2196 if (spc.find_first_not_of( "0123456789" ) != std::string::npos )
2197 {
2198 return eGOBI_ERR_INVALID_ARG;
2199 }
2200
2201 // Check size
2202 WORD tlvx01Sz = sizeof( sWDSSetMIPProfileRequest_Index );
2203 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz)
2204 {
2205 return eGOBI_ERR_BUFFER_SZ;
2206 }
2207
2208 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut;
2209 pHeader->mTypeID = 0x01;
2210 pHeader->mLength = tlvx01Sz;
2211
2212 ULONG offset = sizeof( sQMIRawContentHeader );
2213
2214 sWDSSetMIPProfileRequest_Index * pTLVx01;
2215 pTLVx01 = (sWDSSetMIPProfileRequest_Index*)(pOut + offset);
2216 memset( pTLVx01, 0, tlvx01Sz );
2217
2218 // Set the values
2219 memcpy( &pTLVx01->mSPC[0], spc.c_str(), spc.size() );
2220 pTLVx01->mProfileIndex = index;
2221
2222 offset += tlvx01Sz;
2223
2224 // Add Enabled, if specified
2225 if (pEnabled != 0)
2226 {
2227 // Check size
2228 WORD tlvx10Sz = sizeof( sWDSSetMIPProfileRequest_State );
2229 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx10Sz)
2230 {
2231 return eGOBI_ERR_BUFFER_SZ;
2232 }
2233
2234 pHeader = (sQMIRawContentHeader*)(pOut + offset);
2235 pHeader->mTypeID = 0x10;
2236 pHeader->mLength = tlvx10Sz;
2237
2238 offset += sizeof( sQMIRawContentHeader );
2239
2240 sWDSSetMIPProfileRequest_State * pTLVx10;
2241 pTLVx10 = (sWDSSetMIPProfileRequest_State*)(pOut + offset);
2242 memset( pTLVx10, 0, tlvx10Sz );
2243
2244 // Set the value
2245 pTLVx10->mEnabled = (*pEnabled == 0 ? 0 : 1);
2246
2247 offset += tlvx10Sz;
2248 }
2249
2250 // Add Home Address, if specified
2251 if (pAddress != 0)
2252 {
2253 // Check size
2254 WORD tlvx11Sz = sizeof( sWDSSetMIPProfileRequest_HomeAddress );
2255 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx11Sz)
2256 {
2257 return eGOBI_ERR_BUFFER_SZ;
2258 }
2259
2260 pHeader = (sQMIRawContentHeader*)(pOut + offset);
2261 pHeader->mTypeID = 0x11;
2262 pHeader->mLength = tlvx11Sz;
2263
2264 offset += sizeof( sQMIRawContentHeader );
2265
2266 sWDSSetMIPProfileRequest_HomeAddress * pTLVx11;
2267 pTLVx11 = (sWDSSetMIPProfileRequest_HomeAddress*)(pOut + offset);
2268 memset( pTLVx11, 0, tlvx11Sz );
2269
2270 ULONG ip0 = (*pAddress & 0x000000FF);
2271 ULONG ip1 = (*pAddress & 0x0000FF00) >> 8;
2272 ULONG ip2 = (*pAddress & 0x00FF0000) >> 16;
2273 ULONG ip3 = (*pAddress & 0xFF000000) >> 24;
2274
2275 // Set the value
2276 pTLVx11->mIPV4Address[0] = (INT8)ip0;
2277 pTLVx11->mIPV4Address[1] = (INT8)ip1;
2278 pTLVx11->mIPV4Address[2] = (INT8)ip2;
2279 pTLVx11->mIPV4Address[3] = (INT8)ip3;
2280
2281 offset += tlvx11Sz;
2282 }
2283
2284 // Add Primary Home Agent Address, if specified
2285 if (pPrimaryHA != 0)
2286 {
2287 // Check size
2288 WORD tlvx12Sz = sizeof( sWDSSetMIPProfileRequest_PrimaryHomeAgentAddress );
2289 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx12Sz)
2290 {
2291 return eGOBI_ERR_BUFFER_SZ;
2292 }
2293
2294 pHeader = (sQMIRawContentHeader*)(pOut + offset);
2295 pHeader->mTypeID = 0x12;
2296 pHeader->mLength = tlvx12Sz;
2297
2298 offset += sizeof( sQMIRawContentHeader );
2299
2300 sWDSSetMIPProfileRequest_PrimaryHomeAgentAddress * pTLVx12;
2301 pTLVx12 = (sWDSSetMIPProfileRequest_PrimaryHomeAgentAddress*)(pOut + offset);
2302 memset( pTLVx12, 0, tlvx12Sz );
2303
2304 ULONG ip0 = (*pPrimaryHA & 0x000000FF);
2305 ULONG ip1 = (*pPrimaryHA & 0x0000FF00) >> 8;
2306 ULONG ip2 = (*pPrimaryHA & 0x00FF0000) >> 16;
2307 ULONG ip3 = (*pPrimaryHA & 0xFF000000) >> 24;
2308
2309 // Set the value
2310 pTLVx12->mIPV4Address[0] = (INT8)ip0;
2311 pTLVx12->mIPV4Address[1] = (INT8)ip1;
2312 pTLVx12->mIPV4Address[2] = (INT8)ip2;
2313 pTLVx12->mIPV4Address[3] = (INT8)ip3;
2314
2315 offset += tlvx12Sz;
2316 }
2317
2318 // Add Secondary Home Agent Address, if specified
2319 if (pSecondaryHA != 0)
2320 {
2321 // Check size
2322 WORD tlvx13Sz = sizeof( sWDSSetMIPProfileRequest_SecondaryHomeAgentAddress );
2323 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx13Sz)
2324 {
2325 return eGOBI_ERR_BUFFER_SZ;
2326 }
2327
2328 pHeader = (sQMIRawContentHeader*)(pOut + offset);
2329 pHeader->mTypeID = 0x13;
2330 pHeader->mLength = tlvx13Sz;
2331
2332 offset += sizeof( sQMIRawContentHeader );
2333
2334 sWDSSetMIPProfileRequest_SecondaryHomeAgentAddress * pTLVx13;
2335 pTLVx13 = (sWDSSetMIPProfileRequest_SecondaryHomeAgentAddress*)(pOut + offset);
2336 memset( pTLVx13, 0, tlvx13Sz );
2337
2338 ULONG ip0 = (*pSecondaryHA & 0x000000FF);
2339 ULONG ip1 = (*pSecondaryHA & 0x0000FF00) >> 8;
2340 ULONG ip2 = (*pSecondaryHA & 0x00FF0000) >> 16;
2341 ULONG ip3 = (*pSecondaryHA & 0xFF000000) >> 24;
2342
2343 // Set the value
2344 pTLVx13->mIPV4Address[0] = (INT8)ip0;
2345 pTLVx13->mIPV4Address[1] = (INT8)ip1;
2346 pTLVx13->mIPV4Address[2] = (INT8)ip2;
2347 pTLVx13->mIPV4Address[3] = (INT8)ip3;
2348
2349 offset += tlvx13Sz;
2350 }
2351
2352 // Add reverse tunneling, if specified
2353 if (pRevTunneling != 0)
2354 {
2355 // Check size
2356 WORD tlvx14Sz = sizeof( sWDSSetMIPProfileRequest_ReverseTunneling );
2357 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx14Sz)
2358 {
2359 return eGOBI_ERR_BUFFER_SZ;
2360 }
2361
2362 pHeader = (sQMIRawContentHeader*)(pOut + offset);
2363 pHeader->mTypeID = 0x14;
2364 pHeader->mLength = tlvx14Sz;
2365
2366 offset += sizeof( sQMIRawContentHeader );
2367
2368 sWDSSetMIPProfileRequest_ReverseTunneling * pTLVx14;
2369 pTLVx14 = (sWDSSetMIPProfileRequest_ReverseTunneling*)(pOut + offset);
2370 memset( pTLVx14, 0, tlvx14Sz );
2371
2372 // Set the value
2373 pTLVx14->mReverseTunneling = (*pRevTunneling == 0 ? 0 : 1);
2374
2375 offset += tlvx14Sz;
2376 }
2377
2378 // Add NAI, if specified
2379 if (pNAI != 0)
2380 {
2381 std::string nai( pNAI );
2382
2383 // Check size
2384 WORD tlvx15Sz = (WORD)nai.size();
2385 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx15Sz)
2386 {
2387 return eGOBI_ERR_BUFFER_SZ;
2388 }
2389
2390 pHeader = (sQMIRawContentHeader*)(pOut + offset);
2391 pHeader->mTypeID = 0x15;
2392 pHeader->mLength = tlvx15Sz;
2393
2394 offset += sizeof( sQMIRawContentHeader );
2395
2396 // Set the value
2397 memcpy( (pOut + offset), nai.c_str(), nai.size() );
2398
2399 offset += tlvx15Sz;
2400 }
2401
2402 // Add HA SPI, if specified
2403 if (pHASPI != 0)
2404 {
2405 // Check size
2406 WORD tlvx16Sz = sizeof( sWDSSetMIPProfileRequest_HASPI );
2407 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx16Sz)
2408 {
2409 return eGOBI_ERR_BUFFER_SZ;
2410 }
2411
2412 pHeader = (sQMIRawContentHeader*)(pOut + offset);
2413 pHeader->mTypeID = 0x16;
2414 pHeader->mLength = tlvx16Sz;
2415
2416 offset += sizeof( sQMIRawContentHeader );
2417
2418 sWDSSetMIPProfileRequest_HASPI * pTLVx16;
2419 pTLVx16 = (sWDSSetMIPProfileRequest_HASPI*)(pOut + offset);
2420 memset( pTLVx16, 0, tlvx16Sz );
2421
2422 // Set the value
2423 pTLVx16->mHASPI = *pHASPI;
2424
2425 offset += tlvx16Sz;
2426 }
2427
2428 // Add AAA SPI, if specified
2429 if (pAAASPI != 0)
2430 {
2431 // Check size
2432 WORD tlvx17Sz = sizeof( sWDSSetMIPProfileRequeste_AAASPI );
2433 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx17Sz)
2434 {
2435 return eGOBI_ERR_BUFFER_SZ;
2436 }
2437
2438 pHeader = (sQMIRawContentHeader*)(pOut + offset);
2439 pHeader->mTypeID = 0x17;
2440 pHeader->mLength = tlvx17Sz;
2441
2442 offset += sizeof( sQMIRawContentHeader );
2443
2444 sWDSSetMIPProfileRequeste_AAASPI * pTLVx17;
2445 pTLVx17 = (sWDSSetMIPProfileRequeste_AAASPI*)(pOut + offset);
2446 memset( pTLVx17, 0, tlvx17Sz );
2447
2448 // Set the value
2449 pTLVx17->mAAASPI = *pAAASPI;
2450
2451 offset += tlvx17Sz;
2452 }
2453
2454 // Add MN-HA key, if specified
2455 if (pMNHA != 0)
2456 {
2457 std::string mnha( pMNHA );
2458
2459 // Check size
2460 WORD tlvx18Sz = (WORD)mnha.size();
2461 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx18Sz)
2462 {
2463 return eGOBI_ERR_BUFFER_SZ;
2464 }
2465
2466 pHeader = (sQMIRawContentHeader*)(pOut + offset);
2467 pHeader->mTypeID = 0x18;
2468 pHeader->mLength = tlvx18Sz;
2469
2470 offset += sizeof( sQMIRawContentHeader );
2471
2472 // Set the value
2473 memcpy( (pOut + offset), mnha.c_str(), mnha.size() );
2474
2475 offset += tlvx18Sz;
2476 }
2477
2478 // Add MN-AAA key, if specified
2479 if (pMNHA != 0)
2480 {
2481 std::string mnaaa( pMNAAA );
2482
2483 // Check size
2484 WORD tlvx19Sz = (WORD)mnaaa.size();
2485 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx19Sz)
2486 {
2487 return eGOBI_ERR_BUFFER_SZ;
2488 }
2489
2490 pHeader = (sQMIRawContentHeader*)(pOut + offset);
2491 pHeader->mTypeID = 0x19;
2492 pHeader->mLength = tlvx19Sz;
2493
2494 offset += sizeof( sQMIRawContentHeader );
2495
2496 // Set the value
2497 memcpy( (pOut + offset), mnaaa.c_str(), mnaaa.size() );
2498
2499 offset += tlvx19Sz;
2500 }
2501
2502 // At least one of the optional parameters must have been set
2503 if (offset <= sizeof( sQMIRawContentHeader ) + tlvx01Sz)
2504 {
2505 return eGOBI_ERR_INVALID_ARG;
2506 }
2507
2508 *pOutLen = offset;
2509
2510 return eGOBI_ERR_NONE;
2511 }
2512
2513 /*===========================================================================
2514 METHOD:
2515 PackGetMobileIPProfile
2516
2517 DESCRIPTION:
2518 This function gets the specified mobile IP profile settings
2519
2520 PARAMETERS:
2521 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
2522 contain, upon output the number of BYTEs copied
2523 to pOut
2524 pOut [ O ] - Output buffer
2525 index [ I ] - Mobile IP profile ID
2526
2527 RETURN VALUE:
2528 ULONG - Return code
2529 ===========================================================================*/
2530 ULONG PackGetMobileIPProfile(
2531 ULONG * pOutLen,
2532 BYTE * pOut,
2533 BYTE index )
2534 {
2535 // Validate arguments
2536 if (pOut == 0)
2537 {
2538 return eGOBI_ERR_INVALID_ARG;
2539 }
2540
2541 // Check size
2542 WORD tlvx01Sz = sizeof( sWDSGetMIPProfileRequest_Index );
2543 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz)
2544 {
2545 return eGOBI_ERR_BUFFER_SZ;
2546 }
2547
2548 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut;
2549 pHeader->mTypeID = 0x01;
2550 pHeader->mLength = tlvx01Sz;
2551
2552 ULONG offset = sizeof( sQMIRawContentHeader );
2553
2554 sWDSGetMIPProfileRequest_Index * pTLVx01;
2555 pTLVx01 = (sWDSGetMIPProfileRequest_Index*)(pOut + offset);
2556 memset( pTLVx01, 0, tlvx01Sz );
2557
2558 // Set the values
2559 pTLVx01->mProfileIndex = index;
2560
2561 offset += tlvx01Sz;
2562 *pOutLen = offset;
2563
2564 return eGOBI_ERR_NONE;
2565 }
2566
2567 /*===========================================================================
2568 METHOD:
2569 ParseGetMobileIPProfile
2570
2571 DESCRIPTION:
2572 This function gets the specified mobile IP profile settings
2573
2574 PARAMETERS:
2575 inLen [ I ] - Length of input buffer
2576 pIn [ I ] - Input buffer
2577 pEnabled [ O ] - Mobile IP profile enabled?
2578 pAddress [ O ] - Home IPv4 address
2579 pPrimaryHA [ O ] - Primary home agent IPv4 address
2580 pSecondaryHA [ O ] - Secondary home agent IPv4 address
2581 pRevTunneling [ O ] - Reverse tunneling enabled?
2582 naiSize [ I ] - The maximum number of characters (including NULL
2583 terminator) that the NAI array can contain
2584 pNAI [ O ] - Network access identifier string
2585 pHASPI [ O ] - HA security parameter index
2586 pAAASPI [ O ] - AAA security parameter index
2587 pHAState [ O ] - HA key state
2588 pAAAState [ O ] - AAA key state
2589
2590 RETURN VALUE:
2591 ULONG - Return code
2592 ===========================================================================*/
2593 ULONG ParseGetMobileIPProfile(
2594 ULONG inLen,
2595 const BYTE * pIn,
2596 BYTE * pEnabled,
2597 ULONG * pAddress,
2598 ULONG * pPrimaryHA,
2599 ULONG * pSecondaryHA,
2600 BYTE * pRevTunneling,
2601 BYTE naiSize,
2602 CHAR * pNAI,
2603 ULONG * pHASPI,
2604 ULONG * pAAASPI,
2605 ULONG * pHAState,
2606 ULONG * pAAAState )
2607 {
2608 // Validate arguments
2609 if (pIn == 0
2610 || pEnabled == 0
2611 || pAddress == 0
2612 || pPrimaryHA == 0
2613 || pSecondaryHA == 0
2614 || pRevTunneling == 0
2615 || naiSize == 0
2616 || pNAI == 0
2617 || pHASPI == 0
2618 || pAAASPI == 0
2619 || pHAState == 0
2620 || pAAAState == 0)
2621 {
2622 return eGOBI_ERR_INVALID_ARG;
2623 }
2624
2625 // Assume errors
2626 *pEnabled = 0xff;
2627 *pAddress = 0xffffffff;
2628 *pPrimaryHA = 0xffffffff;
2629 *pSecondaryHA = 0xffffffff;
2630 *pRevTunneling = 0xff;
2631 *pHASPI = 0xffffffff;
2632 *pAAASPI = 0xffffffff;
2633 *pHAState = 0xffffffff;
2634 *pAAAState = 0xffffffff;
2635
2636 // Find the State
2637 const sWDSGetMIPProfileResponse_State * pTLVx10;
2638 ULONG outLenx10;
2639 ULONG rc = GetTLV( inLen, pIn, 0x10, &outLenx10, (const BYTE **)&pTLVx10 );
2640 if (rc == eGOBI_ERR_NONE)
2641 {
2642 if (outLenx10 < sizeof( sWDSGetMIPProfileResponse_State ))
2643 {
2644 return eGOBI_ERR_MALFORMED_RSP;
2645 }
2646
2647 *pEnabled = pTLVx10->mEnabled;
2648 }
2649
2650 // Find the Home Address
2651 const sWDSGetMIPProfileResponse_HomeAddress * pTLVx11;
2652 ULONG outLenx11;
2653 rc = GetTLV( inLen, pIn, 0x11, &outLenx11, (const BYTE **)&pTLVx11 );
2654 if (rc == eGOBI_ERR_NONE)
2655 {
2656 if (outLenx11 < sizeof( sWDSGetMIPProfileResponse_HomeAddress ))
2657 {
2658 return eGOBI_ERR_MALFORMED_RSP;
2659 }
2660
2661 ULONG ip0 = pTLVx11->mIPV4Address[0];
2662 ULONG ip1 = pTLVx11->mIPV4Address[1] << 8;
2663 ULONG ip2 = pTLVx11->mIPV4Address[2] << 16;
2664 ULONG ip3 = pTLVx11->mIPV4Address[3] << 24;
2665
2666 *pAddress = (ip0 | ip1 | ip2 | ip3);
2667 }
2668
2669 // Find the Primary Home Agent Address
2670 const sWDSGetMIPProfileResponse_PrimaryHomeAgentAddress * pTLVx12;
2671 ULONG outLenx12;
2672 rc = GetTLV( inLen, pIn, 0x12, &outLenx12, (const BYTE **)&pTLVx12 );
2673 if (rc == eGOBI_ERR_NONE)
2674 {
2675 if (outLenx12 < sizeof( sWDSGetMIPProfileResponse_PrimaryHomeAgentAddress ))
2676 {
2677 return eGOBI_ERR_MALFORMED_RSP;
2678 }
2679
2680 ULONG ip0 = pTLVx12->mIPV4Address[0];
2681 ULONG ip1 = pTLVx12->mIPV4Address[1] << 8;
2682 ULONG ip2 = pTLVx12->mIPV4Address[2] << 16;
2683 ULONG ip3 = pTLVx12->mIPV4Address[3] << 24;
2684
2685 *pPrimaryHA = (ip0 | ip1 | ip2 | ip3);
2686 }
2687
2688 // Find the Secondary Home Agent Address
2689 const sWDSGetMIPProfileResponse_SecondaryHomeAgentAddress * pTLVx13;
2690 ULONG outLenx13;
2691 rc = GetTLV( inLen, pIn, 0x13, &outLenx13, (const BYTE **)&pTLVx13 );
2692 if (rc == eGOBI_ERR_NONE)
2693 {
2694 if (outLenx13 < sizeof( sWDSGetMIPProfileResponse_SecondaryHomeAgentAddress ))
2695 {
2696 return eGOBI_ERR_MALFORMED_RSP;
2697 }
2698
2699 ULONG ip0 = pTLVx13->mIPV4Address[0];
2700 ULONG ip1 = pTLVx13->mIPV4Address[1] << 8;
2701 ULONG ip2 = pTLVx13->mIPV4Address[2] << 16;
2702 ULONG ip3 = pTLVx13->mIPV4Address[3] << 24;
2703
2704 *pSecondaryHA = (ip0 | ip1 | ip2 | ip3);
2705 }
2706
2707 // Find the Reverse tunneling, if enabled
2708 const sWDSGetMIPProfileResponse_ReverseTunneling * pTLVx14;
2709 ULONG outLenx14;
2710 rc = GetTLV( inLen, pIn, 0x14, &outLenx14, (const BYTE **)&pTLVx14 );
2711 if (rc == eGOBI_ERR_NONE)
2712 {
2713 if (outLenx10 < sizeof( sWDSGetMIPProfileResponse_ReverseTunneling ))
2714 {
2715 return eGOBI_ERR_MALFORMED_RSP;
2716 }
2717
2718 *pRevTunneling = pTLVx14->mReverseTunneling;
2719 }
2720
2721 // Find the NAI, if enabled
2722 const sWDSGetMIPProfileResponse_NAI * pTLVx15;
2723 ULONG outLenx15;
2724 rc = GetTLV( inLen, pIn, 0x15, &outLenx15, (const BYTE **)&pTLVx15 );
2725 if (rc == eGOBI_ERR_NONE)
2726 {
2727 if (naiSize < outLenx15 + 1)
2728 {
2729 return eGOBI_ERR_BUFFER_SZ;
2730 }
2731
2732 memcpy( pNAI, (const BYTE *)pTLVx15, outLenx15 );
2733
2734 // Null terminate
2735 pNAI[outLenx15] = 0;
2736 }
2737
2738 // Find the HA SPI
2739 const sWDSGetMIPProfileResponse_HASPI * pTLVx16;
2740 ULONG outLenx16;
2741 rc = GetTLV( inLen, pIn, 0x16, &outLenx16, (const BYTE **)&pTLVx16 );
2742 if (rc == eGOBI_ERR_NONE)
2743 {
2744 if (outLenx16 < sizeof( sWDSGetMIPProfileResponse_HASPI ))
2745 {
2746 return eGOBI_ERR_MALFORMED_RSP;
2747 }
2748
2749 *pHASPI = pTLVx16->mHASPI;
2750 }
2751
2752 // Find the AAA SPI
2753 const sWDSGetMIPProfileResponse_AAASPI * pTLVx17;
2754 ULONG outLenx17;
2755 rc = GetTLV( inLen, pIn, 0x17, &outLenx17, (const BYTE **)&pTLVx17 );
2756 if (rc == eGOBI_ERR_NONE)
2757 {
2758 if (outLenx17 < sizeof( sWDSGetMIPProfileResponse_AAASPI ))
2759 {
2760 return eGOBI_ERR_MALFORMED_RSP;
2761 }
2762
2763 *pAAASPI = pTLVx17->mAAASPI;
2764 }
2765
2766 // Find the HA state
2767 const sWDSGetMIPProfileResponse_HAState * pTLVx1A;
2768 ULONG outLenx1A;
2769 rc = GetTLV( inLen, pIn, 0x1A, &outLenx1A, (const BYTE **)&pTLVx1A );
2770 if (rc == eGOBI_ERR_NONE)
2771 {
2772 if (outLenx1A < sizeof( sWDSGetMIPProfileResponse_HAState ))
2773 {
2774 return eGOBI_ERR_MALFORMED_RSP;
2775 }
2776
2777 *pHAState = pTLVx1A->mKeyState;
2778 }
2779
2780 // Find the AAA state
2781 const sWDSGetMIPProfileResponse_AAAState * pTLVx1B;
2782 ULONG outLenx1B;
2783 rc = GetTLV( inLen, pIn, 0x1B, &outLenx1B, (const BYTE **)&pTLVx1B );
2784 if (rc == eGOBI_ERR_NONE)
2785 {
2786 if (outLenx1B < sizeof( sWDSGetMIPProfileResponse_AAAState ))
2787 {
2788 return eGOBI_ERR_MALFORMED_RSP;
2789 }
2790
2791 *pAAAState = pTLVx1B->mKeyState;
2792 }
2793
2794 return eGOBI_ERR_NONE;
2795 }
2796
2797 /*===========================================================================
2798 METHOD:
2799 PackSetMobileIPParameters
2800
2801 DESCRIPTION:
2802 This function sets the specified mobile IP parameters
2803
2804 PARAMETERS:
2805 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
2806 contain, upon output the number of BYTEs copied
2807 to pOut
2808 pOut [ O ] - Output buffer
2809 pSPC [ I ] - Six digit service programming code
2810 pMode [ I ] - (Optional) Desired mobile IP setting
2811 pRetryLimit [ I ] - (Optional) Retry attempt limit
2812 pRetryInterval [ I ] - (Optional) Retry attempt interval
2813 pReRegPeriod [ I ] - (Optional) Re-registration period
2814 pReRegTraffic [ I ] - (Optional) Re-registration only with traffic?
2815 pHAAuthenticator [ I ] - (Optional) MH-HA authenticator calculator?
2816 pHA2002bis [ I ] - (Optional) MH-HA RFC 2002bis authentication?
2817
2818 RETURN VALUE:
2819 ULONG - Return code
2820 ===========================================================================*/
2821 ULONG PackSetMobileIPParameters(
2822 ULONG * pOutLen,
2823 BYTE * pOut,
2824 CHAR * pSPC,
2825 ULONG * pMode,
2826 BYTE * pRetryLimit,
2827 BYTE * pRetryInterval,
2828 BYTE * pReRegPeriod,
2829 BYTE * pReRegTraffic,
2830 BYTE * pHAAuthenticator,
2831 BYTE * pHA2002bis )
2832 {
2833 // Validate arguments
2834 if (pOut == 0 || pSPC == 0 || pSPC[0] == 0)
2835 {
2836 return eGOBI_ERR_INVALID_ARG;
2837 }
2838
2839 std::string spc( pSPC );
2840 if (spc.size() > 6)
2841 {
2842 return eGOBI_ERR_INVALID_ARG;
2843 }
2844
2845 if (spc.find_first_not_of( "0123456789" ) != std::string::npos )
2846 {
2847 return eGOBI_ERR_INVALID_ARG;
2848 }
2849
2850 // Check size
2851 WORD tlvx01Sz = sizeof( sWDSSetMIPParametersRequest_SPC );
2852 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz)
2853 {
2854 return eGOBI_ERR_BUFFER_SZ;
2855 }
2856
2857 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut;
2858 pHeader->mTypeID = 0x01;
2859 pHeader->mLength = tlvx01Sz;
2860
2861 ULONG offset = sizeof( sQMIRawContentHeader );
2862
2863 sWDSSetMIPParametersRequest_SPC * pTLVx01;
2864 pTLVx01 = (sWDSSetMIPParametersRequest_SPC*)(pOut + offset);
2865 memset( pTLVx01, 0, tlvx01Sz );
2866
2867 // Set the values
2868 memcpy( &pTLVx01->mSPC[0], spc.c_str(), spc.size() );
2869
2870 offset += tlvx01Sz;
2871
2872 // Add Mode, if specified
2873 if (pMode != 0)
2874 {
2875 // Check size
2876 WORD tlvx10Sz = sizeof( sWDSSetMIPParametersRequest_MobileIPMode );
2877 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx10Sz)
2878 {
2879 return eGOBI_ERR_BUFFER_SZ;
2880 }
2881
2882 pHeader = (sQMIRawContentHeader*)(pOut + offset);
2883 pHeader->mTypeID = 0x10;
2884 pHeader->mLength = tlvx10Sz;
2885
2886 offset += sizeof( sQMIRawContentHeader );
2887
2888 sWDSSetMIPParametersRequest_MobileIPMode * pTLVx10;
2889 pTLVx10 = (sWDSSetMIPParametersRequest_MobileIPMode*)(pOut + offset);
2890 memset( pTLVx10, 0, tlvx10Sz );
2891
2892 // Set the value
2893 pTLVx10->mMIPMode = (eQMIMobileIPModes)*pMode;
2894
2895 offset += tlvx10Sz;
2896 }
2897
2898 // Add Retry Limit, if specified
2899 if (pRetryLimit != 0)
2900 {
2901 // Check size
2902 WORD tlvx11Sz = sizeof( sWDSSetMIPParametersRequest_RetryAttemptLimit );
2903 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx11Sz)
2904 {
2905 return eGOBI_ERR_BUFFER_SZ;
2906 }
2907
2908 pHeader = (sQMIRawContentHeader*)(pOut + offset);
2909 pHeader->mTypeID = 0x11;
2910 pHeader->mLength = tlvx11Sz;
2911
2912 offset += sizeof( sQMIRawContentHeader );
2913
2914 sWDSSetMIPParametersRequest_RetryAttemptLimit * pTLVx11;
2915 pTLVx11 = (sWDSSetMIPParametersRequest_RetryAttemptLimit*)(pOut + offset);
2916 memset( pTLVx11, 0, tlvx11Sz );
2917
2918 // Set the value
2919 pTLVx11->mRetryAttemptLimit = *pRetryLimit;
2920
2921 offset += tlvx11Sz;
2922 }
2923
2924 // Add Retry interval, if specified
2925 if (pRetryInterval != 0)
2926 {
2927 // Check size
2928 WORD tlvx12Sz = sizeof( sWDSSetMIPParametersRequest_RetryAttemptInterval );
2929 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx12Sz)
2930 {
2931 return eGOBI_ERR_BUFFER_SZ;
2932 }
2933
2934 pHeader = (sQMIRawContentHeader*)(pOut + offset);
2935 pHeader->mTypeID = 0x12;
2936 pHeader->mLength = tlvx12Sz;
2937
2938 offset += sizeof( sQMIRawContentHeader );
2939
2940 sWDSSetMIPParametersRequest_RetryAttemptInterval * pTLVx12;
2941 pTLVx12 = (sWDSSetMIPParametersRequest_RetryAttemptInterval*)(pOut + offset);
2942 memset( pTLVx12, 0, tlvx12Sz );
2943
2944 // Set the value
2945 pTLVx12->mRetryAttemptInterval = *pRetryInterval;
2946
2947 offset += tlvx12Sz;
2948 }
2949
2950 // Add Re-registration period, if specified
2951 if (pReRegPeriod != 0)
2952 {
2953 // Check size
2954 WORD tlvx13Sz = sizeof( sWDSSetMIPParametersRequest_ReRegistrationPeriod );
2955 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx13Sz)
2956 {
2957 return eGOBI_ERR_BUFFER_SZ;
2958 }
2959
2960 pHeader = (sQMIRawContentHeader*)(pOut + offset);
2961 pHeader->mTypeID = 0x13;
2962 pHeader->mLength = tlvx13Sz;
2963
2964 offset += sizeof( sQMIRawContentHeader );
2965
2966 sWDSSetMIPParametersRequest_ReRegistrationPeriod * pTLVx13;
2967 pTLVx13 = (sWDSSetMIPParametersRequest_ReRegistrationPeriod*)(pOut + offset);
2968 memset( pTLVx13, 0, tlvx13Sz );
2969
2970 // Set the value
2971 pTLVx13->mReRegistrationPeriod = *pReRegPeriod;
2972
2973 offset += tlvx13Sz;
2974 }
2975
2976 // Add Re-registration on traffic flag, if specified
2977 if (pReRegTraffic != 0)
2978 {
2979 // Check size
2980 WORD tlvx14Sz = sizeof( sWDSSetMIPParametersRequest_ReRegistrationOnlyWithTraffic );
2981 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx14Sz)
2982 {
2983 return eGOBI_ERR_BUFFER_SZ;
2984 }
2985
2986 pHeader = (sQMIRawContentHeader*)(pOut + offset);
2987 pHeader->mTypeID = 0x14;
2988 pHeader->mLength = tlvx14Sz;
2989
2990 offset += sizeof( sQMIRawContentHeader );
2991
2992 sWDSSetMIPParametersRequest_ReRegistrationOnlyWithTraffic * pTLVx14;
2993 pTLVx14 = (sWDSSetMIPParametersRequest_ReRegistrationOnlyWithTraffic*)(pOut + offset);
2994 memset( pTLVx14, 0, tlvx14Sz );
2995
2996 // Set the value
2997 pTLVx14->mReRegistrationOnlyWithTraffic = (*pReRegTraffic == 0 ? 0 : 1);
2998
2999 offset += tlvx14Sz;
3000 }
3001
3002 // Add HA authenticator flag, if specified
3003 if (pHAAuthenticator != 0)
3004 {
3005 // Check size
3006 WORD tlvx15Sz = sizeof( sWDSSetMIPParametersRequest_MNHAAuthenticatorCalculator );
3007 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx15Sz)
3008 {
3009 return eGOBI_ERR_BUFFER_SZ;
3010 }
3011
3012 pHeader = (sQMIRawContentHeader*)(pOut + offset);
3013 pHeader->mTypeID = 0x15;
3014 pHeader->mLength = tlvx15Sz;
3015
3016 offset += sizeof( sQMIRawContentHeader );
3017
3018 sWDSSetMIPParametersRequest_MNHAAuthenticatorCalculator * pTLVx15;
3019 pTLVx15 = (sWDSSetMIPParametersRequest_MNHAAuthenticatorCalculator*)(pOut + offset);
3020 memset( pTLVx15, 0, tlvx15Sz );
3021
3022 // Set the value
3023 pTLVx15->mMNHAAuthenticatorCalculator = (*pHAAuthenticator == 0 ? 0 : 1);
3024
3025 offset += tlvx15Sz;
3026 }
3027
3028 // Add HA RFC2002bis authentication flag, if specified
3029 if (pHA2002bis != 0)
3030 {
3031 // Check size
3032 WORD tlvx16Sz = sizeof( sWDSSetMIPParametersRequest_MNHARFC2002BISAuthentication );
3033 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx16Sz)
3034 {
3035 return eGOBI_ERR_BUFFER_SZ;
3036 }
3037
3038 pHeader = (sQMIRawContentHeader*)(pOut + offset);
3039 pHeader->mTypeID = 0x16;
3040 pHeader->mLength = tlvx16Sz;
3041
3042 offset += sizeof( sQMIRawContentHeader );
3043
3044 sWDSSetMIPParametersRequest_MNHARFC2002BISAuthentication * pTLVx16;
3045 pTLVx16 = (sWDSSetMIPParametersRequest_MNHARFC2002BISAuthentication*)(pOut + offset);
3046 memset( pTLVx16, 0, tlvx16Sz );
3047
3048 // Set the value
3049 pTLVx16->mMNHARFC2002BISAuthentication = (*pHA2002bis == 0 ? 0 : 1);
3050
3051 offset += tlvx16Sz;
3052 }
3053
3054 // At least one of the optional parameters must have been set
3055 if (offset <= sizeof( sQMIRawContentHeader ) + tlvx01Sz)
3056 {
3057 return eGOBI_ERR_INVALID_ARG;
3058 }
3059
3060 *pOutLen = offset;
3061
3062 return eGOBI_ERR_NONE;
3063 }
3064
3065 /*===========================================================================
3066 METHOD:
3067 ParseGetMobileIPParameters
3068
3069 DESCRIPTION:
3070 This function gets the mobile IP parameters
3071
3072 PARAMETERS:
3073 inLen [ I ] - Length of input buffer
3074 pIn [ I ] - Input buffer
3075 pMode [ O ] - Current mobile IP setting
3076 pRetryLimit [ O ] - Retry attempt limit
3077 pRetryInterval [ O ] - Retry attempt interval
3078 pReRegPeriod [ O ] - Re-registration period
3079 pReRegTraffic [ O ] - Re-registration only with traffic?
3080 pHAAuthenticator [ O ] - MH-HA authenticator calculator?
3081 pHA2002bis [ O ] - MH-HA RFC 2002bis authentication?
3082
3083 RETURN VALUE:
3084 ULONG - Return code
3085 ===========================================================================*/
3086 ULONG ParseGetMobileIPParameters(
3087 ULONG inLen,
3088 const BYTE * pIn,
3089 ULONG * pMode,
3090 BYTE * pRetryLimit,
3091 BYTE * pRetryInterval,
3092 BYTE * pReRegPeriod,
3093 BYTE * pReRegTraffic,
3094 BYTE * pHAAuthenticator,
3095 BYTE * pHA2002bis )
3096 {
3097 // Validate arguments
3098 if (pIn == 0
3099 || pMode == 0
3100 || pRetryLimit == 0
3101 || pRetryInterval == 0
3102 || pReRegPeriod == 0
3103 || pReRegTraffic == 0
3104 || pHAAuthenticator == 0
3105 || pHA2002bis == 0)
3106 {
3107 return eGOBI_ERR_INVALID_ARG;
3108 }
3109
3110 *pMode = 0xffffffff;
3111 *pRetryLimit = 0xff;
3112 *pRetryInterval = 0xff;
3113 *pReRegPeriod = 0xff;
3114 *pReRegTraffic = 0xff;
3115 *pHAAuthenticator = 0xff;
3116 *pHA2002bis = 0xff;
3117
3118 // Find the mode
3119 const sWDSGetMIPParametersResponse_MobileIPMode * pTLVx10;
3120 ULONG outLenx10;
3121 ULONG rc = GetTLV( inLen, pIn, 0x10, &outLenx10, (const BYTE **)&pTLVx10 );
3122 if (rc == eGOBI_ERR_NONE)
3123 {
3124 if (outLenx10 < sizeof( sWDSGetMIPParametersResponse_MobileIPMode ))
3125 {
3126 return eGOBI_ERR_MALFORMED_RSP;
3127 }
3128
3129 *pMode = pTLVx10->mMIPMode;
3130 }
3131
3132 // Find the Retry limit
3133 const sWDSGetMIPParametersResponse_RetryAttemptLimit * pTLVx11;
3134 ULONG outLenx11;
3135 rc = GetTLV( inLen, pIn, 0x11, &outLenx11, (const BYTE **)&pTLVx11 );
3136 if (rc == eGOBI_ERR_NONE)
3137 {
3138 if (outLenx11 < sizeof( sWDSGetMIPParametersResponse_RetryAttemptLimit ))
3139 {
3140 return eGOBI_ERR_MALFORMED_RSP;
3141 }
3142
3143 *pRetryLimit = pTLVx11->mRetryAttemptLimit;
3144 }
3145
3146 // Find the Retry Interval
3147 const sWDSGetMIPParametersResponse_RetryAttemptInterval * pTLVx12;
3148 ULONG outLenx12;
3149 rc = GetTLV( inLen, pIn, 0x12, &outLenx12, (const BYTE **)&pTLVx12 );
3150 if (rc == eGOBI_ERR_NONE)
3151 {
3152 if (outLenx12 < sizeof( sWDSGetMIPParametersResponse_RetryAttemptInterval ))
3153 {
3154 return eGOBI_ERR_MALFORMED_RSP;
3155 }
3156
3157 *pRetryInterval = pTLVx12->mRetryAttemptInterval;
3158 }
3159
3160 // Find the Re-registration period
3161 const sWDSGetMIPParametersResponse_ReRegistrationPeriod * pTLVx13;
3162 ULONG outLenx13;
3163 rc = GetTLV( inLen, pIn, 0x13, &outLenx13, (const BYTE **)&pTLVx13 );
3164 if (rc == eGOBI_ERR_NONE)
3165 {
3166 if (outLenx13 < sizeof( sWDSGetMIPParametersResponse_ReRegistrationPeriod ))
3167 {
3168 return eGOBI_ERR_MALFORMED_RSP;
3169 }
3170
3171 *pReRegPeriod = pTLVx13->mReRegistrationPeriod;
3172 }
3173
3174 // Find the Re-register on traffic flag
3175 const sWDSGetMIPParametersResponse_ReRegistrationOnlyWithTraffic * pTLVx14;
3176 ULONG outLenx14;
3177 rc = GetTLV( inLen, pIn, 0x14, &outLenx14, (const BYTE **)&pTLVx14 );
3178 if (rc == eGOBI_ERR_NONE)
3179 {
3180 if (outLenx14 < sizeof( sWDSGetMIPParametersResponse_ReRegistrationOnlyWithTraffic ))
3181 {
3182 return eGOBI_ERR_MALFORMED_RSP;
3183 }
3184
3185 *pReRegTraffic = pTLVx14->mReRegistrationOnlyWithTraffic;
3186 }
3187
3188 // Find the HA authenticator
3189 const sWDSGetMIPParametersResponse_MNHAAuthenticatorCalculator * pTLVx15;
3190 ULONG outLenx15;
3191 rc = GetTLV( inLen, pIn, 0x15, &outLenx15, (const BYTE **)&pTLVx15 );
3192 if (rc == eGOBI_ERR_NONE)
3193 {
3194 if (outLenx15 < sizeof( sWDSGetMIPParametersResponse_MNHAAuthenticatorCalculator ))
3195 {
3196 return eGOBI_ERR_MALFORMED_RSP;
3197 }
3198
3199 *pHAAuthenticator = pTLVx15->mMNHAAuthenticatorCalculator;
3200 }
3201
3202 // Find the HA RFC2002bis authentication flag
3203 const sWDSGetMIPParametersResponse_MNHARFC2002BISAuthentication * pTLVx16;
3204 ULONG outLenx16;
3205 rc = GetTLV( inLen, pIn, 0x16, &outLenx16, (const BYTE **)&pTLVx16 );
3206 if (rc == eGOBI_ERR_NONE)
3207 {
3208 if (outLenx16 < sizeof( sWDSGetMIPParametersResponse_MNHARFC2002BISAuthentication ))
3209 {
3210 return eGOBI_ERR_MALFORMED_RSP;
3211 }
3212
3213 *pHA2002bis = pTLVx16->mMNHARFC2002BISAuthentication;
3214 }
3215
3216 return eGOBI_ERR_NONE;
3217 }
3218
3219 /*===========================================================================
3220 METHOD:
3221 ParseGetLastMobileIPError
3222
3223 DESCRIPTION:
3224 This function gets the last mobile IP error
3225
3226 PARAMETERS:
3227 inLen [ I ] - Length of input buffer
3228 pIn [ I ] - Input buffer
3229 pError [ O ] - Last mobile IP error
3230
3231 RETURN VALUE:
3232 ULONG - Return code
3233 ===========================================================================*/
3234 ULONG ParseGetLastMobileIPError(
3235 ULONG inLen,
3236 const BYTE * pIn,
3237 ULONG * pError )
3238 {
3239 // Validate arguments
3240 if (pIn == 0 || pError == 0)
3241 {
3242 return eGOBI_ERR_INVALID_ARG;
3243 }
3244
3245 // Find the TLV
3246 const sWDSGetLastMIPStatusResponse_Status * pTLVx01;
3247 ULONG outLenx01;
3248 ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 );
3249 if (rc != eGOBI_ERR_NONE)
3250 {
3251 return rc;
3252 }
3253
3254 // Is the TLV large enough?
3255 if (outLenx01 < sizeof( sWDSGetLastMIPStatusResponse_Status ))
3256 {
3257 return eGOBI_ERR_MALFORMED_RSP;
3258 }
3259
3260 *pError = pTLVx01->mLastMIPStatus;
3261
3262 return eGOBI_ERR_NONE;
3263 }
3264
3265 /*===========================================================================
3266 METHOD:
3267 PackSetDNSSettings
3268
3269 DESCRIPTION:
3270 This function sets the DNS settings for the device
3271
3272 PARAMETERS:
3273 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
3274 contain, upon output the number of BYTEs copied
3275 to pOut
3276 pOut [ O ] - Output buffer
3277 pPrimaryDNS [ I ] - (Optional) Primary DNS IPv4 address
3278 pSecondaryDNS [ I ] - (Optional) Secondary DNS IPv4 address
3279
3280 RETURN VALUE:
3281 ULONG - Return code
3282 ===========================================================================*/
3283 ULONG PackSetDNSSettings(
3284 ULONG * pOutLen,
3285 BYTE * pOut,
3286 ULONG * pPrimaryDNS,
3287 ULONG * pSecondaryDNS )
3288 {
3289 // Validate arguments
3290 // At least one must be specified
3291 if (pOut == 0 || (pPrimaryDNS == 0 && pSecondaryDNS == 0))
3292 {
3293 return eGOBI_ERR_INVALID_ARG;
3294 }
3295
3296 sQMIRawContentHeader * pHeader;
3297 ULONG offset = 0;
3298
3299 // Add Primary DNS, if specified
3300 if (pPrimaryDNS != 0)
3301 {
3302 // Check size
3303 WORD tlvx10Sz = sizeof( sWDSSetDNSSettingRequest_PrimaryDNS );
3304 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx10Sz)
3305 {
3306 return eGOBI_ERR_BUFFER_SZ;
3307 }
3308
3309 pHeader = (sQMIRawContentHeader*)(pOut + offset);
3310 pHeader->mTypeID = 0x10;
3311 pHeader->mLength = tlvx10Sz;
3312
3313 offset += sizeof( sQMIRawContentHeader );
3314
3315 sWDSSetDNSSettingRequest_PrimaryDNS * pTLVx10;
3316 pTLVx10 = (sWDSSetDNSSettingRequest_PrimaryDNS*)(pOut + offset);
3317 memset( pTLVx10, 0, tlvx10Sz );
3318
3319 ULONG ip0 = (*pPrimaryDNS & 0x000000FF);
3320 ULONG ip1 = (*pPrimaryDNS & 0x0000FF00) >> 8;
3321 ULONG ip2 = (*pPrimaryDNS & 0x00FF0000) >> 16;
3322 ULONG ip3 = (*pPrimaryDNS & 0xFF000000) >> 24;
3323
3324 // Set the value
3325 pTLVx10->mIPV4Address[0] = (INT8)ip0;
3326 pTLVx10->mIPV4Address[1] = (INT8)ip1;
3327 pTLVx10->mIPV4Address[2] = (INT8)ip2;
3328 pTLVx10->mIPV4Address[3] = (INT8)ip3;
3329
3330 offset += tlvx10Sz;
3331 }
3332
3333 // Add Secondary DNS, if specified
3334 if (pSecondaryDNS != 0)
3335 {
3336 // Check size
3337 WORD tlvx11Sz = sizeof( sWDSSetDNSSettingRequest_SecondaryDNS );
3338 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx11Sz)
3339 {
3340 return eGOBI_ERR_BUFFER_SZ;
3341 }
3342
3343 pHeader = (sQMIRawContentHeader*)(pOut + offset);
3344 pHeader->mTypeID = 0x11;
3345 pHeader->mLength = tlvx11Sz;
3346
3347 offset += sizeof( sQMIRawContentHeader );
3348
3349 sWDSSetDNSSettingRequest_SecondaryDNS * pTLVx11;
3350 pTLVx11 = (sWDSSetDNSSettingRequest_SecondaryDNS*)(pOut + offset);
3351 memset( pTLVx11, 0, tlvx11Sz );
3352
3353 ULONG ip0 = (*pSecondaryDNS & 0x000000FF);
3354 ULONG ip1 = (*pSecondaryDNS & 0x0000FF00) >> 8;
3355 ULONG ip2 = (*pSecondaryDNS & 0x00FF0000) >> 16;
3356 ULONG ip3 = (*pSecondaryDNS & 0xFF000000) >> 24;
3357
3358 // Set the value
3359 pTLVx11->mIPV4Address[0] = (INT8)ip0;
3360 pTLVx11->mIPV4Address[1] = (INT8)ip1;
3361 pTLVx11->mIPV4Address[2] = (INT8)ip2;
3362 pTLVx11->mIPV4Address[3] = (INT8)ip3;
3363
3364 offset += tlvx11Sz;
3365 }
3366
3367 *pOutLen = offset;
3368
3369 return eGOBI_ERR_NONE;
3370 }
3371
3372 /*===========================================================================
3373 METHOD:
3374 ParseGetDNSSettings
3375
3376 DESCRIPTION:
3377 This function gets the DNS settings for the device
3378
3379 PARAMETERS:
3380 inLen [ I ] - Length of input buffer
3381 pIn [ I ] - Input buffer
3382 pPrimaryDNS [ O ] - Primary DNS IPv4 address
3383 pSecondaryDNS [ O ] - Secondary DNS IPv4 address
3384
3385 RETURN VALUE:
3386 ULONG - Return code
3387 ===========================================================================*/
3388 ULONG ParseGetDNSSettings(
3389 ULONG inLen,
3390 const BYTE * pIn,
3391 ULONG * pPrimaryDNS,
3392 ULONG * pSecondaryDNS )
3393 {
3394 // Validate arguments
3395 if (pIn == 0 || pPrimaryDNS == 0 || pSecondaryDNS == 0)
3396 {
3397 return eGOBI_ERR_INVALID_ARG;
3398 }
3399
3400 // Find the Primary DNS
3401 const sWDSGetDNSSettingResponse_PrimaryDNS * pTLVx10;
3402 ULONG outLenx10;
3403 ULONG rc = GetTLV( inLen, pIn, 0x10, &outLenx10, (const BYTE **)&pTLVx10 );
3404 if (rc == eGOBI_ERR_NONE)
3405 {
3406 if (outLenx10 < sizeof( sWDSGetDNSSettingResponse_PrimaryDNS ))
3407 {
3408 return eGOBI_ERR_MALFORMED_RSP;
3409 }
3410
3411 ULONG ip0 = pTLVx10->mIPV4Address[0];
3412 ULONG ip1 = pTLVx10->mIPV4Address[1] << 8;
3413 ULONG ip2 = pTLVx10->mIPV4Address[2] << 16;
3414 ULONG ip3 = pTLVx10->mIPV4Address[3] << 24;
3415
3416 *pPrimaryDNS = (ip0 | ip1 | ip2 | ip3);
3417 }
3418
3419 // Find the Secondary DNS
3420 const sWDSGetDNSSettingResponse_SecondaryDNS * pTLVx11;
3421 ULONG outLenx11;
3422 rc = GetTLV( inLen, pIn, 0x11, &outLenx11, (const BYTE **)&pTLVx11 );
3423 if (rc == eGOBI_ERR_NONE)
3424 {
3425 if (outLenx11 < sizeof( sWDSGetDNSSettingResponse_SecondaryDNS ))
3426 {
3427 return eGOBI_ERR_MALFORMED_RSP;
3428 }
3429
3430 ULONG ip0 = pTLVx11->mIPV4Address[0];
3431 ULONG ip1 = pTLVx11->mIPV4Address[1] << 8;
3432 ULONG ip2 = pTLVx11->mIPV4Address[2] << 16;
3433 ULONG ip3 = pTLVx11->mIPV4Address[3] << 24;
3434
3435 *pSecondaryDNS = (ip0 | ip1 | ip2 | ip3);
3436 }
3437
3438 return eGOBI_ERR_NONE;
3439 }
3440
3441 /*===========================================================================
3442 METHOD:
3443 ParseGetDataBearerTechnology
3444
3445 DESCRIPTION:
3446 This function retrieves the current data bearer technology (only
3447 valid when connected)
3448
3449 PARAMETERS:
3450 inLen [ I ] - Length of input buffer
3451 pIn [ I ] - Input buffer
3452 pDataCaps [ O ] - The data bearer technology
3453
3454 RETURN VALUE:
3455 ULONG - Return code
3456 ===========================================================================*/
3457 ULONG ParseGetDataBearerTechnology(
3458 ULONG inLen,
3459 const BYTE * pIn,
3460 ULONG * pDataBearer )
3461 {
3462 // Validate arguments
3463 if (pIn == 0 || pDataBearer == 0)
3464 {
3465 return eGOBI_ERR_INVALID_ARG;
3466 }
3467
3468 // Find the TLV
3469 const sWDSGetDataBearerTechnologyResponse_Technology * pTLVx01;
3470 ULONG outLenx01;
3471 ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 );
3472 if (rc != eGOBI_ERR_NONE)
3473 {
3474 return rc;
3475 }
3476
3477 // Is the TLV large enough?
3478 if (outLenx01 < sizeof( sWDSGetDataBearerTechnologyResponse_Technology ))
3479 {
3480 return eGOBI_ERR_MALFORMED_RSP;
3481 }
3482
3483 *pDataBearer = pTLVx01->mDataBearerTechnology;
3484
3485 return eGOBI_ERR_NONE;
3486 }