blob: b7dea00ef0d3242166010ff15e26b34d12475e3f [file] [log] [blame]
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <dlfcn.h>
#include <stdint.h>
#include <string.h>
#include <pthread.h>
//mbtk include
typedef unsigned int uint32;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef void (*mbtk_info_callback_func)(const void* data, int data_len);
typedef struct
{
int client_fd;
pthread_t read_thread_id;
int exit_fd[2];
bool is_waitting;
pthread_cond_t cond;
pthread_mutex_t mutex;
pthread_mutex_t send_mutex;
// Temp response data.
uint16 info_err;
uint16 data_len;
void *data;
//mbtk wyq for server_ready_status add start
char server_ready_status;
//mbtk wyq for server_ready_status add end
mbtk_info_callback_func net_state_cb;
mbtk_info_callback_func call_state_cb;
mbtk_info_callback_func sms_state_cb;
mbtk_info_callback_func radio_state_cb;
mbtk_info_callback_func sim_state_cb;
mbtk_info_callback_func pdp_state_cb;
//add signal by xr
mbtk_info_callback_func signal_state_cb;
} mbtk_info_handle_t;
typedef enum {
MBTK_SIM_ABSENT = 0,
MBTK_SIM_NOT_READY = 1,
MBTK_SIM_READY = 2,
MBTK_SIM_PIN = 3,
MBTK_SIM_PUK = 4,
MBTK_SIM_NETWORK_PERSONALIZATION = 5
} mbtk_sim_state_enum;
typedef enum
{
MBTK_DEV_MODEM_MIN_FUN, //Modem 最小功能
MBTK_DEV_MODEM_FULL_FUN, //Modem 全功能
MBTK_DEV_MODEM_DISABLE_RECEIVE_RF_CIRCUITS = 3, //Modem 禁用射频接收电路
MBTK_DEV_MODEM_DISABLE_TRANSMIT_AND_RECEIVE_RF_CIRCUITS, //Modem禁用射频发射和接收电路
MBTK_DEV_MODEM_DISABLE_SIM, //Modem 禁用(U)SIM 卡
MBTK_DEV_MODEM_TURN_OFF_FULL_SECONDARY_RECEIVE, //Modem 完全禁用辅助接收
}MBTK_DEV_MODEM_FUNCTION;
typedef struct
{
MBTK_DEV_MODEM_FUNCTION fun;
int rst;
} mbtk_modem_info_t;
//gsw include
#define GSW_HAL_SUCCESS 0
#define GSW_HAL_FAIL -1
#define GSW_HAL_MEM_INVAILD -2
#define GSW_SIM_ICCID_LENGTH 20+1
#define GSW_SIM_IMSI_LENGTH 20+1
#define GSW_SIM_MSISDN_LENGTH 20+1
#define GSW_SIM_IMEI_LENGTH 20+1
typedef enum sim_status
{
SIM_STATUS_ABSENT = 0, /**< sim absent*/
SIM_STATUS_PRESENT = 1, /**< sim present mtk as ready*/
SIM_STATUS_ERROR = 2, /**< sim error*/
SIM_STATUS_READY = 3, /**< sim state ready mtk no this value*/
SIM_STATUS_PIN = 4, /**< pinlock status*/
} sim_status_e_type;
int (*gsw_sim_sdk_init)(int32_t token);
int (*gsw_sim_sdk_deinit)(void);
int (*gsw_get_sim_status)(int32_t *sim_state);
int (*gsw_get_sim_iccid)(int32_t len, int8_t *iccid);
int (*gsw_get_sim_imsi)(int32_t len, int8_t *imsi);
int (*gsw_get_sim_msisdn)(int32_t len, int8_t *msisdn);
int (*gsw_set_sim_power_down)(void);
int (*gsw_set_sim_power_up)(void);
#define lib_gsw_sim_path "/lib/libgsw_lib.so"
static void *dlHandle_sim = NULL;
static int gsw_sim_api_import()
{
dlHandle_sim = dlopen(lib_gsw_sim_path, RTLD_NOW);
if (dlHandle_sim == NULL) {
printf("dlopen gsw_sim_sdk_init fail\n");
return GSW_HAL_FAIL;
}
gsw_sim_sdk_init = (int(*)(int32_t token))dlsym(dlHandle_sim, "gsw_sim_sdk_init");
if (gsw_sim_sdk_init == NULL) {
printf("dlsym gsw_sim_sdk_init fail\n");
return GSW_HAL_FAIL;
}
gsw_sim_sdk_deinit = (int(*)(void))dlsym(dlHandle_sim, "gsw_sim_sdk_deinit");
if (gsw_sim_sdk_deinit == NULL) {
printf("dlsym gsw_sim_sdk_deinit fail\n");
return GSW_HAL_FAIL;
}
gsw_get_sim_status = (int(*)(int32_t *sim_state))dlsym(dlHandle_sim, "gsw_get_sim_status");
if (gsw_get_sim_status == NULL) {
printf("dlsym gsw_get_sim_status fail\n");
return GSW_HAL_FAIL;
}
gsw_get_sim_iccid = (int(*)(int32_t len, int8_t *iccid))dlsym(dlHandle_sim, "gsw_get_sim_iccid");
if (gsw_get_sim_iccid == NULL) {
printf("dlsym gsw_get_sim_iccid fail\n");
return GSW_HAL_FAIL;
}
gsw_get_sim_imsi = (int(*)(int32_t len, int8_t *imsi))dlsym(dlHandle_sim, "gsw_get_sim_imsi");
if (gsw_get_sim_imsi == NULL) {
printf("dlsym gsw_get_sim_imsi fail\n");
return GSW_HAL_FAIL;
}
gsw_get_sim_msisdn = (int(*)(int32_t len, int8_t *msisdn))dlsym(dlHandle_sim,"gsw_get_sim_msisdn");
if (gsw_get_sim_msisdn == NULL) {
printf("dlsym gsw_get_sim_msisdn fail\n");
return GSW_HAL_FAIL;
}
gsw_set_sim_power_down = (int(*)(void))dlsym(dlHandle_sim,"gsw_set_sim_power_down");
if (gsw_set_sim_power_down == NULL) {
printf("dlsym gsw_set_sim_power_down fail\n");
return GSW_HAL_FAIL;
}
gsw_set_sim_power_up = (int(*)(void))dlsym(dlHandle_sim,"gsw_set_sim_power_up");
if (gsw_set_sim_power_up == NULL) {
printf("dlsym gsw_set_sim_power_up fail\n");
return GSW_HAL_FAIL;
}
return GSW_HAL_SUCCESS;
}
int main()
{
char operator[10];
int opt;
int ret = -1;
gsw_sim_api_import();
while(1)
{
printf("-1.exit\n");
printf("1.sim init\n");
printf("2.sim deinit\n");
printf("3.imsi : Get IMSI.\n");
printf("4.iccid : Get ICCID.\n");
printf("5.msisdn : Get phone number.\n");
printf("6.sim states\n");
printf("7.sim power_down\n");
printf("8.sim power_up\n");
printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Enter cmd:");
char* temp = NULL;
memset(operator, 0, sizeof(operator));
temp = fgets(operator, sizeof(operator), stdin);
fflush(stdin);
printf("temp = %s",temp);
opt = atoi(operator);
switch(opt)
{
case -1:
{
printf("exit\n");
return 0;
}
//gsw_sim_sdk_init
case 1:
{
printf("sdk_init\n");
ret = gsw_sim_sdk_init(123);
if(ret == 0)
{
printf("gsw_sim_sdk_init success\n");
}
else
{
printf("gsw_sim_sdk_init fail,ret = %d\n",ret);
}
break;
}
//sim deinit
case 2:
{
printf("sim deinit\n");
ret = gsw_sim_sdk_deinit();
if(ret == 0)
{
printf("gsw_sim_sdk_deinit success\n");
}
else
{
printf("gsw_sim_sdk_deinit fail,ret = %d\n",ret);
}
break;
}
//imsi
case 3:
{
char imsi[GSW_SIM_IMEI_LENGTH] = {0};
ret = gsw_get_sim_imsi(GSW_SIM_IMEI_LENGTH, (int8_t *)imsi);
if(ret == 0)
{
printf("gsw_get_sim_imsi success, imsi = %s\n",imsi);
}
else
{
printf("gsw_get_sim_imsi fail,ret = %d\n",ret);
}
break;
}
//iccid
case 4:
{
char iccid[GSW_SIM_ICCID_LENGTH] = {0};
ret = gsw_get_sim_iccid(GSW_SIM_ICCID_LENGTH, (int8_t *)iccid);
if(ret == 0)
{
printf("gsw_get_sim_iccid success, iccid = %s\n",iccid);
}
else
{
printf("gsw_get_sim_iccid fail,ret = %d\n",ret);
}
break;
}
//msisdn
case 5:
{
char msisdn[GSW_SIM_MSISDN_LENGTH] = {0};
ret = gsw_get_sim_msisdn(GSW_SIM_MSISDN_LENGTH, (int8_t *)msisdn);
if(ret == 0)
{
printf("gsw_get_sim_msisdn success, msisdn = %s\n",msisdn);
}
else
{
printf("gsw_get_sim_msisdn fail,ret = %d\n",ret);
}
break;
}
//sim states
case 6:
{
int sim_state;
printf("start gsw_get_sim_status\n");
ret = gsw_get_sim_status(&sim_state);
printf("end gsw_get_sim_status\n");
if(ret == 0)
{
printf("gsw_get_sim_status success,sim_state = %d\n",sim_state);
}
else
{
printf("gsw_get_sim_status fail,ret = %d\n",ret);
}
break;
}
//sim power_down
case 7:
{
ret = gsw_set_sim_power_down();
if(ret == 0)
{
printf("gsw_set_sim_power_down success\n");
}
else
{
printf("gsw_set_sim_power_down fail,ret = %d\n",ret);
}
break;
}
//sim power_up
case 8:
{
ret = gsw_set_sim_power_up();
if(ret == 0)
{
printf("gsw_set_sim_power_up success\n");
}
else
{
printf("gsw_set_sim_power_up fail,ret = %d\n",ret);
}
break;
}
default :
{
printf("error cmd.\n");
continue;
}
}
}
}