b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame^] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <errno.h> |
| 4 | #include <dlfcn.h> |
| 5 | |
| 6 | #include "mbtk/mbtk_type.h" |
| 7 | #include "mbtk/mbtk_device.h" |
| 8 | #include "utlAtParser.h" |
| 9 | #include "utlTrace.h" |
| 10 | |
| 11 | |
| 12 | #include "mbtk_device_info.h" |
| 13 | |
| 14 | #define MBTK_LIB_PATH "/lib/libmbtk_lib.so" |
| 15 | |
| 16 | typedef int (*mbtk_dev_info_read_func)(mbtk_device_info_item_enum, void *, int); |
| 17 | |
| 18 | //extern TelAtParserID mbtkCurAtHandle; |
| 19 | /* |
| 20 | ATI |
| 21 | Manufacturer:"LYNQ" |
| 22 | Model:"LYNQ_L501" |
| 23 | Revision:L501C_USBv02.04b07.01 |
| 24 | IMEI: 868070040313763 |
| 25 | |
| 26 | OK |
| 27 | */ |
| 28 | extern mbtk_dev_info *dev_infos_ptr; |
| 29 | |
| 30 | static bool dev_info_inited = FALSE; |
| 31 | static char revision_out[48] = {0}; |
| 32 | static char revision_in[64] = {0}; |
| 33 | static mbtk_dev_info_read_func dev_info_read = NULL; |
| 34 | |
| 35 | static int dev_info_get() |
| 36 | { |
| 37 | if(dev_info_inited) { |
| 38 | return 0; |
| 39 | } |
| 40 | void *handle = dlopen(MBTK_LIB_PATH , RTLD_LAZY); |
| 41 | if(handle == NULL) |
| 42 | { |
| 43 | DBGMSG(MBTK_AT, "dlopen() %s fail : %d", MBTK_LIB_PATH, errno); |
| 44 | return -1; |
| 45 | } |
| 46 | |
| 47 | dev_info_read = (mbtk_dev_info_read_func)dlsym(handle, "mbtk_dev_info_read"); |
| 48 | if(dev_info_read == NULL) |
| 49 | { |
| 50 | DBGMSG(MBTK_AT, "dlsym(mbtk_dev_info_read) fail : %d", errno); |
| 51 | return -1; |
| 52 | } |
| 53 | |
| 54 | mbtk_device_info_basic_t info_basic; |
| 55 | memset(&info_basic, 0, sizeof(mbtk_device_info_basic_t)); |
| 56 | |
| 57 | // mbtk_dev_info_read() |
| 58 | int result = dev_info_read(MBTK_DEVICE_INFO_ITEM_BASIC, &info_basic, sizeof(mbtk_device_info_basic_t)); |
| 59 | if(result) { |
| 60 | DBGMSG(MBTK_AT, "mbtk_dev_info_read(BASIC) fail."); |
| 61 | return -1; |
| 62 | } |
| 63 | |
| 64 | if(strlen(info_basic.revision_out) > 0) { |
| 65 | memcpy(revision_out, info_basic.revision_out, strlen(info_basic.revision_out)); |
| 66 | } |
| 67 | if(strlen(info_basic.revision_in) > 0) { |
| 68 | memcpy(revision_in, info_basic.revision_in, strlen(info_basic.revision_in)); |
| 69 | } |
| 70 | dev_info_inited = TRUE; |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | void mbtk_ati_str_get(char *ati_str, int len_max) |
| 75 | { |
| 76 | //char *imei = "868070040313763"; |
| 77 | |
| 78 | if(dev_infos_ptr) { |
| 79 | DBGMSG(MBTK_AT, "IMEI : %s[len - %d]", dev_infos_ptr->imei, strlen(dev_infos_ptr->imei)); |
| 80 | } else { |
| 81 | DBGMSG(MBTK_AT, "IMEI error."); |
| 82 | } |
| 83 | |
| 84 | char *revision_ptr = NULL; |
| 85 | if (InProduction_Mode() && !dev_info_get() && strlen(revision_out) > 0) { |
| 86 | revision_ptr = revision_out; |
| 87 | } else { |
| 88 | revision_ptr = MBTK_DEVICES_REVISION; |
| 89 | } |
| 90 | |
| 91 | if(dev_infos_ptr && strlen(dev_infos_ptr->imei) > 0) { |
| 92 | snprintf(ati_str, len_max, |
| 93 | "Manufacturer:\"%s\"\r\n" |
| 94 | "Model:\"%s\"\r\n" |
| 95 | "Revision:%s\r\n" |
| 96 | "IMEI:%s\r\n", |
| 97 | MBTK_DEVICES_MANUFACTURER, MBTK_DEVICES_MODEL, |
| 98 | revision_ptr, |
| 99 | dev_infos_ptr->imei); |
| 100 | } else { |
| 101 | snprintf(ati_str, len_max, |
| 102 | "Manufacturer:\"%s\"\r\n" |
| 103 | "Model:\"%s\"\r\n" |
| 104 | "Revision:%s\r\n" |
| 105 | "IMEI:\r\n", |
| 106 | MBTK_DEVICES_MANUFACTURER, MBTK_DEVICES_MODEL, |
| 107 | revision_ptr); |
| 108 | } |
| 109 | } |
| 110 | |