wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 1 | #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 | |
| 17 | typedef uint32_t sim_client_handle_type; |
| 18 | |
| 19 | sim_client_handle_type ph_sim = 2023; |
| 20 | sim_client_handle_type h_sim = 2023; |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 21 | |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 22 | |
| 23 | int main(int argc, char const *argv[]) |
| 24 | { |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 25 | 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"); |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 43 | |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 44 | while(1) |
| 45 | { |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 46 | int cmdIdx = -1; |
| 47 | int res = -1; |
| 48 | |
| 49 | printf("operator: >> \n"); |
| 50 | |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 51 | scanf("%d", &cmdIdx); |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 52 | fflush(stdin); |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 53 | |
| 54 | switch(cmdIdx) |
| 55 | { |
| 56 | //"qser_sim_init" |
| 57 | case 0: |
| 58 | { |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 59 | //int token; |
| 60 | //printf("input token\n"); |
| 61 | //scanf("%d", &token); |
| 62 | res = qser_sim_client_init(&h_sim); |
| 63 | if(res == 0) |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 64 | { |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 65 | printf("Run qser_sim_client_init\n"); |
| 66 | }else{ |
| 67 | printf("qser_sim_client_init error\n"); |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 68 | } |
| 69 | } |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 70 | break; |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 71 | //"qser_sim_getimsi" |
| 72 | case 1: |
| 73 | { |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 74 | 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); |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 82 | } |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 83 | } |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 84 | break; |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 85 | //"qser_get_iccid" |
| 86 | case 2: |
| 87 | { |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 88 | 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); |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 95 | } |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 96 | } |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 97 | break; |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 98 | //qser_get_phonenumber |
| 99 | case 3: |
| 100 | { |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 101 | 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); |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 109 | } |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 110 | } |
| 111 | break; |
| 112 | //qser_verify_pin |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 113 | case 4: |
| 114 | { |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 115 | 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.liu | 8583dce | 2024-04-03 13:30:08 +0800 | [diff] [blame] | 122 | |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 123 | 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.liu | 8583dce | 2024-04-03 13:30:08 +0800 | [diff] [blame] | 129 | } |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 130 | } |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 131 | break; |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 132 | //qser_change_pin |
| 133 | case 5: |
| 134 | { |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 135 | 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.liu | 8583dce | 2024-04-03 13:30:08 +0800 | [diff] [blame] | 148 | |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 149 | 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.liu | 8583dce | 2024-04-03 13:30:08 +0800 | [diff] [blame] | 155 | } |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 156 | } |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 157 | break; |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 158 | //qser_unlock_pin |
| 159 | case 6: |
| 160 | { |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 161 | 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.liu | 8583dce | 2024-04-03 13:30:08 +0800 | [diff] [blame] | 168 | |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 169 | 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.liu | 8583dce | 2024-04-03 13:30:08 +0800 | [diff] [blame] | 182 | } |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 183 | } |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 184 | break; |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 185 | //qser_enable_pin |
| 186 | case 7: |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 187 | { |
| 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); |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 201 | } |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 202 | } |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 203 | break; |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 204 | //qser_disable_pin |
| 205 | case 8: |
| 206 | { |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 207 | 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); |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 220 | } |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 221 | } |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 222 | break; |
| 223 | //qser_get_sim_status |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 224 | case 9: |
| 225 | { |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 226 | QSER_SIM_CARD_STATUS_INFO_T pt_info; |
b.liu | 8583dce | 2024-04-03 13:30:08 +0800 | [diff] [blame] | 227 | |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 228 | 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.liu | 8583dce | 2024-04-03 13:30:08 +0800 | [diff] [blame] | 234 | } |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 235 | } |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 236 | break; |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 237 | //qser_get_imei |
| 238 | case 10: |
| 239 | { |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 240 | 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); |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 247 | } |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 248 | } |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 249 | break; |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 250 | //qser_get_imei_and_sv |
| 251 | case 11: |
| 252 | { |
| 253 | char imei[BUF_SIZE]=""; |
| 254 | char sv[BUF_SIZE]=""; |
| 255 | |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 256 | 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); |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 262 | } |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 263 | } |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 264 | break; |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 265 | //qser_reset_modem |
| 266 | case 12: |
| 267 | { |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 268 | 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); |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 274 | } |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 275 | } |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 276 | break; |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 277 | //qser_get_version |
| 278 | case 13: |
| 279 | { |
| 280 | char buf[VER_SIZE]=""; |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 281 | |
| 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); |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 288 | } |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 289 | } |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 290 | break; |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 291 | //qser_reset_sim |
| 292 | case 14: |
| 293 | { |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 294 | 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); |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 300 | } |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 301 | } |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 302 | break; |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 303 | //qser_deinit_sim |
| 304 | case 15: |
| 305 | { |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 306 | 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); |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 312 | } |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 313 | } |
b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame] | 314 | break; |
| 315 | case 16: |
| 316 | printf("main exit\n"); |
| 317 | return 0; |
| 318 | default : |
wangyouqiang | 3e3bf92 | 2024-01-05 15:38:34 +0800 | [diff] [blame] | 319 | break; |
| 320 | } |
| 321 | |
| 322 | } |
| 323 | |
| 324 | return 0; |
| 325 | } |