| #include <stdio.h> |
| #include <stdlib.h> |
| #include <errno.h> |
| #include <dlfcn.h> |
| |
| #include "mbtk/mbtk_type.h" |
| #include "mbtk/mbtk_device.h" |
| #include "utlAtParser.h" |
| #include "utlTrace.h" |
| |
| |
| #include "mbtk_device_info.h" |
| |
| #define MBTK_LIB_PATH "/lib/libmbtk_lib.so" |
| |
| typedef int (*mbtk_dev_info_read_func)(mbtk_device_info_item_enum, void *, int); |
| |
| //extern TelAtParserID mbtkCurAtHandle; |
| /* |
| ATI |
| Manufacturer:"LYNQ" |
| Model:"LYNQ_L501" |
| Revision:L501C_USBv02.04b07.01 |
| IMEI: 868070040313763 |
| |
| OK |
| */ |
| extern mbtk_dev_info *dev_infos_ptr; |
| |
| static bool dev_info_inited = FALSE; |
| static char revision_out[48] = {0}; |
| static char revision_in[64] = {0}; |
| static mbtk_dev_info_read_func dev_info_read = NULL; |
| |
| static int dev_info_get() |
| { |
| if(dev_info_inited) { |
| return 0; |
| } |
| void *handle = dlopen(MBTK_LIB_PATH , RTLD_LAZY); |
| if(handle == NULL) |
| { |
| DBGMSG(MBTK_AT, "dlopen() %s fail : %d", MBTK_LIB_PATH, errno); |
| return -1; |
| } |
| |
| dev_info_read = (mbtk_dev_info_read_func)dlsym(handle, "mbtk_dev_info_read"); |
| if(dev_info_read == NULL) |
| { |
| DBGMSG(MBTK_AT, "dlsym(mbtk_dev_info_read) fail : %d", errno); |
| return -1; |
| } |
| |
| mbtk_device_info_basic_t info_basic; |
| memset(&info_basic, 0, sizeof(mbtk_device_info_basic_t)); |
| |
| // mbtk_dev_info_read() |
| int result = dev_info_read(MBTK_DEVICE_INFO_ITEM_BASIC, &info_basic, sizeof(mbtk_device_info_basic_t)); |
| if(result) { |
| DBGMSG(MBTK_AT, "mbtk_dev_info_read(BASIC) fail."); |
| return -1; |
| } |
| |
| if(strlen(info_basic.revision_out) > 0) { |
| memcpy(revision_out, info_basic.revision_out, strlen(info_basic.revision_out)); |
| } |
| if(strlen(info_basic.revision_in) > 0) { |
| memcpy(revision_in, info_basic.revision_in, strlen(info_basic.revision_in)); |
| } |
| dev_info_inited = TRUE; |
| return 0; |
| } |
| |
| void mbtk_ati_str_get(char *ati_str, int len_max) |
| { |
| //char *imei = "868070040313763"; |
| |
| if(dev_infos_ptr) { |
| DBGMSG(MBTK_AT, "IMEI : %s[len - %d]", dev_infos_ptr->imei, strlen(dev_infos_ptr->imei)); |
| } else { |
| DBGMSG(MBTK_AT, "IMEI error."); |
| } |
| |
| char *revision_ptr = NULL; |
| if (InProduction_Mode() && !dev_info_get() && strlen(revision_out) > 0) { |
| revision_ptr = revision_out; |
| } else { |
| revision_ptr = MBTK_DEVICES_REVISION; |
| } |
| |
| if(dev_infos_ptr && strlen(dev_infos_ptr->imei) > 0) { |
| snprintf(ati_str, len_max, |
| "Manufacturer:\"%s\"\r\n" |
| "Model:\"%s\"\r\n" |
| "Revision:%s\r\n" |
| "IMEI:%s\r\n", |
| MBTK_DEVICES_MANUFACTURER, MBTK_DEVICES_MODEL, |
| revision_ptr, |
| dev_infos_ptr->imei); |
| } else { |
| snprintf(ati_str, len_max, |
| "Manufacturer:\"%s\"\r\n" |
| "Model:\"%s\"\r\n" |
| "Revision:%s\r\n" |
| "IMEI:\r\n", |
| MBTK_DEVICES_MANUFACTURER, MBTK_DEVICES_MODEL, |
| revision_ptr); |
| } |
| } |
| |