[Tapi] Implementation of Sim class.
[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     [StructLayout(LayoutKind.Sequential)]
258     internal struct SimApduResponseStruct
259     {
260         internal ushort RespLen;
261         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 5120)]
262         internal string ApduResp;
263     }
264
265     [StructLayout(LayoutKind.Sequential)]
266     internal struct SimIccIdInfoStruct
267     {
268         internal int IccLength;
269         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
270         internal string IccNumber;
271     }
272
273     [StructLayout(LayoutKind.Sequential)]
274     internal struct SimCphsServiceTableStruct
275     {
276         internal int CustomerServiceProfile;
277         internal int ServiceStringTable;
278         internal int MailboxNumbers;
279         internal int OperatorNameShortForm;
280         internal int InformationNumbers;
281     }
282
283     [StructLayout(LayoutKind.Sequential)]
284     internal struct SimCphsInfoStruct
285     {
286         internal SimCphsPhaseType CphsPhase;
287         internal SimCphsServiceTableStruct CphsServiceTable;
288     }
289
290     [StructLayout(LayoutKind.Explicit)]
291     internal struct CstServiceStrct
292     {
293         [FieldOffset(0)]
294         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 47)]
295         internal string CdmaService;
296         [FieldOffset(0)]
297         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 41)]
298         internal string CsimService;
299     }
300
301     [StructLayout(LayoutKind.Sequential)]
302     internal struct SimCstStrct
303     {
304         internal SimCdmaServiceTable CdmaSvcTable;
305         internal CstServiceStrct Cst;
306     }
307
308     [StructLayout(LayoutKind.Explicit)]
309     internal struct ServiceTable
310     {
311         [FieldOffset(0)]
312         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 56)]
313         internal string SimSstService;
314         [FieldOffset(0)]
315         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
316         internal string SimUstService;
317         [FieldOffset(0)]
318         internal SimCstStrct Cst;
319     }
320
321     [StructLayout(LayoutKind.Sequential)]
322     internal struct SimServiceTableStruct
323     {
324         internal SimCardType SimType;
325         internal ServiceTable Table;
326     }
327
328     [StructLayout(LayoutKind.Sequential)]
329     internal struct SimSubscriberInfoStruct
330     {
331         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 27)]
332         internal string Number;
333         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 31)]
334         internal string Name;
335     }
336
337     [StructLayout(LayoutKind.Sequential)]
338     internal struct SimMsisdnListStruct
339     {
340         internal int Count;
341         [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3, ArraySubType = UnmanagedType.LPStruct)]
342         internal SimSubscriberInfoStruct[] List;
343     }
344
345     [StructLayout(LayoutKind.Sequential)]
346     internal struct SimOplmnwactStruct
347     {
348         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 7)]
349         internal string Plmn;
350         internal int IsUmts;
351         internal int IsGsm;
352     }
353
354     [StructLayout(LayoutKind.Sequential)]
355     internal struct SimOplmnwactListStruct
356     {
357         internal int Count;
358         [MarshalAs(UnmanagedType.ByValArray, SizeConst = 100, ArraySubType = UnmanagedType.LPStruct)]
359         internal SimOplmnwactStruct[] List;
360     }
361
362     [StructLayout(LayoutKind.Sequential)]
363     internal struct SimSpnStruct
364     {
365         internal byte DisplayCondition;
366         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 41)]
367         internal string Spn;
368     }
369
370     [StructLayout(LayoutKind.Sequential)]
371     internal struct SimCphsNetNameStruct
372     {
373         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 41)]
374         internal string FullName;
375         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 11)]
376         internal string ShortName;
377     }
378
379     [StructLayout(LayoutKind.Sequential)]
380     internal struct SimPinResultStruct
381     {
382         internal SimPinType Type;
383         internal int RetryCount;
384     }
385
386     [StructLayout(LayoutKind.Sequential)]
387     internal struct SimLockInfoStruct
388     {
389         internal SimLockType Type;
390         internal SimLockStatus Status;
391         internal int RetryCount;
392     }
393
394     [StructLayout(LayoutKind.Sequential)]
395     internal struct SimAtrResponseStruct
396     {
397         internal ushort AtrRespLen;
398         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 5120)]
399         internal string AtrResp;
400     }
401
402     [StructLayout(LayoutKind.Sequential)]
403     internal struct SimImpuListStruct
404     {
405         internal uint Count;
406         internal IntPtr List;
407     }
408
409     [StructLayout(LayoutKind.Sequential)]
410     internal struct SimPcscfStruct
411     {
412         internal SimPcscfType Type;
413         [MarshalAs(UnmanagedType.LPStr)]
414         internal string Pcscf;
415     }
416
417     [StructLayout(LayoutKind.Sequential)]
418     internal struct SimPcscfListStruct
419     {
420         internal uint Count;
421         internal IntPtr List;
422     }
423
424     internal static class SimStructConversions
425     {
426         internal static SimImsiInfo ConvertSimImsiInfoStruct(SimImsiInfoStruct imsiStruct)
427         {
428             SimImsiInfo imsi = new SimImsiInfo();
429             imsi.CountryCode = imsiStruct.Mcc;
430             imsi.NetworkCode = imsiStruct.Mnc;
431             imsi.StationId = imsiStruct.Msin;
432             return imsi;
433         }
434
435         internal static SimEccInfo ConvertSimEccInfoStruct(SimEccInfoStruct eccStruct)
436         {
437             SimEccInfo ecc = new SimEccInfo();
438             ecc.NameInfo = eccStruct.Name;
439             ecc.NumberInfo = eccStruct.Number;
440             ecc.TypeInfo = eccStruct.Type;
441             return ecc;
442         }
443
444         internal static SimEccInfoList ConvertSimEccInfoListStruct(SimEccInfoListStruct listStruct)
445         {
446             SimEccInfoList eccList = new SimEccInfoList();
447             eccList.EccCount = listStruct.Count;
448             List<SimEccInfo> eccInfoList = new List<SimEccInfo>();
449             foreach (SimEccInfoStruct info in listStruct.ListInfo)
450             {
451                 eccInfoList.Add(ConvertSimEccInfoStruct(info));
452             }
453
454             eccList.List = eccInfoList;
455             return eccList;
456         }
457
458         internal static SimIccIdInfo ConvertSimIccIdInfoStruct(SimIccIdInfoStruct iccStruct)
459         {
460             SimIccIdInfo iccId = new SimIccIdInfo();
461             iccId.Length = iccStruct.IccLength;
462             iccId.Number = iccStruct.IccNumber;
463             return iccId;
464         }
465
466         internal static SimCfis ConvertSimCfisStruct(SimCfisStruct cfisStruct)
467         {
468             SimCfis cfis = new SimCfis();
469             cfis.RecIndex = cfisStruct.RecIndex;
470             cfis.MspNum = cfisStruct.MspNum;
471             cfis.CfuStatus = cfisStruct.CfuStatus;
472             cfis.Ton = cfisStruct.Ton;
473             cfis.Npi = cfisStruct.Npi;
474             cfis.CfuNum = cfisStruct.CfuNum;
475             cfis.Cc2Id = cfisStruct.Cc2Id;
476             cfis.Ext7Id = cfisStruct.Ext7Id;
477             return cfis;
478         }
479
480         internal static SimCfisList ConvertSimCfisListStruct(SimCfisListStruct listStruct)
481         {
482             SimCfisList cfisList = new SimCfisList();
483             cfisList.Count = listStruct.ProfileCount;
484             List<SimCfis> cfis = new List<SimCfis>();
485             foreach (SimCfisStruct cfStruct in listStruct.CfisList)
486             {
487                 cfis.Add(ConvertSimCfisStruct(cfStruct));
488             }
489
490             cfisList.List = cfis;
491             return cfisList;
492         }
493
494         internal static SimCphsCf ConvertSimCphsCfStruct(SimCphsCfStruct cphsCfStruct)
495         {
496             SimCphsCf cphs = new SimCphsCf();
497             cphs.Line1 = cphsCfStruct.Line1;
498             cphs.Line2 = cphsCfStruct.Line2;
499             cphs.Fax = cphsCfStruct.Fax;
500             cphs.Data = cphsCfStruct.Data;
501             return cphs;
502         }
503
504         internal static SimCallForwardResponse ConvertSimCallForwardResponseStruct(SimCallForwardResponseStruct respStruct)
505         {
506             SimCallForwardResponse resp = new SimCallForwardResponse();
507             if (respStruct.IsCphs == 1)
508             {
509                 resp.IsCphsCf = true;
510             }
511
512             else if (respStruct.IsCphs == 0)
513             {
514                 resp.IsCphsCf = false;
515             }
516
517             resp.List = ConvertSimCfisListStruct(respStruct.CfList);
518             resp.CphsCfInfo = ConvertSimCphsCfStruct(respStruct.CphsCf);
519             return resp;
520         }
521
522         internal static SimMwis ConvertSimMwisStruct(SimMwisStruct mwisStruct)
523         {
524             SimMwis mwis = new SimMwis();
525             mwis.RecIndex = mwisStruct.RecIndex;
526             mwis.IndicatorStatus = mwisStruct.IndicatorStatus;
527             mwis.VoiceCount = mwisStruct.VoiceCount;
528             mwis.FaxCount = mwisStruct.FaxCount;
529             mwis.EmailCount = mwisStruct.EmailCount;
530             mwis.OtherCount = mwisStruct.OtherCount;
531             mwis.VideoCount = mwisStruct.VideoCount;
532             return mwis;
533         }
534
535         internal static SimMwisList ConvertSimMwisListStruct(SimMwisListStruct mwStruct)
536         {
537             SimMwisList mwList = new SimMwisList();
538             mwList.Count = mwStruct.ProfileCount;
539             List<SimMwis> mwisList = new List<SimMwis>();
540             foreach (SimMwisStruct mwisStruct in mwStruct.MwList)
541             {
542                 mwisList.Add(ConvertSimMwisStruct(mwisStruct));
543             }
544
545             mwList.List = mwisList;
546             return mwList;
547         }
548
549         internal static SimCphsMw ConvertSimCphsMwStruct(SimCphsMwStruct cphsStruct)
550         {
551             SimCphsMw cphsMw = new SimCphsMw();
552             if (cphsStruct.Voice1 == 1)
553             {
554                 cphsMw.IsVoice1 = true;
555             }
556
557             else
558             {
559                 cphsMw.IsVoice1 = false;
560             }
561
562             if (cphsStruct.Voice2 == 1)
563             {
564                 cphsMw.IsVoice2 = true;
565             }
566
567             else
568             {
569                 cphsMw.IsVoice2 = false;
570             }
571
572             if (cphsStruct.Fax == 1)
573             {
574                 cphsMw.IsFax = true;
575             }
576
577             else
578             {
579                 cphsMw.IsFax = false;
580             }
581
582             if (cphsStruct.Data == 1)
583             {
584                 cphsMw.IsData = true;
585             }
586
587             else
588             {
589                 cphsMw.IsData = false;
590             }
591
592             return cphsMw;
593         }
594
595         internal static SimMessageWaitingResponse ConvertSimMessageWaitingRespStruct(SimMessageWaitingResponseStruct responseStruct)
596         {
597             SimMessageWaitingResponse waitingResp = new SimMessageWaitingResponse();
598             if (responseStruct.IsCphs == 1)
599             {
600                 waitingResp.IsCphsMw = true;
601             }
602
603             else
604             {
605                 waitingResp.IsCphsMw = false;
606             }
607
608             waitingResp.List = ConvertSimMwisListStruct(responseStruct.MwList);
609             waitingResp.CphsMwInfo = ConvertSimCphsMwStruct(responseStruct.CphsMw);
610             return waitingResp;
611         }
612
613         internal static SimMailboxNumber ConvertSimMailboxNumberStruct(SimMailboxNumberStruct mbStruct)
614         {
615             SimMailboxNumber mbNumber = new SimMailboxNumber();
616             if (mbStruct.IsCphs == 1)
617             {
618                 mbNumber.IsCphs = true;
619             }
620
621             else if (mbStruct.IsCphs == 0)
622             {
623                 mbNumber.IsCphs = false;
624             }
625
626             mbNumber.RecIndex = mbStruct.RecIndex;
627             mbNumber.ProfileNumber = mbStruct.ProfileNum;
628             mbNumber.MbType = mbStruct.MbType;
629             mbNumber.AlphaMaxLength = mbStruct.AlphaMaxLen;
630             mbNumber.AlphaId = mbStruct.AlphaId;
631             mbNumber.Ton = mbStruct.Ton;
632             mbNumber.Npi = mbStruct.Npi;
633             mbNumber.Number = mbStruct.Number;
634             mbNumber.CcId = mbStruct.CcId;
635             mbNumber.Ext1Id = mbStruct.Ext1Id;
636             return mbNumber;
637         }
638
639         internal static SimMailboxList ConvertSimMailboxListStruct(SimMailboxListStruct mbListStruct)
640         {
641             SimMailboxList mbList = new SimMailboxList();
642             mbList.MbCount = mbListStruct.Count;
643             List<SimMailboxNumber> mbNumList = new List<SimMailboxNumber>();
644             foreach (SimMailboxNumberStruct mbStruct in mbListStruct.List)
645             {
646                 mbNumList.Add(ConvertSimMailboxNumberStruct(mbStruct));
647             }
648
649             mbList.MbList = mbNumList;
650             return mbList;
651         }
652
653         internal static SimCphsServiceTable ConvertSimCphsServiceTableStruct(SimCphsServiceTableStruct svcStruct)
654         {
655             SimCphsServiceTable svcTable = new SimCphsServiceTable();
656             svcTable.CustomerSvcProfile = svcStruct.CustomerServiceProfile;
657             svcTable.SvcStringTable = svcStruct.ServiceStringTable;
658             svcTable.MbNumbers = svcStruct.MailboxNumbers;
659             svcTable.OperatorNameShort = svcStruct.OperatorNameShortForm;
660             svcTable.InformationNum = svcStruct.InformationNumbers;
661             return svcTable;
662         }
663
664         internal static SimCphsInfo ConvertSimCphsInfoStruct(SimCphsInfoStruct cphsStruct)
665         {
666             SimCphsInfo cphsInfo = new SimCphsInfo();
667             cphsInfo.Phase = cphsStruct.CphsPhase;
668             cphsInfo.CphsSvcTable = ConvertSimCphsServiceTableStruct(cphsStruct.CphsServiceTable);
669             return cphsInfo;
670         }
671
672         internal static SimCst ConvertSimCstStruct(SimCstStrct cstStruct)
673         {
674             SimCst cst = new SimCst();
675             cst.CdmaSvc = cstStruct.CdmaSvcTable;
676             if (cstStruct.CdmaSvcTable == SimCdmaServiceTable.Cdma)
677             {
678                 cst.Cdma = Encoding.ASCII.GetBytes(cstStruct.Cst.CdmaService);
679             }
680
681             else if (cstStruct.CdmaSvcTable == SimCdmaServiceTable.Csim)
682             {
683                 cst.Csim = Encoding.ASCII.GetBytes(cstStruct.Cst.CsimService);
684             }
685
686             return cst;
687         }
688
689         internal static SimServiceTable ConvertSimServiceTableStruct(SimServiceTableStruct svcTableStruct)
690         {
691             SimServiceTable svcTable = new SimServiceTable();
692             svcTable.Type = svcTableStruct.SimType;
693             if (svcTableStruct.SimType == SimCardType.Gsm)
694             {
695                 svcTable.Sst = Encoding.ASCII.GetBytes(svcTableStruct.Table.SimSstService);
696             }
697
698             else if (svcTableStruct.SimType == SimCardType.Usim)
699             {
700                 svcTable.Ust = Encoding.ASCII.GetBytes(svcTableStruct.Table.SimUstService);
701             }
702
703             else if (svcTableStruct.SimType == SimCardType.Ruim)
704             {
705                 svcTable.Cst = ConvertSimCstStruct(svcTableStruct.Table.Cst);
706             }
707
708             return svcTable;
709         }
710
711         internal static SimSubscriberInfo ConvertSimSubscriberInfoStruct(SimSubscriberInfoStruct infoStruct)
712         {
713             SimSubscriberInfo subscriber = new SimSubscriberInfo();
714             subscriber.MsisdnNum = infoStruct.Number;
715             subscriber.MsisdnName = infoStruct.Name;
716             return subscriber;
717         }
718
719         internal static SimMsisdnList ConvertSimMsisdnListStruct(SimMsisdnListStruct msisdnStruct)
720         {
721             SimMsisdnList list = new SimMsisdnList();
722             list.MsisdnCount = msisdnStruct.Count;
723             List<SimSubscriberInfo> subsList = new List<SimSubscriberInfo>();
724             foreach (SimSubscriberInfoStruct subsStruct in msisdnStruct.List)
725             {
726                 subsList.Add(ConvertSimSubscriberInfoStruct(subsStruct));
727             }
728
729             list.SubscriberList = subsList;
730             return list;
731         }
732
733         internal static SimOplmnwact ConvertSimOplmnwactStruct(SimOplmnwactStruct oplmnStruct)
734         {
735             SimOplmnwact oplmn = new SimOplmnwact();
736             oplmn.PlmnString = oplmnStruct.Plmn;
737             if (oplmnStruct.IsUmts == 1)
738             {
739                 oplmn.UmtsFlag = true;
740             }
741
742             else if (oplmnStruct.IsUmts == 0)
743             {
744                 oplmn.UmtsFlag = false;
745             }
746
747             if (oplmnStruct.IsGsm == 1)
748             {
749                 oplmn.GsmFlag = true;
750             }
751
752             else if (oplmnStruct.IsGsm == 0)
753             {
754                 oplmn.GsmFlag = false;
755             }
756
757             return oplmn;
758         }
759
760         internal static SimOplmnwactList ConvertSimOplmnwactListStruct(SimOplmnwactListStruct listStruct)
761         {
762             SimOplmnwactList oplmnList = new SimOplmnwactList();
763             oplmnList.OplmnCount = listStruct.Count;
764             List<SimOplmnwact> wactList = new List<SimOplmnwact>();
765             foreach (SimOplmnwactStruct wactStruct in listStruct.List)
766             {
767                 wactList.Add(ConvertSimOplmnwactStruct(wactStruct));
768             }
769
770             oplmnList.OplmnList = wactList;
771             return oplmnList;
772         }
773
774         internal static SimSpn ConvertSimSpnStruct(SimSpnStruct spnStruct)
775         {
776             SimSpn spn = new SimSpn();
777             spn.Condition = spnStruct.DisplayCondition;
778             spn.SpName = spnStruct.Spn;
779             return spn;
780         }
781
782         internal static SimCphsNetName ConvertSimCphsNetNameStruct(SimCphsNetNameStruct cphsStruct)
783         {
784             SimCphsNetName cphsName = new SimCphsNetName();
785             cphsName.Full = cphsStruct.FullName;
786             cphsName.Short = cphsStruct.ShortName;
787             return cphsName;
788         }
789
790         internal static SimAuthenticationResponse ConvertSimAuthenticationResponseStruct(SimAuthenticationResponseStruct respStruct)
791         {
792             SimAuthenticationResponse response = new SimAuthenticationResponse();
793             response.Type = respStruct.AuthType;
794             response.Result = respStruct.AuthResult;
795             response.RespLength = respStruct.RespLength;
796             response.RespData = respStruct.RespData;
797             response.AuthKeyLen = respStruct.AuthKeyLength;
798             response.Key = respStruct.AuthKey;
799             response.CipherLen = respStruct.CipherLength;
800             response.Cipher = respStruct.CipherData;
801             response.IntegrityLen = respStruct.IntegrityLength;
802             response.Integrity = respStruct.IntegrityData;
803             return response;
804         }
805
806         internal static SimPinResult ConvertSimPinResultStruct(SimPinResultStruct resultStruct)
807         {
808             SimPinResult pinResult = new SimPinResult();
809             pinResult.PinType = resultStruct.Type;
810             pinResult.Retry = resultStruct.RetryCount;
811             return pinResult;
812         }
813
814         internal static SimFacilityResult ConvertSimFacilityResultStruct(SimFacilityResultStruct resultStruct)
815         {
816             SimFacilityResult facilityResult = new SimFacilityResult();
817             facilityResult.LockType = resultStruct.Type;
818             facilityResult.Count = resultStruct.RetryCount;
819             return facilityResult;
820         }
821
822         internal static SimFacilityInfo ConvertSimFacilityInfoStruct(SimFacilityInfoStruct infoStruct)
823         {
824             SimFacilityInfo facilityInfo = new SimFacilityInfo();
825             facilityInfo.LockType = infoStruct.Type;
826             facilityInfo.FacilityStatus = infoStruct.Status;
827             return facilityInfo;
828         }
829
830         internal static SimLockInfo ConvertSimLockInfoStruct(SimLockInfoStruct infoStruct)
831         {
832             SimLockInfo lockInfo = new SimLockInfo();
833             lockInfo.LockType = infoStruct.Type;
834             lockInfo.LockStatus = infoStruct.Status;
835             lockInfo.Count = infoStruct.RetryCount;
836             return lockInfo;
837         }
838
839         internal static SimApduResponse ConvertSimApduResponseStruct(SimApduResponseStruct respStruct)
840         {
841             SimApduResponse response = new SimApduResponse();
842             response.ApduLen = respStruct.RespLen;
843             response.ApduResp = Encoding.ASCII.GetBytes(respStruct.ApduResp);
844             return response;
845         }
846
847         internal static SimAtrResponse ConvertSimAtrResponseStruct(SimAtrResponseStruct respStruct)
848         {
849             SimAtrResponse atrResp = new SimAtrResponse();
850             atrResp.AtrRespLen = respStruct.AtrRespLen;
851             atrResp.AtrResp = Encoding.ASCII.GetBytes(respStruct.AtrResp);
852             return atrResp;
853         }
854
855         internal static SimImpuList ConvertSimImpuListStruct(SimImpuListStruct listStruct)
856         {
857             SimImpuList impuList = new SimImpuList();
858             impuList.DataCount = listStruct.Count;
859             IntPtr[] ptrList = new IntPtr[listStruct.Count];
860             Marshal.Copy(listStruct.List, ptrList, 0, (int)listStruct.Count);
861             List<string> list = new List<string>();
862             for (int i = 0; i < listStruct.Count; i++)
863             {
864                 list.Add(Marshal.PtrToStringAnsi(ptrList[i]));
865             }
866
867             impuList.ImpuList = list;
868             return impuList;
869         }
870
871         internal static SimPcscf ConvertSimPcscfStruct(SimPcscfStruct pcscfStruct)
872         {
873             SimPcscf pcscf = new SimPcscf();
874             pcscf.PcscfType = pcscfStruct.Type;
875             pcscf.PcscfData = pcscfStruct.Pcscf;
876             return pcscf;
877         }
878
879         internal static SimPcscfList ConvertSimPcscfListStruct(SimPcscfListStruct listStruct)
880         {
881             SimPcscfList pcscfList = new SimPcscfList();
882             pcscfList.DataCount = listStruct.Count;
883             IntPtr[] ptrList = new IntPtr[listStruct.Count];
884             Marshal.Copy(listStruct.List, ptrList, 0, (int)listStruct.Count);
885             List<SimPcscf> list = new List<SimPcscf>();
886             for (int i = 0; i < listStruct.Count; i++)
887             {
888                 list.Add(ConvertSimPcscfStruct(Marshal.PtrToStructure<SimPcscfStruct>(ptrList[i])));
889             }
890
891             pcscfList.PcscfList = list;
892             return pcscfList;
893         }
894     }
895
896     internal static class SimClassConversions
897     {
898         internal static SimCallForwardRequestStruct ConvertSimCallForwardRequest(SimCallForwardRequest request)
899         {
900             SimCallForwardRequestStruct cfStruct = new SimCallForwardRequestStruct();
901             if (request.IsCphs == true)
902             {
903                 cfStruct.IsCphs = 1;
904             }
905
906             else if (request.IsCphs == false)
907             {
908                 cfStruct.IsCphs = 0;
909             }
910
911             if (request.IsCphs == true)
912             {
913                 cfStruct.CfData.CphsCf.Line1 = request.CphsCf.Line1;
914                 cfStruct.CfData.CphsCf.Line2 = request.CphsCf.Line2;
915                 cfStruct.CfData.CphsCf.Fax = request.CphsCf.Fax;
916                 cfStruct.CfData.CphsCf.Data = request.CphsCf.Data;
917             }
918
919             else
920             {
921                 cfStruct.CfData.Cfis.RecIndex = request.Cfis.RecIndex;
922                 cfStruct.CfData.Cfis.MspNum = request.Cfis.MspNum;
923                 cfStruct.CfData.Cfis.CfuStatus = request.Cfis.CfuStatus;
924                 cfStruct.CfData.Cfis.Ton = request.Cfis.Ton;
925                 cfStruct.CfData.Cfis.Npi = request.Cfis.Npi;
926                 cfStruct.CfData.Cfis.CfuNum = request.Cfis.CfuNum;
927                 cfStruct.CfData.Cfis.Cc2Id = request.Cfis.Cc2Id;
928                 cfStruct.CfData.Cfis.Ext7Id = request.Cfis.Ext7Id;
929             }
930
931             return cfStruct;
932         }
933
934         internal static SimMwisStruct ConvertSimMwis(SimMwis mwis)
935         {
936             SimMwisStruct mwisStruct = new SimMwisStruct();
937             mwisStruct.RecIndex = mwis.RecIndex;
938             mwisStruct.IndicatorStatus = mwis.IndicatorStatus;
939             mwisStruct.VoiceCount = mwis.VoiceCount;
940             mwisStruct.FaxCount = mwis.FaxCount;
941             mwisStruct.EmailCount = mwis.EmailCount;
942             mwisStruct.OtherCount = mwis.OtherCount;
943             mwisStruct.VideoCount = mwis.VideoCount;
944             return mwisStruct;
945         }
946
947         internal static SimCphsMwStruct ConvertSimCphsMw(SimCphsMw cphsMw)
948         {
949             SimCphsMwStruct cphsStruct = new SimCphsMwStruct();
950             if (cphsMw.IsVoice1 == true)
951             {
952                 cphsStruct.Voice1 = 1;
953             }
954
955             else
956             {
957                 cphsStruct.Voice1 = 0;
958             }
959
960             if (cphsMw.IsVoice2 == true)
961             {
962                 cphsStruct.Voice2 = 1;
963             }
964
965             else
966             {
967                 cphsStruct.Voice2 = 0;
968             }
969
970             if (cphsMw.IsFax == true)
971             {
972                 cphsStruct.Fax = 1;
973             }
974
975             else
976             {
977                 cphsStruct.Fax = 0;
978             }
979
980             if (cphsMw.IsData == true)
981             {
982                 cphsStruct.Data = 1;
983             }
984
985             else
986             {
987                 cphsStruct.Data = 0;
988             }
989
990             return cphsStruct;
991         }
992
993         internal static SimMessageWaitingRequestStruct ConvertSimMessageWaitingRequest(SimMessageWaitingRequest request)
994         {
995             SimMessageWaitingRequestStruct requestStruct = new SimMessageWaitingRequestStruct();
996             if (request.IsCphs == true)
997             {
998                 requestStruct.IsCphs = 1;
999             }
1000
1001             else
1002             {
1003                 requestStruct.IsCphs = 0;
1004             }
1005
1006             if (request.IsCphs == true)
1007             {
1008                 requestStruct.Mw.CphsMw = ConvertSimCphsMw(request.CphsMw);
1009             }
1010
1011             else
1012             {
1013                 requestStruct.Mw.Mwis = ConvertSimMwis(request.Mwis);
1014             }
1015
1016             return requestStruct;
1017         }
1018
1019         internal static SimMailboxNumberStruct ConvertSimMailboxNumber(SimMailboxNumber mbNumber)
1020         {
1021             SimMailboxNumberStruct mbStruct = new SimMailboxNumberStruct();
1022             if (mbNumber.IsCphs)
1023             {
1024                 mbStruct.IsCphs = 1;
1025             }
1026
1027             else
1028             {
1029                 mbStruct.IsCphs = 0;
1030             }
1031
1032             mbStruct.RecIndex = mbNumber.RecIndex;
1033             mbStruct.ProfileNum = mbNumber.ProfileNumber;
1034             mbStruct.MbType = mbNumber.MbType;
1035             mbStruct.AlphaMaxLen = mbNumber.AlphaMaxLength;
1036             mbStruct.AlphaId = mbNumber.AlphaId;
1037             mbStruct.Ton = mbNumber.Ton;
1038             mbStruct.Npi = mbNumber.Npi;
1039             mbStruct.Number = mbNumber.Number;
1040             mbStruct.CcId = mbNumber.CcId;
1041             mbStruct.Ext1Id = mbNumber.Ext1Id;
1042             return mbStruct;
1043         }
1044
1045         internal static SimPinDataStruct ConvertSimPinData(SimPinData data)
1046         {
1047             SimPinDataStruct pinStruct = new SimPinDataStruct();
1048             pinStruct.Type = data.Type;
1049             pinStruct.Pin = data.Pin;
1050             pinStruct.PinLength = data.PinLength;
1051             return pinStruct;
1052         }
1053
1054         internal static SimFacilityStruct ConvertSimFacility(SimFacility facility)
1055         {
1056             SimFacilityStruct facilityStruct = new SimFacilityStruct();
1057             facilityStruct.LockType = facility.LockType;
1058             facilityStruct.Password = facility.Password;
1059             facilityStruct.PasswordLength = facility.PasswordLength;
1060             return facilityStruct;
1061         }
1062
1063         internal static SimApduStruct ConvertSimApdu(SimApdu apdu)
1064         {
1065             SimApduStruct apduStruct = new SimApduStruct();
1066             apduStruct.ApduLen = apdu.ApduLength;
1067             apduStruct.Apdu = Encoding.UTF8.GetString(apdu.Apdu);
1068             return apduStruct;
1069         }
1070
1071         internal static SimAuthenticationDataStruct ConvertSimAuthenticationDataStruct(SimAuthenticationData authData)
1072         {
1073             SimAuthenticationDataStruct authStruct = new SimAuthenticationDataStruct();
1074             authStruct.AuthType = authData.AuthType;
1075             authStruct.RandLength = authData.RandLength;
1076             authStruct.AutnLength = authData.AutnLength;
1077             authStruct.RandData = Encoding.UTF8.GetString(authData.RandData);
1078             authStruct.AutnData = Encoding.UTF8.GetString(authData.AutnData);
1079             return authStruct;
1080         }
1081     }
1082 }