Debian Codegraph @

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