Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Tapi / Tizen.Tapi / SimStructs.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Runtime.InteropServices;
19 using System.Collections.Generic;
20 using System.Text;
21
22 namespace Tizen.Tapi
23 {
24     [StructLayout(LayoutKind.Sequential)]
25     internal struct SimImsiInfoStruct
26     {
27         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)]
28         internal string Mcc;
29         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)]
30         internal string Mnc;
31         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 11)]
32         internal string Msin;
33     }
34
35     [StructLayout(LayoutKind.Sequential)]
36     internal struct SimEccInfoStruct
37     {
38         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 31)]
39         internal string Name;
40         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 7)]
41         internal string Number;
42         internal SimEccEmergencyServiceType Type;
43     }
44
45     [StructLayout(LayoutKind.Sequential)]
46     internal struct SimEccInfoListStruct
47     {
48         internal int Count;
49         [MarshalAs(UnmanagedType.ByValArray, SizeConst = 15, ArraySubType = UnmanagedType.LPStruct)]
50         internal SimEccInfoStruct[] ListInfo;
51     }
52
53     [StructLayout(LayoutKind.Explicit)]
54     internal struct CfDataStruct
55     {
56         [FieldOffset(0)]
57         internal SimCfisStruct Cfis;
58         [FieldOffset(0)]
59         internal SimCphsCfStruct CphsCf;
60     }
61
62     [StructLayout(LayoutKind.Sequential)]
63     internal struct SimCallForwardRequestStruct
64     {
65         internal int IsCphs;
66         internal CfDataStruct CfData;
67     }
68
69     [StructLayout(LayoutKind.Sequential)]
70     internal struct SimCfisStruct
71     {
72         internal int RecIndex;
73         internal byte MspNum;
74         internal byte CfuStatus;
75         internal SimTypeOfNumber Ton;
76         internal SimNumberPlanIdentity Npi;
77         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 21)]
78         internal string CfuNum;
79         internal byte Cc2Id;
80         internal byte Ext7Id;
81     }
82
83     [StructLayout(LayoutKind.Sequential)]
84     internal struct SimCfisListStruct
85     {
86         internal int ProfileCount;
87         [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2, ArraySubType = UnmanagedType.LPStruct)]
88         internal SimCfisStruct[] CfisList;
89     }
90
91     [StructLayout(LayoutKind.Sequential)]
92     internal struct SimCphsCfStruct
93     {
94         internal int Line1;
95         internal int Line2;
96         internal int Fax;
97         internal int Data;
98     }
99
100     [StructLayout(LayoutKind.Sequential)]
101     internal struct SimCallForwardResponseStruct
102     {
103         internal int IsCphs;
104         internal SimCfisListStruct CfList;
105         internal SimCphsCfStruct CphsCf;
106     }
107
108     [StructLayout(LayoutKind.Explicit)]
109     internal struct MwData
110     {
111         [FieldOffset(0)]
112         internal SimMwisStruct Mwis;
113         [FieldOffset(0)]
114         internal SimCphsMwStruct CphsMw;
115     }
116
117     [StructLayout(LayoutKind.Sequential)]
118     internal struct SimMessageWaitingRequestStruct
119     {
120         internal int IsCphs;
121         internal MwData Mw;
122     }
123
124     [StructLayout(LayoutKind.Sequential)]
125     internal struct SimMwisStruct
126     {
127         internal int RecIndex;
128         internal byte IndicatorStatus;
129         internal int VoiceCount;
130         internal int FaxCount;
131         internal int EmailCount;
132         internal int OtherCount;
133         internal int VideoCount;
134     }
135
136     [StructLayout(LayoutKind.Sequential)]
137     internal struct SimMwisListStruct
138     {
139         internal int ProfileCount;
140         [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2, ArraySubType = UnmanagedType.LPStruct)]
141         internal SimMwisStruct[] MwList;
142     }
143
144     [StructLayout(LayoutKind.Sequential)]
145     internal struct SimCphsMwStruct
146     {
147         internal int Voice1;
148         internal int Voice2;
149         internal int Fax;
150         internal int Data;
151     }
152
153     [StructLayout(LayoutKind.Sequential)]
154     internal struct SimMessageWaitingResponseStruct
155     {
156         internal int IsCphs;
157         internal SimMwisListStruct MwList;
158         internal SimCphsMwStruct CphsMw;
159     }
160
161     [StructLayout(LayoutKind.Sequential)]
162     internal struct SimMailboxNumberStruct
163     {
164         internal int IsCphs;
165         internal int RecIndex;
166         internal int ProfileNum;
167         internal SimMailboxType MbType;
168         internal int AlphaMaxLen;
169         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 31)]
170         internal string AlphaId;
171         internal SimTypeOfNumber Ton;
172         internal SimNumberPlanIdentity Npi;
173         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 21)]
174         internal string Number;
175         internal byte CcId;
176         internal byte Ext1Id;
177     }
178
179     [StructLayout(LayoutKind.Sequential)]
180     internal struct SimMailboxListStruct
181     {
182         internal int Count;
183         [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10, ArraySubType = UnmanagedType.LPStruct)]
184         internal SimMailboxNumberStruct[] List;
185     }
186
187     [StructLayout(LayoutKind.Sequential)]
188     internal struct SimAuthenticationDataStruct
189     {
190         internal SimAuthenticationType AuthType;
191         internal int RandLength;
192         internal int AutnLength;
193         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
194         internal string RandData;
195         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
196         internal string AutnData;
197     }
198
199     [StructLayout(LayoutKind.Sequential)]
200     internal struct SimAuthenticationResponseStruct
201     {
202         internal SimAuthenticationType AuthType;
203         internal SimAuthenticationResult AuthResult;
204         internal int RespLength;
205         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
206         internal string RespData;
207         internal int AuthKeyLength;
208         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
209         internal string AuthKey;
210         internal int CipherLength;
211         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
212         internal string CipherData;
213         internal int IntegrityLength;
214         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
215         internal string IntegrityData;
216     }
217
218     [StructLayout(LayoutKind.Sequential)]
219     internal struct SimPinDataStruct
220     {
221         internal SimPinType Type;
222         [MarshalAs(UnmanagedType.LPStr)]
223         internal string Pin;
224         internal uint PinLength;
225     }
226
227     [StructLayout(LayoutKind.Sequential)]
228     internal struct SimFacilityStruct
229     {
230         internal SimLockType LockType;
231         [MarshalAs(UnmanagedType.LPStr)]
232         internal string Password;
233         internal int PasswordLength;
234     }
235
236     [StructLayout(LayoutKind.Sequential)]
237     internal struct SimFacilityResultStruct
238     {
239         internal SimLockType Type;
240         internal int RetryCount;
241     }
242
243     [StructLayout(LayoutKind.Sequential)]
244     internal struct SimFacilityInfoStruct
245     {
246         internal SimLockType Type;
247         internal SimFacilityStatus Status;
248     }
249
250     [StructLayout(LayoutKind.Sequential)]
251     internal struct SimApduStruct
252     {
253         internal ushort ApduLen;
254         [MarshalAs(UnmanagedType.LPStr)]
255         internal string Apdu;
256     }
257
258     [StructLayout(LayoutKind.Sequential)]
259     internal struct SimApduResponseStruct
260     {
261         internal ushort RespLen;
262         [MarshalAs(UnmanagedType.ByValArray, SizeConst = 5120)]
263         internal byte[] ApduResp;
264     }
265
266     [StructLayout(LayoutKind.Sequential)]
267     internal struct SimIccIdInfoStruct
268     {
269         internal int IccLength;
270         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
271         internal string IccNumber;
272     }
273
274     [StructLayout(LayoutKind.Sequential)]
275     internal struct SimCphsServiceTableStruct
276     {
277         internal int CustomerServiceProfile;
278         internal int ServiceStringTable;
279         internal int MailboxNumbers;
280         internal int OperatorNameShortForm;
281         internal int InformationNumbers;
282     }
283
284     [StructLayout(LayoutKind.Sequential)]
285     internal struct SimCphsInfoStruct
286     {
287         internal SimCphsPhaseType CphsPhase;
288         internal SimCphsServiceTableStruct CphsServiceTable;
289     }
290
291     [StructLayout(LayoutKind.Explicit)]
292     internal struct CstServiceStrct
293     {
294         [FieldOffset(0)]
295         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 47)]
296         internal string CdmaService;
297         [FieldOffset(0)]
298         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 41)]
299         internal string CsimService;
300     }
301
302     [StructLayout(LayoutKind.Sequential)]
303     internal struct SimCstStrct
304     {
305         internal SimCdmaServiceTable CdmaSvcTable;
306         internal CstServiceStrct Cst;
307     }
308
309     [StructLayout(LayoutKind.Explicit)]
310     internal struct ServiceTable
311     {
312         [FieldOffset(0)]
313         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 56)]
314         internal string SimSstService;
315         [FieldOffset(0)]
316         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
317         internal string SimUstService;
318         [FieldOffset(0)]
319         internal SimCstStrct Cst;
320     }
321
322     [StructLayout(LayoutKind.Sequential)]
323     internal struct SimServiceTableStruct
324     {
325         internal SimCardType SimType;
326         internal ServiceTable Table;
327     }
328
329     [StructLayout(LayoutKind.Sequential)]
330     internal struct SimSubscriberInfoStruct
331     {
332         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 27)]
333         internal string Number;
334         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 31)]
335         internal string Name;
336     }
337
338     [StructLayout(LayoutKind.Sequential)]
339     internal struct SimMsisdnListStruct
340     {
341         internal int Count;
342         [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3, ArraySubType = UnmanagedType.LPStruct)]
343         internal SimSubscriberInfoStruct[] List;
344     }
345
346     [StructLayout(LayoutKind.Sequential)]
347     internal struct SimOplmnwactStruct
348     {
349         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 7)]
350         internal string Plmn;
351         internal int IsUmts;
352         internal int IsGsm;
353     }
354
355     [StructLayout(LayoutKind.Sequential)]
356     internal struct SimOplmnwactListStruct
357     {
358         internal int Count;
359         [MarshalAs(UnmanagedType.ByValArray, SizeConst = 100, ArraySubType = UnmanagedType.LPStruct)]
360         internal SimOplmnwactStruct[] List;
361     }
362
363     [StructLayout(LayoutKind.Sequential)]
364     internal struct SimSpnStruct
365     {
366         internal byte DisplayCondition;
367         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 41)]
368         internal string Spn;
369     }
370
371     [StructLayout(LayoutKind.Sequential)]
372     internal struct SimCphsNetNameStruct
373     {
374         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 41)]
375         internal string FullName;
376         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 11)]
377         internal string ShortName;
378     }
379
380     [StructLayout(LayoutKind.Sequential)]
381     internal struct SimPinResultStruct
382     {
383         internal SimPinType Type;
384         internal int RetryCount;
385     }
386
387     [StructLayout(LayoutKind.Sequential)]
388     internal struct SimLockInfoStruct
389     {
390         internal SimLockType Type;
391         internal SimLockStatus Status;
392         internal int RetryCount;
393     }
394
395     [StructLayout(LayoutKind.Sequential)]
396     internal struct SimAtrResponseStruct
397     {
398         internal ushort AtrRespLen;
399         [MarshalAs(UnmanagedType.ByValArray, SizeConst = 5120)]
400         internal byte[] AtrResp;
401     }
402
403     [StructLayout(LayoutKind.Sequential)]
404     internal struct SimImpuListStruct
405     {
406         internal uint Count;
407         internal IntPtr List;
408     }
409
410     [StructLayout(LayoutKind.Sequential)]
411     internal struct SimPcscfStruct
412     {
413         internal SimPcscfType Type;
414         [MarshalAs(UnmanagedType.LPStr)]
415         internal string Pcscf;
416     }
417
418     [StructLayout(LayoutKind.Sequential)]
419     internal struct SimPcscfListStruct
420     {
421         internal uint Count;
422         internal IntPtr List;
423     }
424
425     internal static class SimStructConversions
426     {
427         internal static SimImsiInfo ConvertSimImsiInfoStruct(SimImsiInfoStruct imsiStruct)
428         {
429             SimImsiInfo imsi = new SimImsiInfo();
430             imsi.CountryCode = imsiStruct.Mcc;
431             imsi.NetworkCode = imsiStruct.Mnc;
432             imsi.StationId = imsiStruct.Msin;
433             return imsi;
434         }
435
436         internal static SimEccInfo ConvertSimEccInfoStruct(SimEccInfoStruct eccStruct)
437         {
438             SimEccInfo ecc = new SimEccInfo();
439             ecc.NameInfo = eccStruct.Name;
440             ecc.NumberInfo = eccStruct.Number;
441             ecc.TypeInfo = eccStruct.Type;
442             return ecc;
443         }
444
445         internal static SimEccInfoList ConvertSimEccInfoListStruct(SimEccInfoListStruct listStruct)
446         {
447             SimEccInfoList eccList = new SimEccInfoList();
448             eccList.EccCount = listStruct.Count;
449             List<SimEccInfo> eccInfoList = new List<SimEccInfo>();
450             foreach (SimEccInfoStruct info in listStruct.ListInfo)
451             {
452                 eccInfoList.Add(ConvertSimEccInfoStruct(info));
453             }
454
455             eccList.List = eccInfoList;
456             return eccList;
457         }
458
459         internal static SimIccIdInfo ConvertSimIccIdInfoStruct(SimIccIdInfoStruct iccStruct)
460         {
461             SimIccIdInfo iccId = new SimIccIdInfo();
462             iccId.Length = iccStruct.IccLength;
463             iccId.Number = iccStruct.IccNumber;
464             return iccId;
465         }
466
467         internal static SimCfis ConvertSimCfisStruct(SimCfisStruct cfisStruct)
468         {
469             SimCfis cfis = new SimCfis();
470             cfis.RecIndex = cfisStruct.RecIndex;
471             cfis.MspNum = cfisStruct.MspNum;
472             cfis.CfuStatus = cfisStruct.CfuStatus;
473             cfis.Ton = cfisStruct.Ton;
474             cfis.Npi = cfisStruct.Npi;
475             cfis.CfuNum = cfisStruct.CfuNum;
476             cfis.Cc2Id = cfisStruct.Cc2Id;
477             cfis.Ext7Id = cfisStruct.Ext7Id;
478             return cfis;
479         }
480
481         internal static SimCfisList ConvertSimCfisListStruct(SimCfisListStruct listStruct)
482         {
483             SimCfisList cfisList = new SimCfisList();
484             cfisList.Count = listStruct.ProfileCount;
485             List<SimCfis> cfis = new List<SimCfis>();
486             foreach (SimCfisStruct cfStruct in listStruct.CfisList)
487             {
488                 cfis.Add(ConvertSimCfisStruct(cfStruct));
489             }
490
491             cfisList.List = cfis;
492             return cfisList;
493         }
494
495         internal static SimCphsCf ConvertSimCphsCfStruct(SimCphsCfStruct cphsCfStruct)
496         {
497             SimCphsCf cphs = new SimCphsCf();
498             cphs.Line1 = cphsCfStruct.Line1;
499             cphs.Line2 = cphsCfStruct.Line2;
500             cphs.Fax = cphsCfStruct.Fax;
501             cphs.Data = cphsCfStruct.Data;
502             return cphs;
503         }
504
505         internal static SimCallForwardResponse ConvertSimCallForwardResponseStruct(SimCallForwardResponseStruct respStruct)
506         {
507             SimCallForwardResponse resp = new SimCallForwardResponse();
508             if (respStruct.IsCphs == 1)
509             {
510                 resp.IsCphsCf = true;
511             }
512
513             else if (respStruct.IsCphs == 0)
514             {
515                 resp.IsCphsCf = false;
516             }
517
518             resp.List = ConvertSimCfisListStruct(respStruct.CfList);
519             resp.CphsCfInfo = ConvertSimCphsCfStruct(respStruct.CphsCf);
520             return resp;
521         }
522
523         internal static SimMwis ConvertSimMwisStruct(SimMwisStruct mwisStruct)
524         {
525             SimMwis mwis = new SimMwis();
526             mwis.RecIndex = mwisStruct.RecIndex;
527             mwis.IndicatorStatus = mwisStruct.IndicatorStatus;
528             mwis.VoiceCount = mwisStruct.VoiceCount;
529             mwis.FaxCount = mwisStruct.FaxCount;
530             mwis.EmailCount = mwisStruct.EmailCount;
531             mwis.OtherCount = mwisStruct.OtherCount;
532             mwis.VideoCount = mwisStruct.VideoCount;
533             return mwis;
534         }
535
536         internal static SimMwisList ConvertSimMwisListStruct(SimMwisListStruct mwStruct)
537         {
538             SimMwisList mwList = new SimMwisList();
539             mwList.Count = mwStruct.ProfileCount;
540             List<SimMwis> mwisList = new List<SimMwis>();
541             foreach (SimMwisStruct mwisStruct in mwStruct.MwList)
542             {
543                 mwisList.Add(ConvertSimMwisStruct(mwisStruct));
544             }
545
546             mwList.List = mwisList;
547             return mwList;
548         }
549
550         internal static SimCphsMw ConvertSimCphsMwStruct(SimCphsMwStruct cphsStruct)
551         {
552             SimCphsMw cphsMw = new SimCphsMw();
553             if (cphsStruct.Voice1 == 1)
554             {
555                 cphsMw.IsVoice1 = true;
556             }
557
558             else
559             {
560                 cphsMw.IsVoice1 = false;
561             }
562
563             if (cphsStruct.Voice2 == 1)
564             {
565                 cphsMw.IsVoice2 = true;
566             }
567
568             else
569             {
570                 cphsMw.IsVoice2 = false;
571             }
572
573             if (cphsStruct.Fax == 1)
574             {
575                 cphsMw.IsFax = true;
576             }
577
578             else
579             {
580                 cphsMw.IsFax = false;
581             }
582
583             if (cphsStruct.Data == 1)
584             {
585                 cphsMw.IsData = true;
586             }
587
588             else
589             {
590                 cphsMw.IsData = false;
591             }
592
593             return cphsMw;
594         }
595
596         internal static SimMessageWaitingResponse ConvertSimMessageWaitingRespStruct(SimMessageWaitingResponseStruct responseStruct)
597         {
598             SimMessageWaitingResponse waitingResp = new SimMessageWaitingResponse();
599             if (responseStruct.IsCphs == 1)
600             {
601                 waitingResp.IsCphsMw = true;
602             }
603
604             else
605             {
606                 waitingResp.IsCphsMw = false;
607             }
608
609             waitingResp.List = ConvertSimMwisListStruct(responseStruct.MwList);
610             waitingResp.CphsMwInfo = ConvertSimCphsMwStruct(responseStruct.CphsMw);
611             return waitingResp;
612         }
613
614         internal static SimMailboxNumber ConvertSimMailboxNumberStruct(SimMailboxNumberStruct mbStruct)
615         {
616             SimMailboxNumber mbNumber = new SimMailboxNumber();
617             if (mbStruct.IsCphs == 1)
618             {
619                 mbNumber.IsCphs = true;
620             }
621
622             else if (mbStruct.IsCphs == 0)
623             {
624                 mbNumber.IsCphs = false;
625             }
626
627             mbNumber.RecIndex = mbStruct.RecIndex;
628             mbNumber.ProfileNumber = mbStruct.ProfileNum;
629             mbNumber.MbType = mbStruct.MbType;
630             mbNumber.AlphaMaxLength = mbStruct.AlphaMaxLen;
631             mbNumber.AlphaId = mbStruct.AlphaId;
632             mbNumber.Ton = mbStruct.Ton;
633             mbNumber.Npi = mbStruct.Npi;
634             mbNumber.Number = mbStruct.Number;
635             mbNumber.CcId = mbStruct.CcId;
636             mbNumber.Ext1Id = mbStruct.Ext1Id;
637             return mbNumber;
638         }
639
640         internal static SimMailboxList ConvertSimMailboxListStruct(SimMailboxListStruct mbListStruct)
641         {
642             SimMailboxList mbList = new SimMailboxList();
643             mbList.MbCount = mbListStruct.Count;
644             List<SimMailboxNumber> mbNumList = new List<SimMailboxNumber>();
645             foreach (SimMailboxNumberStruct mbStruct in mbListStruct.List)
646             {
647                 mbNumList.Add(ConvertSimMailboxNumberStruct(mbStruct));
648             }
649
650             mbList.MbList = mbNumList;
651             return mbList;
652         }
653
654         internal static SimCphsServiceTable ConvertSimCphsServiceTableStruct(SimCphsServiceTableStruct svcStruct)
655         {
656             SimCphsServiceTable svcTable = new SimCphsServiceTable();
657             svcTable.CustomerSvcProfile = svcStruct.CustomerServiceProfile;
658             svcTable.SvcStringTable = svcStruct.ServiceStringTable;
659             svcTable.MbNumbers = svcStruct.MailboxNumbers;
660             svcTable.OperatorNameShort = svcStruct.OperatorNameShortForm;
661             svcTable.InformationNum = svcStruct.InformationNumbers;
662             return svcTable;
663         }
664
665         internal static SimCphsInfo ConvertSimCphsInfoStruct(SimCphsInfoStruct cphsStruct)
666         {
667             SimCphsInfo cphsInfo = new SimCphsInfo();
668             cphsInfo.Phase = cphsStruct.CphsPhase;
669             cphsInfo.CphsSvcTable = ConvertSimCphsServiceTableStruct(cphsStruct.CphsServiceTable);
670             return cphsInfo;
671         }
672
673         internal static SimCst ConvertSimCstStruct(SimCstStrct cstStruct)
674         {
675             SimCst cst = new SimCst();
676             cst.CdmaSvc = cstStruct.CdmaSvcTable;
677             if (cstStruct.CdmaSvcTable == SimCdmaServiceTable.Cdma)
678             {
679                 cst.Cdma = Encoding.ASCII.GetBytes(cstStruct.Cst.CdmaService);
680             }
681
682             else if (cstStruct.CdmaSvcTable == SimCdmaServiceTable.Csim)
683             {
684                 cst.Csim = Encoding.ASCII.GetBytes(cstStruct.Cst.CsimService);
685             }
686
687             return cst;
688         }
689
690         internal static SimServiceTable ConvertSimServiceTableStruct(SimServiceTableStruct svcTableStruct)
691         {
692             SimServiceTable svcTable = new SimServiceTable();
693             svcTable.Type = svcTableStruct.SimType;
694             if (svcTableStruct.SimType == SimCardType.Gsm)
695             {
696                 svcTable.Sst = Encoding.ASCII.GetBytes(svcTableStruct.Table.SimSstService);
697             }
698
699             else if (svcTableStruct.SimType == SimCardType.Usim)
700             {
701                 svcTable.Ust = Encoding.ASCII.GetBytes(svcTableStruct.Table.SimUstService);
702             }
703
704             else if (svcTableStruct.SimType == SimCardType.Ruim)
705             {
706                 svcTable.Cst = ConvertSimCstStruct(svcTableStruct.Table.Cst);
707             }
708
709             return svcTable;
710         }
711
712         internal static SimSubscriberInfo ConvertSimSubscriberInfoStruct(SimSubscriberInfoStruct infoStruct)
713         {
714             SimSubscriberInfo subscriber = new SimSubscriberInfo();
715             subscriber.MsisdnNum = infoStruct.Number;
716             subscriber.MsisdnName = infoStruct.Name;
717             return subscriber;
718         }
719
720         internal static SimMsisdnList ConvertSimMsisdnListStruct(SimMsisdnListStruct msisdnStruct)
721         {
722             SimMsisdnList list = new SimMsisdnList();
723             list.MsisdnCount = msisdnStruct.Count;
724             List<SimSubscriberInfo> subsList = new List<SimSubscriberInfo>();
725             foreach (SimSubscriberInfoStruct subsStruct in msisdnStruct.List)
726             {
727                 subsList.Add(ConvertSimSubscriberInfoStruct(subsStruct));
728             }
729
730             list.SubscriberList = subsList;
731             return list;
732         }
733
734         internal static SimOplmnwact ConvertSimOplmnwactStruct(SimOplmnwactStruct oplmnStruct)
735         {
736             SimOplmnwact oplmn = new SimOplmnwact();
737             oplmn.PlmnString = oplmnStruct.Plmn;
738             if (oplmnStruct.IsUmts == 1)
739             {
740                 oplmn.UmtsFlag = true;
741             }
742
743             else if (oplmnStruct.IsUmts == 0)
744             {
745                 oplmn.UmtsFlag = false;
746             }
747
748             if (oplmnStruct.IsGsm == 1)
749             {
750                 oplmn.GsmFlag = true;
751             }
752
753             else if (oplmnStruct.IsGsm == 0)
754             {
755                 oplmn.GsmFlag = false;
756             }
757
758             return oplmn;
759         }
760
761         internal static SimOplmnwactList ConvertSimOplmnwactListStruct(SimOplmnwactListStruct listStruct)
762         {
763             SimOplmnwactList oplmnList = new SimOplmnwactList();
764             oplmnList.OplmnCount = listStruct.Count;
765             List<SimOplmnwact> wactList = new List<SimOplmnwact>();
766             foreach (SimOplmnwactStruct wactStruct in listStruct.List)
767             {
768                 wactList.Add(ConvertSimOplmnwactStruct(wactStruct));
769             }
770
771             oplmnList.OplmnList = wactList;
772             return oplmnList;
773         }
774
775         internal static SimSpn ConvertSimSpnStruct(SimSpnStruct spnStruct)
776         {
777             SimSpn spn = new SimSpn();
778             spn.Condition = spnStruct.DisplayCondition;
779             spn.SpName = spnStruct.Spn;
780             return spn;
781         }
782
783         internal static SimCphsNetName ConvertSimCphsNetNameStruct(SimCphsNetNameStruct cphsStruct)
784         {
785             SimCphsNetName cphsName = new SimCphsNetName();
786             cphsName.Full = cphsStruct.FullName;
787             cphsName.Short = cphsStruct.ShortName;
788             return cphsName;
789         }
790
791         internal static SimAuthenticationResponse ConvertSimAuthenticationResponseStruct(SimAuthenticationResponseStruct respStruct)
792         {
793             SimAuthenticationResponse response = new SimAuthenticationResponse();
794             response.Type = respStruct.AuthType;
795             response.Result = respStruct.AuthResult;
796             response.RespLength = respStruct.RespLength;
797             response.RespData = respStruct.RespData;
798             response.AuthKeyLen = respStruct.AuthKeyLength;
799             response.Key = respStruct.AuthKey;
800             response.CipherLen = respStruct.CipherLength;
801             response.Cipher = respStruct.CipherData;
802             response.IntegrityLen = respStruct.IntegrityLength;
803             response.Integrity = respStruct.IntegrityData;
804             return response;
805         }
806
807         internal static SimPinResult ConvertSimPinResultStruct(SimPinResultStruct resultStruct)
808         {
809             SimPinResult pinResult = new SimPinResult();
810             pinResult.PinType = resultStruct.Type;
811             pinResult.Retry = resultStruct.RetryCount;
812             return pinResult;
813         }
814
815         internal static SimFacilityResult ConvertSimFacilityResultStruct(SimFacilityResultStruct resultStruct)
816         {
817             SimFacilityResult facilityResult = new SimFacilityResult();
818             facilityResult.LockType = resultStruct.Type;
819             facilityResult.Count = resultStruct.RetryCount;
820             return facilityResult;
821         }
822
823         internal static SimFacilityInfo ConvertSimFacilityInfoStruct(SimFacilityInfoStruct infoStruct)
824         {
825             SimFacilityInfo facilityInfo = new SimFacilityInfo();
826             facilityInfo.LockType = infoStruct.Type;
827             facilityInfo.FacilityStatus = infoStruct.Status;
828             return facilityInfo;
829         }
830
831         internal static SimLockInfo ConvertSimLockInfoStruct(SimLockInfoStruct infoStruct)
832         {
833             SimLockInfo lockInfo = new SimLockInfo();
834             lockInfo.LockType = infoStruct.Type;
835             lockInfo.LockStatus = infoStruct.Status;
836             lockInfo.Count = infoStruct.RetryCount;
837             return lockInfo;
838         }
839
840         internal static SimApduResponse ConvertSimApduResponseStruct(SimApduResponseStruct respStruct)
841         {
842             SimApduResponse response = new SimApduResponse();
843             response.ApduLen = respStruct.RespLen;
844             response.ApduResp = respStruct.ApduResp;
845             return response;
846         }
847
848         internal static SimAtrResponse ConvertSimAtrResponseStruct(SimAtrResponseStruct respStruct)
849         {
850             SimAtrResponse atrResp = new SimAtrResponse();
851             atrResp.AtrRespLen = respStruct.AtrRespLen;
852             atrResp.AtrResp = respStruct.AtrResp;
853             return atrResp;
854         }
855
856         internal static SimImpuList ConvertSimImpuListStruct(SimImpuListStruct listStruct)
857         {
858             SimImpuList impuList = new SimImpuList();
859             impuList.DataCount = listStruct.Count;
860             IntPtr[] ptrList = new IntPtr[listStruct.Count];
861             Marshal.Copy(listStruct.List, ptrList, 0, (int)listStruct.Count);
862             List<string> list = new List<string>();
863             for (int i = 0; i < listStruct.Count; i++)
864             {
865                 list.Add(Marshal.PtrToStringAnsi(ptrList[i]));
866             }
867
868             impuList.ImpuList = list;
869             return impuList;
870         }
871
872         internal static SimPcscf ConvertSimPcscfStruct(SimPcscfStruct pcscfStruct)
873         {
874             SimPcscf pcscf = new SimPcscf();
875             pcscf.PcscfType = pcscfStruct.Type;
876             pcscf.PcscfData = pcscfStruct.Pcscf;
877             return pcscf;
878         }
879
880         internal static SimPcscfList ConvertSimPcscfListStruct(SimPcscfListStruct listStruct)
881         {
882             SimPcscfList pcscfList = new SimPcscfList();
883             pcscfList.DataCount = listStruct.Count;
884             IntPtr[] ptrList = new IntPtr[listStruct.Count];
885             Marshal.Copy(listStruct.List, ptrList, 0, (int)listStruct.Count);
886             List<SimPcscf> list = new List<SimPcscf>();
887             for (int i = 0; i < listStruct.Count; i++)
888             {
889                 list.Add(ConvertSimPcscfStruct(Marshal.PtrToStructure<SimPcscfStruct>(ptrList[i])));
890             }
891
892             pcscfList.PcscfList = list;
893             return pcscfList;
894         }
895     }
896
897     internal static class SimClassConversions
898     {
899         internal static SimCallForwardRequestStruct ConvertSimCallForwardRequest(SimCallForwardRequest request)
900         {
901             SimCallForwardRequestStruct cfStruct = new SimCallForwardRequestStruct();
902             if (request.IsCphs == true)
903             {
904                 cfStruct.IsCphs = 1;
905             }
906
907             else if (request.IsCphs == false)
908             {
909                 cfStruct.IsCphs = 0;
910             }
911
912             if (request.IsCphs == true)
913             {
914                 cfStruct.CfData.CphsCf.Line1 = request.CphsCf.Line1;
915                 cfStruct.CfData.CphsCf.Line2 = request.CphsCf.Line2;
916                 cfStruct.CfData.CphsCf.Fax = request.CphsCf.Fax;
917                 cfStruct.CfData.CphsCf.Data = request.CphsCf.Data;
918             }
919
920             else
921             {
922                 cfStruct.CfData.Cfis.RecIndex = request.Cfis.RecIndex;
923                 cfStruct.CfData.Cfis.MspNum = request.Cfis.MspNum;
924                 cfStruct.CfData.Cfis.CfuStatus = request.Cfis.CfuStatus;
925                 cfStruct.CfData.Cfis.Ton = request.Cfis.Ton;
926                 cfStruct.CfData.Cfis.Npi = request.Cfis.Npi;
927                 cfStruct.CfData.Cfis.CfuNum = request.Cfis.CfuNum;
928                 cfStruct.CfData.Cfis.Cc2Id = request.Cfis.Cc2Id;
929                 cfStruct.CfData.Cfis.Ext7Id = request.Cfis.Ext7Id;
930             }
931
932             return cfStruct;
933         }
934
935         internal static SimMwisStruct ConvertSimMwis(SimMwis mwis)
936         {
937             SimMwisStruct mwisStruct = new SimMwisStruct();
938             mwisStruct.RecIndex = mwis.RecIndex;
939             mwisStruct.IndicatorStatus = mwis.IndicatorStatus;
940             mwisStruct.VoiceCount = mwis.VoiceCount;
941             mwisStruct.FaxCount = mwis.FaxCount;
942             mwisStruct.EmailCount = mwis.EmailCount;
943             mwisStruct.OtherCount = mwis.OtherCount;
944             mwisStruct.VideoCount = mwis.VideoCount;
945             return mwisStruct;
946         }
947
948         internal static SimCphsMwStruct ConvertSimCphsMw(SimCphsMw cphsMw)
949         {
950             SimCphsMwStruct cphsStruct = new SimCphsMwStruct();
951             if (cphsMw.IsVoice1 == true)
952             {
953                 cphsStruct.Voice1 = 1;
954             }
955
956             else
957             {
958                 cphsStruct.Voice1 = 0;
959             }
960
961             if (cphsMw.IsVoice2 == true)
962             {
963                 cphsStruct.Voice2 = 1;
964             }
965
966             else
967             {
968                 cphsStruct.Voice2 = 0;
969             }
970
971             if (cphsMw.IsFax == true)
972             {
973                 cphsStruct.Fax = 1;
974             }
975
976             else
977             {
978                 cphsStruct.Fax = 0;
979             }
980
981             if (cphsMw.IsData == true)
982             {
983                 cphsStruct.Data = 1;
984             }
985
986             else
987             {
988                 cphsStruct.Data = 0;
989             }
990
991             return cphsStruct;
992         }
993
994         internal static SimMessageWaitingRequestStruct ConvertSimMessageWaitingRequest(SimMessageWaitingRequest request)
995         {
996             SimMessageWaitingRequestStruct requestStruct = new SimMessageWaitingRequestStruct();
997             if (request.IsCphs == true)
998             {
999                 requestStruct.IsCphs = 1;
1000             }
1001
1002             else
1003             {
1004                 requestStruct.IsCphs = 0;
1005             }
1006
1007             if (request.IsCphs == true)
1008             {
1009                 requestStruct.Mw.CphsMw = ConvertSimCphsMw(request.CphsMw);
1010             }
1011
1012             else
1013             {
1014                 requestStruct.Mw.Mwis = ConvertSimMwis(request.Mwis);
1015             }
1016
1017             return requestStruct;
1018         }
1019
1020         internal static SimMailboxNumberStruct ConvertSimMailboxNumber(SimMailboxNumber mbNumber)
1021         {
1022             SimMailboxNumberStruct mbStruct = new SimMailboxNumberStruct();
1023             if (mbNumber.IsCphs)
1024             {
1025                 mbStruct.IsCphs = 1;
1026             }
1027
1028             else
1029             {
1030                 mbStruct.IsCphs = 0;
1031             }
1032
1033             mbStruct.RecIndex = mbNumber.RecIndex;
1034             mbStruct.ProfileNum = mbNumber.ProfileNumber;
1035             mbStruct.MbType = mbNumber.MbType;
1036             mbStruct.AlphaMaxLen = mbNumber.AlphaMaxLength;
1037             mbStruct.AlphaId = mbNumber.AlphaId;
1038             mbStruct.Ton = mbNumber.Ton;
1039             mbStruct.Npi = mbNumber.Npi;
1040             mbStruct.Number = mbNumber.Number;
1041             mbStruct.CcId = mbNumber.CcId;
1042             mbStruct.Ext1Id = mbNumber.Ext1Id;
1043             return mbStruct;
1044         }
1045
1046         internal static SimPinDataStruct ConvertSimPinData(SimPinData data)
1047         {
1048             SimPinDataStruct pinStruct = new SimPinDataStruct();
1049             pinStruct.Type = data.Type;
1050             pinStruct.Pin = data.Pin;
1051             pinStruct.PinLength = data.PinLength;
1052             return pinStruct;
1053         }
1054
1055         internal static SimFacilityStruct ConvertSimFacility(SimFacility facility)
1056         {
1057             SimFacilityStruct facilityStruct = new SimFacilityStruct();
1058             facilityStruct.LockType = facility.LockType;
1059             facilityStruct.Password = facility.Password;
1060             facilityStruct.PasswordLength = facility.PasswordLength;
1061             return facilityStruct;
1062         }
1063
1064         internal static SimApduStruct ConvertSimApdu(SimApdu apdu)
1065         {
1066             SimApduStruct apduStruct = new SimApduStruct();
1067             apduStruct.ApduLen = (ushort)apdu.Apdu.Length;
1068             apduStruct.Apdu = Encoding.UTF8.GetString(apdu.Apdu);
1069             return apduStruct;
1070         }
1071
1072         internal static SimAuthenticationDataStruct ConvertSimAuthenticationDataStruct(SimAuthenticationData authData)
1073         {
1074             SimAuthenticationDataStruct authStruct = new SimAuthenticationDataStruct();
1075             authStruct.AuthType = authData.AuthType;
1076             authStruct.RandLength = authData.RandLength;
1077             authStruct.AutnLength = authData.AutnLength;
1078             authStruct.RandData = Encoding.UTF8.GetString(authData.RandData);
1079             authStruct.AutnData = Encoding.UTF8.GetString(authData.AutnData);
1080             return authStruct;
1081         }
1082     }
1083 }