blob: cae4530f1d42947c99518f17d182f773fe5be8aa [file] [log] [blame]
wangyouqiang3e3bf922024-01-05 15:38:34 +08001#include <stdlib.h>
2#include <stdio.h>
3#include <string.h>
4#include <sys/types.h>
5#include <pthread.h>
6#include <unistd.h>
7#include <dlfcn.h>
8#include <stdint.h>
9
10#include"lynq_qser_sim.h"
11
12
13#define BUF_SIZE 32
14#define BUF_PIN 16
15#define VER_SIZE 128
16
17typedef uint32_t sim_client_handle_type;
18
19sim_client_handle_type ph_sim = 2023;
20sim_client_handle_type h_sim = 2023;
wangyouqiang3e3bf922024-01-05 15:38:34 +080021
wangyouqiang3e3bf922024-01-05 15:38:34 +080022
23int main(int argc, char const *argv[])
24{
b.liu86b7ff22024-04-03 14:25:55 +080025 printf("=========sim main=========\n"
26 "\t0 qser_sim_init\n"
27 "\t1 qser_get_imsi\n"
28 "\t2 qser_get_iccid\n"
29 "\t3 qser_get_phonenumber\n"
30 "\t4 qser_verify_pin\n"
31 "\t5 qser_change_pin\n"
32 "\t6 qser_unlock_pin\n"
33 "\t7 qser_enable_pin\n"
34 "\t8 qser_disable_pin\n"
35 "\t9 qser_get_sim_status\n"
36 "\t10 qser_get_imei\n"
37 "\t11 qser_get_imei_and_sv\n"
38 "\t12 qser_reset_modem\n"
39 "\t13 qser_get_version\n"
40 "\t14 qser_reset_sim\n"
41 "\t15 qser_deinit_sim\n"
42 "\t16 exit\n");
wangyouqiang3e3bf922024-01-05 15:38:34 +080043
wangyouqiang3e3bf922024-01-05 15:38:34 +080044 while(1)
45 {
b.liu86b7ff22024-04-03 14:25:55 +080046 int cmdIdx = -1;
47 int res = -1;
48
49 printf("operator: >> \n");
50
wangyouqiang3e3bf922024-01-05 15:38:34 +080051 scanf("%d", &cmdIdx);
b.liu86b7ff22024-04-03 14:25:55 +080052 fflush(stdin);
wangyouqiang3e3bf922024-01-05 15:38:34 +080053
54 switch(cmdIdx)
55 {
56 //"qser_sim_init"
57 case 0:
58 {
b.liu86b7ff22024-04-03 14:25:55 +080059 //int token;
60 //printf("input token\n");
61 //scanf("%d", &token);
62 res = qser_sim_client_init(&h_sim);
63 if(res == 0)
wangyouqiang3e3bf922024-01-05 15:38:34 +080064 {
b.liu86b7ff22024-04-03 14:25:55 +080065 printf("Run qser_sim_client_init\n");
66 }else{
67 printf("qser_sim_client_init error\n");
wangyouqiang3e3bf922024-01-05 15:38:34 +080068 }
69 }
b.liu86b7ff22024-04-03 14:25:55 +080070 break;
wangyouqiang3e3bf922024-01-05 15:38:34 +080071 //"qser_sim_getimsi"
72 case 1:
73 {
b.liu86b7ff22024-04-03 14:25:55 +080074 char imsi[BUF_SIZE] = {0};
75 QSER_SIM_APP_ID_INFO_T pt_info;
76 res = qser_sim_getimsi(h_sim, &pt_info, imsi, BUF_SIZE);
77 if(res == 0)
78 {
79 printf("imsi is %s!!!\n",imsi);
80 }else{
81 printf("get imsi error, res = %d\n", res);
wangyouqiang3e3bf922024-01-05 15:38:34 +080082 }
wangyouqiang3e3bf922024-01-05 15:38:34 +080083 }
b.liu86b7ff22024-04-03 14:25:55 +080084 break;
wangyouqiang3e3bf922024-01-05 15:38:34 +080085 //"qser_get_iccid"
86 case 2:
87 {
b.liu86b7ff22024-04-03 14:25:55 +080088 char iccid[BUF_SIZE] = {0};
89 res = qser_sim_geticcid(h_sim, QSER_SIM_SLOT_ID_1, iccid, BUF_SIZE);
90 if(res == 0)
91 {
92 printf("get iccid success!!! iccid is %s\n",iccid);
93 }else{
94 printf("get iccid error, res = %d\n", res);
wangyouqiang3e3bf922024-01-05 15:38:34 +080095 }
wangyouqiang3e3bf922024-01-05 15:38:34 +080096 }
b.liu86b7ff22024-04-03 14:25:55 +080097 break;
wangyouqiang3e3bf922024-01-05 15:38:34 +080098 //qser_get_phonenumber
99 case 3:
100 {
b.liu86b7ff22024-04-03 14:25:55 +0800101 char phonenumber[BUF_SIZE] = "";
102 QSER_SIM_APP_ID_INFO_T pt_info;
103 res = qser_sim_getphonenumber(h_sim, &pt_info, phonenumber, BUF_SIZE);
104 if(res == 0)
105 {
106 printf("get phonenumber success!!! phonenumber is %s\n",phonenumber);
107 }else{
108 printf("get phonenumber error, res = %d\n", res);
wangyouqiang3e3bf922024-01-05 15:38:34 +0800109 }
b.liu86b7ff22024-04-03 14:25:55 +0800110 }
111 break;
112 //qser_verify_pin
wangyouqiang3e3bf922024-01-05 15:38:34 +0800113 case 4:
114 {
b.liu86b7ff22024-04-03 14:25:55 +0800115 char pin[BUF_PIN] = {0};
116 QSER_SIM_VERIFY_PIN_INFO_T pt_info;
117 printf("input pin\n");
118 scanf("%s", pin);
119 strncpy(pt_info.pin_value, pin, BUF_PIN);
120 printf("pin_value = %s , pin = %s\n", pt_info.pin_value, pin);
121 pt_info.pin_value_len = strlen(pt_info.pin_value);
b.liu8583dce2024-04-03 13:30:08 +0800122
b.liu86b7ff22024-04-03 14:25:55 +0800123 res = qser_sim_verifypin(h_sim, &pt_info);
124 if(res == 0)
125 {
126 printf("verify pin success!!!\n");
127 }else{
128 printf("verify pin error, res = %d\n", res);
b.liu8583dce2024-04-03 13:30:08 +0800129 }
wangyouqiang3e3bf922024-01-05 15:38:34 +0800130 }
b.liu86b7ff22024-04-03 14:25:55 +0800131 break;
wangyouqiang3e3bf922024-01-05 15:38:34 +0800132 //qser_change_pin
133 case 5:
134 {
b.liu86b7ff22024-04-03 14:25:55 +0800135 char old_pin[BUF_PIN] = {0};
136 QSER_SIM_CHANGE_PIN_INFO_T pt_info;
137 printf("input old pin\n");
138 scanf("%s", old_pin);
139 char new_pin[BUF_PIN] = {0};
140 printf("input new pin\n");
141 scanf("%s", new_pin);
142 strncpy(pt_info.old_pin_value, old_pin, BUF_PIN);
143 strncpy(pt_info.new_pin_value, new_pin, BUF_PIN);
144 printf("pt_info.old_pin_value = %s, old_pin = %s\n", pt_info.old_pin_value, old_pin);
145 printf("pt_info.new_pin_value = %s, new_pin = %s\n", pt_info.new_pin_value, new_pin);
146 pt_info.old_pin_value_len = strlen(pt_info.old_pin_value);
147 pt_info.new_pin_value_len = strlen(pt_info.new_pin_value);
b.liu8583dce2024-04-03 13:30:08 +0800148
b.liu86b7ff22024-04-03 14:25:55 +0800149 res = qser_sim_changepin(h_sim, &pt_info);
150 if(res == 0)
151 {
152 printf("change pin success!!!\n");
153 }else{
154 printf("change pin error, res = %d\n", res);
b.liu8583dce2024-04-03 13:30:08 +0800155 }
wangyouqiang3e3bf922024-01-05 15:38:34 +0800156 }
b.liu86b7ff22024-04-03 14:25:55 +0800157 break;
wangyouqiang3e3bf922024-01-05 15:38:34 +0800158 //qser_unlock_pin
159 case 6:
160 {
b.liu86b7ff22024-04-03 14:25:55 +0800161 char puk[BUF_PIN] = {0};
162 QSER_SIM_UNBLOCK_PIN_INFO_T pt_info;
163 printf("input puk\n");
164 scanf("%s", puk);
165 char new_pin[BUF_PIN] = {0};
166 printf("input new pin\n");
167 scanf("%s", new_pin);
b.liu8583dce2024-04-03 13:30:08 +0800168
b.liu86b7ff22024-04-03 14:25:55 +0800169 strncpy(pt_info.puk_value, puk, BUF_PIN);
170 strncpy(pt_info.new_pin_value, new_pin, BUF_PIN);
171 printf("pt_info.puk_value = %s, puk = %s\n", pt_info.puk_value, puk);
172 printf("pt_info.new_pin_value = %s, new_pin = %s\n", pt_info.new_pin_value, new_pin);
173 pt_info.new_pin_value_len = strlen(pt_info.new_pin_value);
174 pt_info.puk_value_len = strlen(pt_info.puk_value);
175
176 res = qser_sim_unblockpin(h_sim, &pt_info);
177 if(res == 0)
178 {
179 printf("unlock pin success!!!\n");
180 }else{
181 printf("unlock pin error, res = %d\n", res);
b.liu8583dce2024-04-03 13:30:08 +0800182 }
wangyouqiang3e3bf922024-01-05 15:38:34 +0800183 }
b.liu86b7ff22024-04-03 14:25:55 +0800184 break;
wangyouqiang3e3bf922024-01-05 15:38:34 +0800185 //qser_enable_pin
186 case 7:
b.liu86b7ff22024-04-03 14:25:55 +0800187 {
188 char pin[BUF_PIN] = {0};
189 QSER_SIM_ENABLE_PIN_INFO_T pt_info;
190 printf("input pin\n");
191 scanf("%s", pin);
192 strncpy(pt_info.pin_value, pin, BUF_PIN);
193 pt_info.pin_value_len = strlen(pt_info.pin_value);
194
195 res = qser_sim_enablepin(h_sim, &pt_info);
196 if(res == 0)
197 {
198 printf("pin enabled!!!\n");
199 }else{
200 printf("pin enable error, res =%d\n", res);
wangyouqiang3e3bf922024-01-05 15:38:34 +0800201 }
wangyouqiang3e3bf922024-01-05 15:38:34 +0800202 }
b.liu86b7ff22024-04-03 14:25:55 +0800203 break;
wangyouqiang3e3bf922024-01-05 15:38:34 +0800204 //qser_disable_pin
205 case 8:
206 {
b.liu86b7ff22024-04-03 14:25:55 +0800207 char pin[BUF_PIN] = {0};
208 QSER_SIM_ENABLE_PIN_INFO_T pt_info;
209 printf("input pin\n");
210 scanf("%s", pin);
211 strncpy(pt_info.pin_value, pin, BUF_PIN);
212 pt_info.pin_value_len = strlen(pt_info.pin_value);
213
214 res = qser_sim_disablepin(h_sim, &pt_info);
215 if(res == 0)
216 {
217 printf("pin disnabled!!!\n");
218 }else{
219 printf("pin disable error,res = %d\n", res);
wangyouqiang3e3bf922024-01-05 15:38:34 +0800220 }
wangyouqiang3e3bf922024-01-05 15:38:34 +0800221 }
b.liu86b7ff22024-04-03 14:25:55 +0800222 break;
223 //qser_get_sim_status
wangyouqiang3e3bf922024-01-05 15:38:34 +0800224 case 9:
225 {
b.liu86b7ff22024-04-03 14:25:55 +0800226 QSER_SIM_CARD_STATUS_INFO_T pt_info;
b.liu8583dce2024-04-03 13:30:08 +0800227
b.liu86b7ff22024-04-03 14:25:55 +0800228 res = qser_sim_getcardstatus(h_sim, QSER_SIM_SLOT_ID_1, &pt_info);
229 if(res == 0)
230 {
231 printf("state is %d !!!\n",pt_info.e_card_state);
232 }else{
233 printf("get imsi error,res = %d\n", res);
b.liu8583dce2024-04-03 13:30:08 +0800234 }
wangyouqiang3e3bf922024-01-05 15:38:34 +0800235 }
b.liu86b7ff22024-04-03 14:25:55 +0800236 break;
wangyouqiang3e3bf922024-01-05 15:38:34 +0800237 //qser_get_imei
238 case 10:
239 {
b.liu86b7ff22024-04-03 14:25:55 +0800240 char imei[BUF_SIZE]="";
241 res = qser_sim_getimei(h_sim, imei);
242 if(res == 0)
243 {
244 printf("get imei success!!! imei = %s\n", imei);
245 }else{
246 printf("get imei error, res = %d\n", res);
wangyouqiang3e3bf922024-01-05 15:38:34 +0800247 }
wangyouqiang3e3bf922024-01-05 15:38:34 +0800248 }
b.liu86b7ff22024-04-03 14:25:55 +0800249 break;
wangyouqiang3e3bf922024-01-05 15:38:34 +0800250 //qser_get_imei_and_sv
251 case 11:
252 {
253 char imei[BUF_SIZE]="";
254 char sv[BUF_SIZE]="";
255
b.liu86b7ff22024-04-03 14:25:55 +0800256 res = qser_get_imei_and_sv(h_sim, imei, sv);
257 if(res == 0)
258 {
259 printf("get imei and sv success!!!imei = %s sv = %s\n", imei, sv);
260 }else{
261 printf("get imei and sv error, res = %d\n", res);
wangyouqiang3e3bf922024-01-05 15:38:34 +0800262 }
wangyouqiang3e3bf922024-01-05 15:38:34 +0800263 }
b.liu86b7ff22024-04-03 14:25:55 +0800264 break;
wangyouqiang3e3bf922024-01-05 15:38:34 +0800265 //qser_reset_modem
266 case 12:
267 {
b.liu86b7ff22024-04-03 14:25:55 +0800268 res = qser_reset_modem(h_sim);
269 if(res == 0)
270 {
271 printf("reset modem success!!!\n");
272 }else{
273 printf("reset modem error, res = %d\n", res);
wangyouqiang3e3bf922024-01-05 15:38:34 +0800274 }
wangyouqiang3e3bf922024-01-05 15:38:34 +0800275 }
b.liu86b7ff22024-04-03 14:25:55 +0800276 break;
wangyouqiang3e3bf922024-01-05 15:38:34 +0800277 //qser_get_version
278 case 13:
279 {
280 char buf[VER_SIZE]="";
b.liu86b7ff22024-04-03 14:25:55 +0800281
282 res = qser_get_version(h_sim, buf);
283 if(res == 0)
284 {
285 printf("get version success!!! ver = %s\n", buf);
286 }else{
287 printf("get version error, res = %d\n", res);
wangyouqiang3e3bf922024-01-05 15:38:34 +0800288 }
wangyouqiang3e3bf922024-01-05 15:38:34 +0800289 }
b.liu86b7ff22024-04-03 14:25:55 +0800290 break;
wangyouqiang3e3bf922024-01-05 15:38:34 +0800291 //qser_reset_sim
292 case 14:
293 {
b.liu86b7ff22024-04-03 14:25:55 +0800294 res = qser_reset_sim(h_sim);
295 if(res == 0)
296 {
297 printf("reset sim success!!!\n");
298 }else{
299 printf("reset sim error, res = %d\n", res);
wangyouqiang3e3bf922024-01-05 15:38:34 +0800300 }
wangyouqiang3e3bf922024-01-05 15:38:34 +0800301 }
b.liu86b7ff22024-04-03 14:25:55 +0800302 break;
wangyouqiang3e3bf922024-01-05 15:38:34 +0800303 //qser_deinit_sim
304 case 15:
305 {
b.liu86b7ff22024-04-03 14:25:55 +0800306 res = qser_sim_client_deinit(h_sim);
307 if(res == 0)
308 {
309 printf("sim deinit success is!!!\n");
310 }else{
311 printf("sim deint errors, res = %d\n", res);
wangyouqiang3e3bf922024-01-05 15:38:34 +0800312 }
wangyouqiang3e3bf922024-01-05 15:38:34 +0800313 }
b.liu86b7ff22024-04-03 14:25:55 +0800314 break;
315 case 16:
316 printf("main exit\n");
317 return 0;
318 default :
wangyouqiang3e3bf922024-01-05 15:38:34 +0800319 break;
320 }
321
322 }
323
324 return 0;
325}