blob: d6478c4edf1762afd6e020286504446843004c33 [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;
21int flag_init = 0;
22
23typedef struct
24{
25 int cmdIdx;
26 const char *funcName;
27} st_api_test_case;
28
29//for server test
30st_api_test_case at_api_testcases[] =
31{
32 {0, "qser_sim_init"},
33 {1, "qser_get_imsi"},
34 {2, "qser_get_iccid"},
35 {3, "qser_get_phonenumber"},
36 {4, "qser_verify_pin"},
37 {5, "qser_change_pin"},
38 {6, "qser_unlock_pin"},
39 {7, "qser_enable_pin"},
40 {8, "qser_disable_pin"},
41 {9, "qser_get_sim_status"},
42 {10, "qser_get_imei"},
43 {11, "qser_get_imei_and_sv"},
44 {12, "qser_reset_modem"},
45 {13, "qser_get_version"},
46 {14, "qser_reset_sim"},
47 {15, "qser_deinit_sim"},
48 {-1, NULL}
49};
50
51void print_help(void)
52{
53 int i;
54 printf("Supported test cases:\n");
55 for(i = 0; ; i++)
56 {
57 if(at_api_testcases[i].cmdIdx == -1)
58 {
59 break;
60 }
61 printf("%d:\t%s\n", at_api_testcases[i].cmdIdx, at_api_testcases[i].funcName);
62 }
63}
64
65int main(int argc, char const *argv[])
66{
67 int cmdIdx = 0;
68 int res = 0;
69
70 print_help();
71 while(1)
72 {
73 printf("\nplease input cmd index(-1 exit): ");
74 scanf("%d", &cmdIdx);
75 if(cmdIdx == -1)
76 {
77 break;
78 }
79
80 switch(cmdIdx)
81 {
82 //"qser_sim_init"
83 case 0:
84 {
85 if(flag_init == 1)
86 {
87 printf("init is already\n");
88 break;
89 }
90 else{
91 //int token;
92 //printf("input token\n");
93 //scanf("%d", &token);
94 res = qser_sim_client_init(&h_sim);
95 if(res == 0)
96 {
97 printf("Run qser_sim_client_init\n");
98 flag_init = 1;
99 }else{
100 printf("qser_sim_client_init error\n");
101 }
102
103 break;
104 }
105 }
106
107 //"qser_sim_getimsi"
108 case 1:
109 {
110 if(flag_init == 0){
111 printf("must init first\n");
112 }
113 else{
114 char imsi[BUF_SIZE] = {0};
115 QSER_SIM_APP_ID_INFO_T pt_info;
116 res = qser_sim_getimsi(h_sim, &pt_info, imsi, 32);
117 if(res == 0)
118 {
119 printf("imsi is %s!!!\n",imsi);
120 }else{
121 printf("get imsi error, res = %d\n", res);
122 }
123 }
124 break;
125 }
126
127 //"qser_get_iccid"
128 case 2:
129 {
130 if(flag_init == 0){
131 printf("must init first\n");
132 }
133 else{
134 char iccid[BUF_SIZE] = {0};
135 res = qser_sim_geticcid(h_sim, QSER_SIM_SLOT_ID_1, iccid, 32);
136 if(res == 0)
137 {
138 printf("get iccid success!!! iccid is %s\n",iccid);
139 }else{
140 printf("get iccid error, res = %d\n", res);
141 }
142 }
143 break;
144 }
145 //qser_get_phonenumber
146 case 3:
147 {
148 if(flag_init == 0){
149 printf("must init first\n");
150 }
151 else{
152 char phonenumber[BUF_SIZE] = "";
153 QSER_SIM_APP_ID_INFO_T pt_info;
154 res = qser_sim_getphonenumber(h_sim, &pt_info, phonenumber, 32);
155 if(res == 0)
156 {
157 printf("get phonenumber success!!! phonenumber is %s\n",phonenumber);
158 }else{
159 printf("get phonenumber error, res = %d\n", res);
160 }
161 }
162 break;
163 }
164 //qser_verify_pin
165 case 4:
166 {
167 if(flag_init == 0){
168 printf("must init first\n");
169 }
170 else{
171 char pin[BUF_PIN] = {0};
172 QSER_SIM_VERIFY_PIN_INFO_T pt_info;
173 printf("input pin\n");
174 scanf("%s", pin);
175 strncpy(pt_info.pin_value, pin, BUF_PIN);
176 printf("pin_value = %s , pin = %s\n", pt_info.pin_value, pin);
177 pt_info.pin_value_len = strlen(pt_info.pin_value);
178
179 res = qser_sim_verifypin(h_sim, &pt_info);
180 if(res == 0)
181 {
182 printf("verify pin success!!!\n");
183 }else{
184 printf("verify pin error, res = %d\n", res);
185 }
186
187 }
188 break;
189 }
190 //qser_change_pin
191 case 5:
192 {
193 if(flag_init == 0){
194 printf("must init first\n");
195 }
196 else{
197 char old_pin[BUF_PIN] = {0};
198 QSER_SIM_CHANGE_PIN_INFO_T pt_info;
199 printf("input old pin\n");
200 scanf("%s", old_pin);
201 char new_pin[BUF_PIN] = {0};
202 printf("input new pin\n");
203 scanf("%s", new_pin);
204 strncpy(pt_info.old_pin_value, old_pin, BUF_PIN);
205 strncpy(pt_info.new_pin_value, new_pin, BUF_PIN);
206 printf("pt_info.old_pin_value = %s, old_pin = %s\n", pt_info.old_pin_value, old_pin);
207 printf("pt_info.new_pin_value = %s, new_pin = %s\n", pt_info.new_pin_value, new_pin);
208 pt_info.old_pin_value_len = strlen(pt_info.old_pin_value);
209 pt_info.new_pin_value_len = strlen(pt_info.new_pin_value);
210
211 res = qser_sim_changepin(h_sim, &pt_info);
212 if(res == 0)
213 {
214 printf("change pin success!!!\n");
215 }else{
216 printf("change pin error, res = %d\n", res);
217 }
218 }
219 break;
220 }
221 //qser_unlock_pin
222 case 6:
223 {
224 if(flag_init == 0){
225 printf("must init first\n");
226 }
227 else{
228 char puk[BUF_PIN] = {0};
229 QSER_SIM_UNBLOCK_PIN_INFO_T pt_info;
230 printf("input puk\n");
231 scanf("%s", puk);
232 char new_pin[BUF_PIN] = {0};
233 printf("input new pin\n");
234 scanf("%s", new_pin);
235
236 strncpy(pt_info.puk_value, puk, BUF_PIN);
237 strncpy(pt_info.new_pin_value, new_pin, BUF_PIN);
238 printf("pt_info.puk_value = %s, puk = %s\n", pt_info.puk_value, puk);
239 printf("pt_info.new_pin_value = %s, new_pin = %s\n", pt_info.new_pin_value, new_pin);
240 pt_info.new_pin_value_len = strlen(pt_info.new_pin_value);
241 pt_info.puk_value_len = strlen(pt_info.puk_value);
242
243 res = qser_sim_unblockpin(h_sim, &pt_info);
244 if(res == 0)
245 {
246 printf("unlock pin success!!!\n");
247 }else{
248 printf("unlock pin error, res = %d\n", res);
249 }
250 }
251 break;
252 }
253 //qser_enable_pin
254 case 7:
255 {
256 if(flag_init == 0){
257 printf("must init first\n");
258 }
259 else{
260 char pin[BUF_PIN] = {0};
261 QSER_SIM_ENABLE_PIN_INFO_T pt_info;
262 printf("input pin\n");
263 scanf("%s", pin);
264 strncpy(pt_info.pin_value, pin, BUF_PIN);
265 pt_info.pin_value_len = strlen(pt_info.pin_value);
266
267 res = qser_sim_enablepin(h_sim, &pt_info);
268 if(res == 0)
269 {
270 printf("pin enabled!!!\n");
271 }else{
272 printf("pin enable error, res =%d\n", res);
273 }
274 }
275 break;
276 }
277 //qser_disable_pin
278 case 8:
279 {
280 if(flag_init == 0){
281 printf("must init first\n");
282 }
283 else{
284 char pin[BUF_PIN] = {0};
285 QSER_SIM_ENABLE_PIN_INFO_T pt_info;
286 printf("input pin\n");
287 scanf("%s", pin);
288 strncpy(pt_info.pin_value, pin, BUF_PIN);
289 pt_info.pin_value_len = strlen(pt_info.pin_value);
290
291 res = qser_sim_disablepin(h_sim, &pt_info);
292 if(res == 0)
293 {
294 printf("pin disnabled!!!\n");
295 }else{
296 printf("pin disable error,res = %d\n", res);
297 }
298 }
299 break;
300 }
301 //qser_get_sim_status
302 case 9:
303 {
304 if(flag_init == 0){
305 printf("must init first\n");
306 }
307 else{
308 QSER_SIM_CARD_STATUS_INFO_T pt_info;
309
310 res = qser_sim_getcardstatus(h_sim, QSER_SIM_SLOT_ID_1, &pt_info);
311 if(res == 0)
312 {
313 printf("state is %d !!!\n",pt_info.e_card_state);
314 }else{
315 printf("get imsi error,res = %d\n", res);
316 }
317 }
318 break;
319 }
320 //qser_get_imei
321 case 10:
322 {
323 if(flag_init == 0){
324 printf("must init first\n");
325 }
326 else{
327 char imei[BUF_SIZE]="";
328 res = qser_sim_getimei(h_sim, imei);
329 if(res == 0)
330 {
331 printf("get imei success!!! imei = %s\n", imei);
332 }else{
333 printf("get imei error, res = %d\n", res);
334 }
335 }
336 //flag_init = 0;
337 break;
338 }
339 //qser_get_imei_and_sv
340 case 11:
341 {
342 char imei[BUF_SIZE]="";
343 char sv[BUF_SIZE]="";
344
345 if(flag_init == 0){
346 printf("must init first\n");
347 }
348 else{
349 res = qser_get_imei_and_sv(h_sim, imei, sv);
350 if(res == 0)
351 {
352 printf("get imei and sv success!!!imei = %s sv = %s\n", imei, sv);
353 }else{
354 printf("get imei and sv error, res = %d\n", res);
355 }
356 }
357 //flag_init = 0;
358 break;
359 }
360 //qser_reset_modem
361 case 12:
362 {
363 if(flag_init == 0){
364 printf("must init first\n");
365 }
366 else{
367 res = qser_reset_modem(h_sim);
368 if(res == 0)
369 {
370 printf("reset modem success!!!\n");
371 }else{
372 printf("reset modem error, res = %d\n", res);
373 }
374 }
375 //flag_init = 0;
376 break;
377 }
378 //qser_get_version
379 case 13:
380 {
381 char buf[VER_SIZE]="";
382 if(flag_init == 0){
383 printf("must init first\n");
384 }
385 else{
386 res = qser_get_version(h_sim, buf);
387 if(res == 0)
388 {
389 printf("get version success!!! ver = %s\n", buf);
390 }else{
391 printf("get version error, res = %d\n", res);
392 }
393 }
394 //flag_init = 0;
395 break;
396 }
397 //qser_reset_sim
398 case 14:
399 {
400 if(flag_init == 0){
401 printf("must init first\n");
402 }
403 else{
404 res = qser_reset_sim(h_sim);
405 if(res == 0)
406 {
407 printf("reset sim success!!!\n");
408 }else{
409 printf("reset sim error, res = %d\n", res);
410 }
411 }
412 //flag_init = 0;
413 break;
414 }
415 //qser_deinit_sim
416 case 15:
417 {
418 if(flag_init == 0){
419 printf("must init first\n");
420 }
421 else{
422 res = qser_sim_client_deinit(h_sim);
423 if(res == 0)
424 {
425 printf("sim deinit success is!!!\n");
426 }else{
427 printf("sim deint errors, res = %d\n", res);
428 }
429 }
430 flag_init = 0;
431 break;
432 }
433 default:
434 print_help();
435 break;
436 }
437
438 }
439
440 return 0;
441}