blob: 4f1fd2a97da824dd5617da0e8eefa8ee63d7e3cc [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/**
2* @File: sanichips_dm.c
3* @Brief: Implementation of Device Manager in Sanechips
4*
5* Copyright (C) 2017 Sanechips Technology Co., Ltd.
6* @Author: chen tianming <chen.tianming@sanechips.com.cn>
7*
8* This program is free software; you can redistribute it and/or modify
9* it under the terms of the GNU General Public License version 2 as
10* published by the Free Software Foundation.
11* */
12
13/*******************************************************************************
14 * Í·Îļþ *
15 ******************************************************************************/
16
17#include <pthread.h>
18#include <sys/types.h>
19#include <sys/ipc.h>
20#include <sys/msg.h>
21#include <sys/prctl.h>
22#include "rtc_timer.h"
23#include <stdio.h>
24#include <error.h>
25#include <unistd.h>
26
27#include "cfg_nv_def.h"
28
29#include "softap_api.h"
30#include "unicom_dm.h"
31#include "mobile_dm.h"
32#include "telecom_dm.h"
33/*******************************************************************************
34 * ºê¶¨Òå *
35 ******************************************************************************/
36#define DM_NV_ITEM_SIZE 64
37#define DM_INFO_MAX_SIZE 64
38#define DM_INTERNAL_MSG_SIZE 128
39#define DM_MSG_CMD_REGISTER_REQUEST 0x1000
40#define DM_ROUND_TOTAL 10
41#define DM_MSG_CMD_REGISTER_THREAD_RELEASE 0x1001
42#define DM_MSG_CMD_MAIN_THREAD_EXIT 0x1002
43#define DM_TELECOM_RETRY_TIMES 10
44#define DM_TELECOM_RETRYTIMES_BEFORE_ACTIVED 30
45/*NV name*/
46#define DM_REGISTERED_ROUND "registeredRound"
47#define DM_SECS_EVERY_ROUND "secsEveryRound"
48#define DM_SECS_EVERY_TIME "secsEveryTime"
49#define DM_SEC_TIMER "secsTime"
50#define DM_REGISTER_FLAG "registerFlag"
51#define DM_REGISTER_TYPE "registerDmType"
52
53#define DM_APP_KEY_MOBILE "appKeyMobile"
54#define DM_HOST_NAME "hostName"
55#define DM_PORT_NUM "portNum"
56
57#define DM_MANUF "Manuf"
58#define DM_MODEL "Model"
59#define DM_HW_VERSION "hw_version"
60#define DM_SW_VERSION "wa_version"
61#define DM_OS "OS"
62#define DM_OS_VERSION "OSVersion"
63#define DM_IN_TYPE "Intype"
64#define DM_BRAND "Brand"
65
66#define DM_WCDMA_ONLY "wcdmaModel"
67#define DM_URL_MOBILE "urlMobile"
68
69#define DM_IMEI_PREVIOUS "imeiPrevious"
70#define DM_ICCID_PREVIOUS "iccidPrevious"
71#define DM_VERSION_PREVIOU "versionPrevious"
72#define DM_SIM_CARD_STATUS "creg_stat"
73#define DM_CEREG_STATUS "cereg_stat"
74
75#define DM_REGVER "regver"
76#define DM_MEID "meid"
77#define DM_UETYPE "uetype"
78
79#define DM_SYSTEM_LOCK_FILE_PATH "/sys/power/wake_lock"
80#define DM_SYSTEM_UNLOCK_FILE_PATH "/sys/power/wake_unlock"
81
82
83#define log(...) do { printf(__VA_ARGS__); fflush(stdout); } while(0)
84#define log_err(...) do { log("DM-ERR NOW: FILE(%s) ,LINE(%d) >>>>: ", __FILE__, __LINE__ ); printf(__VA_ARGS__); fflush(stdout);} while(0)
85#ifndef __DM_NO_EBUG__
86#define log_debug(...) do { log("dm-debug now: file(%s) ,line(%d) >>>>: ", __FILE__, __LINE__); printf(__VA_ARGS__); fflush(stdout);} while(0)
87#else
88#define log_debug(...)
89#endif
90
91#define CALL(X) do { int t_ret = (X); if (t_ret != DM_ERR_SUCCESS) { log_err("Get t_ret(%d)\n", t_ret); return t_ret;} } while(0)
92#define CHECK_PARAM(X) do { if(!(X)) {log_err("the param is null\n"); return DM_ERR_PARAM_NULL;} } while(0)
93
94// tap_log(LOG_ERR,MMI_PRINT,"Function rpc_AddObject: %s", ERROR1);
95/*******************************************************************************
96 * Êý¾ÝÀàÐͶ¨Òå *
97 ******************************************************************************/
98
99enum
100{
101 DM_ERR_SUCCESS,
102 DM_ERR_PARAM_NULL,
103 DM_ERR_CREATE_THERAD_ERROR,
104 DM_ERR_CREATE_MSG_QUEUE_ERROR,
105 DM_ERR_DEVICE_TYPE_IS_NONE,
106 DM_ERR_CREATE_TIMER_ERROR,
107 DM_ERR_DEVICE_REGISTERED,
108 DM_ERR_ADD_TIMER_ERROR,
109 DM_ERR_SET_DOMAIN_ERR,
110 DM_ERR_WAITING_NET_STATUS_CHANAGE,
111 DM_ERR_QUEUE_SEND_ERROR,
112 DM_ERR_CHECK_ROUTE_ERROR,
113 DM_ERR_IPC_SEND_MESSAGE_ERROR,
114 DM_ERR_CREATE_JSON_INFO_ERROR,
115 DM_ERR_URL_INFO_CREATE_ERROR,
116 DM_ERR_MOBILE_OVER_RETRY_TMIES_ERROR,
117 DM_ERR_SERVER_ERROR,
118 DM_ERR_SET_TIME_ROUND_ERROR,
119 DM_ERR_NET_ERROR,
120 DM_ERR_RETRY_ERROR,
121 DM_ERR_NO_MOBILE_CARD_ERROR,
122 DM_ERR_ROMAING_STATUS_ERROR,
123};
124
125/* DM ¶¨Ê±Æ÷ID£¬*/
126enum
127{
128 DM_TIMER_ID_UNICOM_START,
129 DM_TIMER_ID_MOBILE_START,
130 DM_TIMER_ID_UNICOM_EVERY_TIMES,
131 DM_TIMER_ID_UNICOM_EVERY_ROUND,
132 DM_TIMER_ID_MOBILE_EVERY_TIMES,
133 DM_TIMER_ID_MAX,
134};
135
136/*DM ×¢²á±ê¼Ç */
137enum
138{
139 DM_REGISTERED_NO,
140 DM_REGISTERED_YES,
141};
142
143/* µ±Ç°ÖÕ¶ËÖÆÊ½ */
144enum DM_TYPE
145{
146 DM_NO_ONE,
147 DM_MOBILE,
148 DM_UNICOM,
149 DM_TELECOM,
150};
151
152/* ÁªÍ¨ÐÅÏ¢½á¹¹ÌåË÷Òý */
153enum DM_UNICOM_INFO_INDEX
154{
155 DM_INFO_MANUF = 0,
156 DM_INFO_MODEL,
157 DM_INFO_HWVISION,
158 DM_INFO_SWVERSION,
159 DM_INFO_OS,
160 DM_INFO_OSVISION,
161 DM_INFO_IMEI1,
162 DM_INFO_ICCID1,
163 DM_INFO_IMSI1,
164 DM_INFO_MSISDN1,
165 DM_INFO_MNC1,
166 DM_INFO_NCLS1,
167 DM_INFO_CELLID1,
168 DM_INFO_LAC1,
169 DM_INFO_ACCTYPE,
170 DM_INFO_TIME,
171 DM_INFO_TAG,
172 DM_INFO_UNICOM_MAX,
173};
174
175/*struct DM_UNICOM - Áªµ÷×¢²áµÄÐÅÏ¢½á¹¹ÃèÊö */
176struct DM_UNICOM_REGISTER_INFO
177{
178 char value[DM_INFO_UNICOM_MAX][DM_INFO_MAX_SIZE];
179};
180
181/* ÒÆ¶¯DMÐÅÏ¢½á¹¹Ë÷Òý */
182typedef enum
183{
184 DM_INFO_MOBILE_SDKVERSION = 0,
185 DM_INFO_MOBILE_IMEI1,
186 DM_INFO_MOBILE_IMEI2,
187 DM_INFO_MOBILE_MEID,
188 DM_INFO_MOBILE_DEVICE_ID,
189 DM_INFO_MOBILE_BRAND,
190 DM_INFO_MOBILE_MODEL,
191 DM_INFO_MOBILE_FIRMWARE_VERSION,
192 DM_INFO_MOBILE_SYSTEM_VERSION,
193 DM_INFO_MOBILE_CPU,
194 DM_INFO_MOBILE_ROM,
195 DM_INFO_MOBILE_RAM,
196 DM_INFO_MOBILE_TYPE,
197 DM_INFO_MOBILE_ICCID1,
198 DM_INFO_MOBILE_ICCID2,
199 DM_INFO_MOBILE_IMSI1,
200 DM_INFO_MOBILE_IMSI2,
201 DM_INFO_MOBILE_MAC,
202 DM_INFO_MOBILE_CELLID,
203 DM_INFO_MOBILE_LAC,
204 DM_INFO_MOBILE_CHNL,
205 DM_INFO_MOBILE_DATA_CARD,
206 DM_INFO_MOBILE_MASTER_STATUS,
207 DM_INFO_MOBILE_SEND_TIME,
208 DM_INFO_MOBILE_SLOT_QUANTITY,
209 DM_INFO_MOBILE_DATA_CARD2,
210 DM_INFO_MOBILE_SLOT_SERVICE1,
211 DM_INFO_MOBILE_SLOT_SERVICE2,
212 DM_INFO_MOBILE_SLOT_NETWORK1,
213 DM_INFO_MOBILE_SLOT_NETWORK2,
214 DM_INFO_MOBILE_LAC2,
215 DM_INFO_MOBILE_CELLID2,
216 DM_INFO_MOBILE_TERMINAL_INTTYPE,
217 DM_INFO_MOBILE_MAX
218} DM_INFO_MOBILE_INDEX;
219
220/*struct DM_MOBILE_INFO ÒÆ¶¯×¢²áµÄÐÅÏ¢½á¹¹ÃèÊö */
221struct DM_MOBILE_REGISTER_INFO
222{
223 char value[DM_INFO_MOBILE_MAX][DM_INFO_MAX_SIZE];
224};
225
226/* µçÐÅÐÅÏ¢½á¹¹ÌåË÷Òý */
227enum DM_TELECOM_INFO_INDEX
228{
229 DM_INFO_REGVER = 0,
230 DM_INFO_MEID,
231 DM_INFO_MODELSMS,
232 DM_INFO_SWVER,
233 DM_INFO_SIM1CDMAIMSI,
234 DM_INFO_UETYPE,
235 DM_INFO_SIM1ICCID,
236 DM_INFO_SIM1LTEIMSI,
237 DM_INFO_IMEI,
238 DM_INFO_BASEID1,
239 DM_INFO_SIM1TYPE,
240 DM_INFO_SID,
241 DM_INFO_NID,
242 DM_INFO_TELECOM_MAX,
243};
244
245/*struct DM_TELECOM - µçÐÅ×¢²áµÄÐÅÏ¢½á¹¹ÃèÊö */
246struct DM_TELECOM_REGISTER_INFO
247{
248 char value[DM_INFO_TELECOM_MAX][DM_INFO_MAX_SIZE];
249};
250
251/**
252 * @brief struct DM_CONTROl_INFO DMÄ£¿éÄÚ²¿ÐÅÏ¢ÃèÊö
253 * @param DM_TYPE:dm ÀàÐÍ moblie unicom telecom
254 * @param registErThreadFlag:×¢²áÏ̱߳ê¼Ç£¬×¢²áÍê³ÉÍ˳öÏß³Ì
255 * @param mainThreadFlag:Ö÷Ï̱߳ê¼Ç£¬×¢²áÍê³ÉÍ˳öÏß³Ì
256 * @param secTimer: dm¿ª»ú¶¨Ê±Ê±¼ä
257 * @param pid:·þÎñÏ̵߳ÄID
258 * @param serverPid:Ö÷Ïß³ÌID
259 * @param msgQueueId:Ö÷ÏûÏ¢¶ÓÁеÄID
260 * @param msgQueueIdReg:×¢²áÏß³ÌÏûÏ¢¶ÓÁÐID
261 * @param registerFlag:×¢²á±êÖ¾£¬±ê¼ÇÊÇ·ñÒѾ­×¢²á
262 * @param secsEveryRound:ÿÂÖ¼ä¸ôµÄʱ¼ä
263 * @param secsEveryTime:ÿ´Î¼ä¸ôµÄʱ¼ä
264 * @param registerTimesEveryRound:ÿÂÖ³¢ÊԵĴÎÊý
265 * @param registerRoundsCurrent:µ±Ç°¿ª»ú³¢ÊÔµÄÂÖÊý
266 * @param registeredRounds:ÒѾ­³¢ÊÔµÄÂÖÊý
267 * @param currentRouds:µ±Ç°³¢ÊÔ×¢²áµÄÂÛÊý
268 * @param currentTimes:µ±Ç°³¢ÊÔ×¢²áµÄ´ÎÊý
269 * @param netStatus:±ê¼Çµ±Ç°µÄÍøÂç״̬
270 * @param imeiPrevious:ÉÏÒ»´Î±£´æµÄimei
271 * @param iccidprevious:ÉÏÒ»´Î±£´æµÄiccid
272 * @param hostName:·þÎñÆ÷ÓòÃû
273 * @param ipAddr:·þÎñÆ÷µØÖ·
274 * @param portNum:·þÎñÆ÷¶Ë¿Ú
275 * @note
276 * @warning
277 */
278struct DM_CONTROl_INFO
279{
280 enum DM_TYPE dmType;
281 int registErThreadFlag;
282 int mainThreadFlag;
283 int secTimer;
284 pthread_t pid;
285 pthread_t serverId;
286 int msgQueueId;
287 int msgQueueIdReg;
288 int registerFlag;
289 int secsEveryRound;
290 int secsEveryTime;
291 int registeredRounds;
292 int currentRounds;
293 int currentTimes;
294 int netStatus;
295 int globalRomaing;
296 int cardType;
297 int needRegForNetStatusChange;
298 char hostName[DM_INFO_MAX_SIZE];
299 char imeiPrevious[DM_INFO_MAX_SIZE];
300 char iccidPrevious[DM_INFO_MAX_SIZE];
301 char ipAddr[32];
302 unsigned long portNum;
303};
304
305/*******************************************************************************
306 * ¾²Ì¬±äÁ¿¶¨Òå *
307 ******************************************************************************/
308static int g_retrytimes_before_netactived = 0;
309
310/*******************************************************************************
311 * ¾²Ì¬º¯Êý¶¨Òå *
312 ******************************************************************************/
313static int dm_control_info_init(struct DM_CONTROl_INFO *dmControlInfo);
314static int dm_register_thread_init(struct DM_CONTROl_INFO *dmControlInfo);
315static int dm_timer_create(struct DM_CONTROl_INFO *dmControlInfo);
316static int dm_server_init(struct DM_CONTROl_INFO *dmControlInfo);
317
318static void* dm_server_thread_entry(void* args);
319static void dm_register_queue_msg_proc(MSG_BUF *pstMsg, struct DM_CONTROl_INFO *dmControlInfo);
320
321static int dm_get_device_type(struct DM_CONTROl_INFO *dmControlInfo);
322static int dm_unicom_control_info_init(struct DM_CONTROl_INFO *dmControlInfo);
323static int dm_mobile_control_info_init(struct DM_CONTROl_INFO *dmControlInfo);
324
325static void dm_wake_lock(const char *lockName);
326static void dm_wake_unlock(const char *unLockName);
327static void dm_write_lockfile(const char *filepath, const char *setbuf);
328
329static int dm_timer_add(unsigned long sec, RTC_ID rtcId);
330
331static void dm_register_flag_clean(struct DM_CONTROl_INFO *dmControlInfo);
332static int dm_server_domain_config_set(MSG_BUF *pstMsg, struct DM_CONTROl_INFO *dmControlInfo);
333static int dm_net_status_change_proc(struct DM_CONTROl_INFO *dmControlInfo);
334static int dm_register_request_handle(struct DM_CONTROl_INFO *dmControlInfo);
335static int dm_mobile_register_request_handle(struct DM_CONTROl_INFO *dmControlInfo);
336static int dm_unicom_register_request_handle(struct DM_CONTROl_INFO *dmControlInfo);
337static int dm_net_global_romaing_proc(struct DM_CONTROl_INFO *dmControlInfo);
338static int dm_unicom_register_start(struct DM_CONTROl_INFO *dmControlInfo);
339
340static int dm_register_msg_send(struct DM_CONTROl_INFO *dmControlInfo);
341static int dm_unicom_url_info_create(struct DM_CONTROl_INFO *dmControlInfo, struct DM_UNICOM_REGISTER_INFO *dmUnicomRegInfo, DM_UNICOM_HTTP_URL_INFO *dmUnicomUrlInfo);
342static int dm_mobile_url_info_create(struct DM_CONTROl_INFO *dmControlInfo, struct DM_MOBILE_REGISTER_INFO *dmMobileRegInfo, DM_MOBILE_HTTPS_URL_INIO *dmMobileUrlInfo);
343
344static int dm_unicom_json_info_create(struct DM_UNICOM_REGISTER_INFO *dmUnicomRegInfo, DM_UNICOM_HTTP_DATA_INFO * httpsDataInfo) ;
345static int dm_mobile_json_info_create(struct DM_MOBILE_REGISTER_INFO *dmMobileRegInfo, DM_MOBILE_HTTPS_DATA_INFO * httpsDataInfo);
346static int dm_unicom_register_info_create(struct DM_CONTROl_INFO *dmControlInfo, struct DM_UNICOM_REGISTER_INFO *dmUnicomRegInfo);
347static int dm_mobile_register_info_create(struct DM_CONTROl_INFO *dmControlInfo, struct DM_MOBILE_REGISTER_INFO *dmMobileRegInfo);
348static void dm_resource_clean(struct DM_CONTROl_INFO *dmControlInfo, void *dataInfo);
349static int dm_register_time_set(struct DM_CONTROl_INFO *dmControlInfo, void *dataInfo);
350static void dm_register_tag_set(struct DM_CONTROl_INFO *dmControlInfo, struct DM_UNICOM_REGISTER_INFO *dmUnicomRegInfo);
351static int dm_mobile_register_start(struct DM_CONTROl_INFO *dmControlInfo);
352
353static int dm_config_info_msg_prc(MSG_BUF *pstMsg, struct DM_CONTROl_INFO *dmControlInfo);
354static int dm_time_every_round_set(MSG_BUF *pstMsg, struct DM_CONTROl_INFO *dmControlInfo);
355static int dm_server_port_num_set(MSG_BUF *pstMsg, struct DM_CONTROl_INFO *dmControlInfo);
356static void dm_data_channel_set(struct DM_MOBILE_REGISTER_INFO *dmMobileRegInfo);
357static int dm_register_thread_release(struct DM_CONTROl_INFO *dmControlInfo);
358static int dm_main_thread_release(struct DM_CONTROl_INFO *dmControlInfo);
359static void dm_rtc_timer_del();
360static int dm_telecom_register_request_handle(struct DM_CONTROl_INFO *dmControlInfo);
361BOOL dm_telecom_need_reg_check(struct DM_CONTROl_INFO *dmControlInfo);
362
363/**
364 * º¯ÊýÃû³Æ£º dm_get_device_type
365 * ¹¦ÄÜÃèÊö£º »ñÈ¡µ±Ç°µÄÉ豸ÀàÐÍ£ºÁªµ÷DM / ÒÆ¶¯DM
366 * ²ÎÊý˵Ã÷£º
367 * ·µ »Ø Öµ£º ³É¹¦ 0: ʧ°Ü ´íÎóÂë
368 * ÆäËü˵Ã÷£º
369 */
370static int dm_get_device_type(struct DM_CONTROl_INFO *dmControlInfo)
371{
372 char dmType[4] = {0};
373 char registerFlag[4] = {0};
374
375 CALL(sc_cfg_get(DM_REGISTER_TYPE, dmType, sizeof(dmType)));
376 CALL(sc_cfg_get(DM_REGISTER_FLAG, registerFlag, sizeof(registerFlag)));
377
378 dmControlInfo->dmType = atoi(dmType);
379 dmControlInfo->registerFlag = atoi(registerFlag);
380
381 return DM_ERR_SUCCESS;
382}
383
384/**
385 * º¯ÊýÃû³Æ£º dm_write_lockfile
386 * ¹¦ÄÜÃèÊö£º ÎļþдÈë×Ö·û²Ù×÷
387 * ²ÎÊý˵Ã÷£º
388 * ·µ »Ø Öµ£º
389 * ÆäËü˵Ã÷£º
390 */
391static void dm_write_lockfile(const char *filepath, const char *setbuf)
392{
393 int fd = -1;
394 int len = 0;
395 if (!filepath || !setbuf)
396 {
397 log_err("parm is null \n");
398 return;
399 }
400
401 fd = open(filepath, O_RDWR);
402 if (-1 == fd)
403 {
404 log_err("open lockfile fail\n");
405 return;
406 }
407
408 len = strlen(setbuf);
409 if (write(fd, setbuf, len) != len)
410 {
411 log_err("write lockfile fail\n");
412 }
413
414 close(fd);
415}
416
417/**
418 * º¯ÊýÃû³Æ£ºdm_wake_lock
419 * ¹¦ÄÜÃèÊö£ºDMÄ£¿éϵͳ˯ÃßÉÏËø
420 * ²ÎÊý˵Ã÷£º
421 * ·µ »Ø Öµ£º
422 * ÆäËü˵Ã÷£º
423 */
424static void dm_wake_lock(const char *lockName)
425{
426 dm_write_lockfile(DM_SYSTEM_LOCK_FILE_PATH, lockName);
427}
428
429/**
430 * º¯ÊýÃû³Æ£ºdm_wake_lock
431 * ¹¦ÄÜÃèÊö£ºDMÄ£¿éϵͳ˯Ãß½âËø
432 * ²ÎÊý˵Ã÷£º
433 * ·µ »Ø Öµ£ºÎÞ
434 * ÆäËü˵Ã÷£º
435 */
436static void dm_wake_unlock(const char *unLockName)
437{
438 dm_write_lockfile(DM_SYSTEM_UNLOCK_FILE_PATH, unLockName);
439}
440
441/**
442 * º¯ÊýÃû³Æ£ºdm_timer_add
443 * ¹¦ÄÜÃèÊö£ºÌí¼ÓRTC¶¨Ê±Æ÷
444 * ²ÎÊý˵Ã÷£ºsec: ·ÖÖÓ
445 * ·µ »Ø Öµ£º
446 * ÆäËü˵Ã÷£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
447 */
448static int dm_timer_add(unsigned long sec, RTC_ID rtcId)
449{
450 int ret = 0;
451 if (0 != (ret = rtc_timer_add(sec, rtcId, MODULE_ID_DMREG)))
452 {
453 log_err("dm add timer error... ret-value(%d)\n", ret);
454 return DM_ERR_ADD_TIMER_ERROR;
455 }
456 return DM_ERR_SUCCESS;
457}
458
459/**
460 * º¯ÊýÃû³Æ£ºdm_create_timer
461 * ¹¦ÄÜÃèÊö£ºDMÄ£¿é´´½¨rtc¶¨Ê±Æ÷
462 * ²ÎÊý˵Ã÷£º
463 * ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
464 * ÆäËü˵Ã÷£º
465 */
466static int dm_timer_create(struct DM_CONTROl_INFO *dmControlInfo)
467{
468 CHECK_PARAM(dmControlInfo);
469
470 if (DM_UNICOM == dmControlInfo->dmType && DM_REGISTERED_NO == dmControlInfo->registerFlag)
471 {
472
473 CALL(dm_timer_add(dmControlInfo->secTimer * 60, DM_TIMER_ID_UNICOM_START));
474 log_debug("dm timer create success: dmType(%d), secTimer(%d)\n", dmControlInfo->dmType, dmControlInfo->secTimer);
475 }
476 else if (DM_MOBILE == dmControlInfo->dmType)
477 {
478
479 CALL(dm_timer_add(10, DM_TIMER_ID_MOBILE_START));
480 log_debug("dm timer create success: dmType(%d), secTimer(%d)\n", dmControlInfo->dmType, dmControlInfo->secTimer);
481 }
482 else if(DM_TELECOM == dmControlInfo->dmType)
483 {
484 CALL(dm_timer_add(10, DM_TIMER_ID_MOBILE_START));
485 log_debug("dm timer create success: dmType(%d), secTimer(%d)\n", dmControlInfo->dmType, dmControlInfo->secTimer);
486 }
487 else
488 {
489
490 log_debug("dm do not need to create timer, because dm have registered or registerRound more than 10...\n");
491 }
492
493 return DM_ERR_SUCCESS;
494}
495
496/**
497 * º¯ÊýÃû³Æ£ºdm_net_status_change_proc
498 * ¹¦ÄÜÃèÊö£ºPDPÏûÏ¢Éϱ¨´¦Àíº¯Êý£¬¼àÌýÍøÂç״̬±ä»¯
499 * ²ÎÊý˵Ã÷£º
500 * ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
501 * ÆäËü˵Ã÷£º
502 */
503static int dm_net_status_change_proc(struct DM_CONTROl_INFO *dmControlInfo)
504{
505 CHECK_PARAM(dmControlInfo);
506 char netStatus[4] = {0};
507 char romaingStatus[DM_NV_ITEM_SIZE] = {0};
508
509 CALL(sc_cfg_get(NV_PDP_STATUS, netStatus, 4));
510 CALL(sc_cfg_get(NV_SIMCARD_ROAM, romaingStatus, sizeof(romaingStatus)));
511
512 dmControlInfo->netStatus = atoi(netStatus);
513
514 if (0 == strcmp(romaingStatus, "Internal"))
515 {
516 dmControlInfo->globalRomaing = 1;
517 }
518 else if (0 == strcmp(romaingStatus, "Home"))
519 {
520 dmControlInfo->globalRomaing = 0;
521 }
522 else
523 {
524 log_err("dm global romaing some error, romaingStatus(%s) \n ", romaingStatus);
525 return DM_ERR_WAITING_NET_STATUS_CHANAGE;
526 }
527
528 /* ÍøÂçÊý¾Ý¿ª¹Ø´ò¿ª£¬ Çҷǹú¼ÊÂþÓÎ */
529 if (dmControlInfo->netStatus && !dmControlInfo->globalRomaing)
530 {
531
532 /* ÏÂÃæ±ê¼ÇµÄ¹¦ÄÜÊÇ: ¶¨Ê±Æ÷³¬Ê±£¬¶øÓÉÓÚÍøÂç¹Ø±Õ£¬±ØÐëµÈ´ýÍøÂ翪¹Ø´ò¿ª½øÐÐ×¢²á
533 * Ðë±£Ö¤´Î±êÖ¾Ö»ÄÜÔÚ×¢²áÏß³ÌÖнøÐÐÐ޸ģ¬(Ô¤·À±äÁ¿¶àÏ߳̽»²æÐÞ¸Ä)
534 */
535 if (dmControlInfo->needRegForNetStatusChange == 1)
536 {
537 /* ÏûÏ¢·¢ËÍ£¬¿ªÊ¼×¢²áÁ÷³Ì */
538 CALL(dm_register_msg_send(dmControlInfo));
539 }
540 }
541
542 log_debug("dm net change now netstatus(%d), romaing(%d), netStatus(%s), romaingStatus(%s),needRegForNetStatusChange(%d) \n", dmControlInfo->netStatus, dmControlInfo->globalRomaing, netStatus, romaingStatus, dmControlInfo->needRegForNetStatusChange);
543 return DM_ERR_SUCCESS;
544}
545
546/**
547 * º¯ÊýÃû³Æ£ºdm_server_port_num_set
548 * ¹¦ÄÜÃèÊö£º×¢²áµÄ·þÎñÆ÷¶Ë¿ÚºÅÅäÖÃ(ÓÉCP²à¹¤³ÌÃüÁî´¥·¢)
549 * ²ÎÊý˵Ã÷£º
550 * ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
551 * ÆäËü˵Ã÷£º
552 */
553static int dm_server_port_num_set(MSG_BUF *pstMsg, struct DM_CONTROl_INFO *dmControlInfo)
554{
555 char *msgData = (char *) pstMsg->aucDataBuf;
556 char *portNum = NULL;
557 char port[12] = {0};
558
559 if (!(portNum = strstr(msgData, "AT+DM_REGISTER_PORT_NUM=")))
560 {
561 log_err("dm set portNum erro , can not find server portNum \n");
562 return DM_ERR_SET_DOMAIN_ERR;
563 }
564
565 portNum = portNum + strlen("AT+DM_REGISTER_PORT_NUM=");
566 sscanf(portNum, "%10[^,]", port);
567
568 /*È·È϶˿ںÅÊÇ·ñºÏ·¨*/
569 if (!strcmp(port, "6001") || !strcmp(port, "6002"))
570 {
571 dmControlInfo->portNum = atol(port);
572 sc_cfg_set(DM_PORT_NUM, port);
573 }
574 else /* ²»ºÏ·¨£¬¹¹Ôì´íÎóµÄport£¬ 0 < port < 65535*/
575 {
576 dmControlInfo->portNum = 65539;
577 sc_cfg_set(DM_PORT_NUM, "65539");
578 }
579
580 log_debug("dm set server portNum config now: server-portNum(%d)\n", dmControlInfo->portNum);
581 return DM_ERR_SUCCESS;
582}
583
584/**
585 * º¯ÊýÃû³Æ£ºdm_set_server_domain_config
586 * ¹¦ÄÜÃèÊö£º×¢²áµÄ·þÎñÆ÷µØÖ·ÓòÃûÅäÖÃ(ÓÉcp²à¹¤³ÌÃüÁî´¥·¢)
587 * ²ÎÊý˵Ã÷£º
588 * ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
589 * ÆäËü˵Ã÷£º
590 */
591static int dm_server_domain_config_set(MSG_BUF *pstMsg, struct DM_CONTROl_INFO *dmControlInfo)
592{
593 CHECK_PARAM(pstMsg);
594 CHECK_PARAM(dmControlInfo);
595
596 char *msgData = (char *) pstMsg->aucDataBuf;
597 char *server = NULL;
598
599 if (!(server = strstr(msgData, "AT+DM_REGISTER_SERVER=")))
600 {
601 log_err("dm server domain set error\n");
602 return DM_ERR_SET_DOMAIN_ERR;
603 }
604
605 memset(dmControlInfo->hostName, 0, DM_INFO_MAX_SIZE);
606 server = server + strlen("AT+DM_REGISTER_SERVER=");
607 sscanf(server, "%32[^,]", dmControlInfo->hostName);
608
609 sc_cfg_set(DM_HOST_NAME, dmControlInfo->hostName);
610
611 log_debug("dm set server domain config now: server-domain(%s)\n", dmControlInfo->hostName);
612 return DM_ERR_SUCCESS;
613}
614
615/**
616 * º¯ÊýÃû³Æ£ºdm_clean_register_flag
617 * ¹¦ÄÜÃèÊö£ºÉèÖÃ×¢²áÿÂÖµÄʱ¼ä ¼ä¸ô£¬(ÓÉcp²àµÄ¹¤³ÌÃüÁî´¥·¢)
618 * ²ÎÊý˵Ã÷£º
619 * ·µ »Ø Öµ£º ³É¹¦ 0: ʧ°Ü ´íÎóÂë
620 * ÆäËü˵Ã÷£º
621 */
622static int dm_time_every_round_set(MSG_BUF *pstMsg, struct DM_CONTROl_INFO *dmControlInfo)
623{
624 CHECK_PARAM(pstMsg);
625 CHECK_PARAM(dmControlInfo);
626
627 char *msgData = (char *) pstMsg->aucDataBuf;
628 char *time = NULL;
629 char timeValue[12] = {0};
630
631 if (!(time = strstr(msgData, "AT+DM_REGISTER_SECS_ROUND=")))
632 {
633 log_err("dm set time evry round error\n");
634 return DM_ERR_SET_TIME_ROUND_ERROR;
635 }
636
637 time = time + strlen("AT+DM_REGISTER_SECS_ROUND=");
638
639 sscanf(time, "%10[^,]", timeValue);
640 dmControlInfo->secsEveryRound = atoi(timeValue);
641 sc_cfg_set(DM_SECS_EVERY_ROUND, timeValue);
642
643 log_debug("dm every round set now, timeValue(%s)", timeValue);
644 return DM_ERR_SUCCESS;
645}
646
647
648/**
649 * º¯ÊýÃû³Æ£ºdm_rtc_timer_del
650 * ¹¦ÄÜÃèÊö£ºÉ¾³ýËùÓеĶ¨Ê±Æ÷
651 * ²ÎÊý˵Ã÷£º
652 * ·µ »Ø Öµ£ºÎÞ
653 * ÆäËü˵Ã÷£º
654 */
655static void dm_rtc_timer_del(void)
656{
657 int index = 0;
658 int ret = 0;
659 for (index = DM_TIMER_ID_UNICOM_START; index < DM_TIMER_ID_MAX; index++)
660 {
661 ret = rtc_timer_del(index, MODULE_ID_DMREG);
662 log_debug("del rtc id(%d), ret(%d)\n", index, ret);
663 }
664}
665
666/**
667 * º¯ÊýÃû³Æ£ºdm_clean_register_flag
668 * ¹¦ÄÜÃèÊö£ºÇå³ý×¢²áµÄ״̬±ê¼Ç£¬±íÃ÷É豸ûÓÐ×¢²á(CP ²à¹¤³ÌÃüÁî´¥·¢)
669 * ²ÎÊý˵Ã÷£º
670 * ·µ »Ø Öµ£º ÎÞ
671 * ÆäËü˵Ã÷£º
672 */
673static void dm_register_flag_clean(struct DM_CONTROl_INFO *dmControlInfo)
674{
675 sc_cfg_set(DM_REGISTER_FLAG, "0");
676 sc_cfg_set(DM_REGISTERED_ROUND, "0");
677 dmControlInfo->currentRounds = 0;
678 dmControlInfo->currentTimes = 0;
679 dmControlInfo->registeredRounds = 0;
680 dmControlInfo->registerFlag = 0;
681
682 if (DM_MOBILE == dmControlInfo->dmType)
683 {
684 sc_cfg_set(DM_IMEI_PREVIOUS, "0");
685 sc_cfg_set(DM_ICCID_PREVIOUS, "0");
686 sc_cfg_set(DM_VERSION_PREVIOU, "");
687 }
688
689 /*ɾ³ýËùÓеĶ¨Ê±Æ÷*/
690 dm_rtc_timer_del();
691
692 dm_register_thread_release(dmControlInfo);
693 log_debug("dm register flag clean now: \n");
694}
695
696#if 0 /*±£ÁôΪºóÐøÀ©Õ¹*/
697/**
698 * º¯ÊýÃû³Æ£ºdm_msg_request_info_send
699 * ¹¦ÄÜÃèÊö£ºÇëÇóbl²ã¸üÐÂNVÐÅÏ¢£¬
700 * ²ÎÊý˵Ã÷£º
701 * ·µ »Ø Öµ£º
702 * ÆäËü˵Ã÷£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
703 */
704static long dm_msg_request_info_send(unsigned short targetId, unsigned short msgCmd, unsigned short dataLen, unsigned char *data, int flag)
705{
706 /* ctm MODULE_ID_AT_CTL */
707 long ret = 0;
708 if (0 != (ret = ipc_send_message(MODULE_ID_DMREG, targetId, msgCmd, dataLen, data, flag)))
709 return DM_ERR_IPC_SEND_MESSAGE_ERROR;
710 log_debug("dm msg request send now: targetId(0x%04x), msgCmd(0x%08x), dataLen(%d)\n", targetId, msgCmd, dataLen);
711 return DM_ERR_SUCCESS;
712}
713#endif
714
715/**
716* º¯ÊýÃû³Æ£ºdm_register_msg_send
717* ¹¦ÄÜÃèÊö£º·¢ËÍ×¢²áÏûÏ¢µ½×¢²áÏß³Ì,·¢Æð×¢²áÁ÷³Ì
718* ²ÎÊý˵Ã÷£º
719* ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
720* ÆäËü˵Ã÷£º
721*/
722static int dm_register_msg_send(struct DM_CONTROl_INFO *dmControlInfo)
723{
724 CHECK_PARAM(dmControlInfo);
725 int ret = 0;
726 long size = 0;
727 MSG_BUF msgBuf = {0};
728
729 msgBuf.usMsgCmd = DM_MSG_CMD_REGISTER_REQUEST;
730 size = sizeof(MSG_BUF) - sizeof(long);
731
732 msgBuf.ulMagic = MSG_MAGIC_WORD;
733 msgBuf.lMsgType = MSG_TYPE_DEFAULT;
734
735 /* ·¢ËÍÏûÏ¢µ½ ×¢²áÏß³Ì ·¢Æð×¢²áÁ÷³Ì */
736 ret = msgsnd(dmControlInfo->msgQueueIdReg, (void*) & (msgBuf), size, 0);
737 if (ret < 0)
738 {
739 log_err("unicom startup proc send msg errro \n");
740 return DM_ERR_QUEUE_SEND_ERROR;
741 }
742
743 return DM_ERR_SUCCESS;
744}
745
746/**
747* º¯ÊýÃû³Æ£º dm_mobile_register_start
748* ¹¦ÄÜÃèÊö£º ÒÆ¶¯DM×¢²áÁ÷³Ì¿ªÊ¼
749* ²ÎÊý˵Ã÷£º
750* ·µ »Ø Öµ£º ³É¹¦ 0: ʧ°Ü ´íÎóÂë
751* ÆäËü˵Ã÷£º
752*/
753static int dm_mobile_register_start(struct DM_CONTROl_INFO *dmControlInfo)
754{
755 char *dataBuf = NULL;
756 int dataSize = 0;
757 int ret = 0;
758 char imei[DM_NV_ITEM_SIZE] = {0};
759 char iccid[DM_NV_ITEM_SIZE] = {0};
760 char version[DM_NV_ITEM_SIZE] = {0};
761 DM_MOBILE_HTTPS_URL_INIO dmMobileUrlInfo = {{0}, {0}, {0}, 0, 0};
762 DM_MOBILE_HTTPS_DATA_INFO dmMobileHttpsDataInfo = {0};
763 struct DM_MOBILE_REGISTER_INFO dmMobileRegInfo ;
764
765 dataSize = (DM_NV_ITEM_SIZE + DM_NV_ITEM_SIZE / 4 + 5) * DM_INFO_MOBILE_MAX;
766
767 if (!(dataBuf = (char *) malloc(dataSize)))
768 {
769 log_err("dm unicom start reg malloc mem error\n");
770 return DM_ERR_PARAM_NULL;
771 }
772 memset(dataBuf, 0, dataSize);
773 dmMobileHttpsDataInfo.dataBuffer = dataBuf;
774 dmMobileHttpsDataInfo.dataLen = dataSize;
775
776 ret = dm_mobile_register_info_create(dmControlInfo, &dmMobileRegInfo);
777 if(DM_ERR_SUCCESS != ret)
778 {
779 goto ErrRet;
780 }
781 ret = dm_mobile_json_info_create(&dmMobileRegInfo, &dmMobileHttpsDataInfo);
782 if(DM_ERR_SUCCESS != ret)
783 {
784 goto ErrRet;
785 }
786 ret = dm_mobile_url_info_create(dmControlInfo, &dmMobileRegInfo, &dmMobileUrlInfo);
787 if(DM_ERR_SUCCESS != ret)
788 {
789 goto ErrRet;
790 } //klockworks issue.
791
792 ret = dm_mobile_https_request(&dmMobileUrlInfo, &dmMobileHttpsDataInfo);
793
794 if (0 == ret)
795 {
796 /*×¢²á³É¹¦£¬±£´æNV */
797 char buf[4] = {0};
798 dmControlInfo->registerFlag = DM_REGISTERED_YES;
799 snprintf(buf, 3, "%d", dmControlInfo->registerFlag);
800 sc_cfg_set("registerFlag", buf); //ctm
801
802 /*дÈëIMEI ICCID ºÅ*/
803 sc_cfg_get(NV_IMEI, imei, sizeof(imei));
804 sc_cfg_get(NV_ZICCID, iccid, sizeof(iccid));
805 sc_cfg_get(DM_SW_VERSION, version, sizeof(version));
806
807 sc_cfg_set(DM_IMEI_PREVIOUS, imei);
808 sc_cfg_set(DM_ICCID_PREVIOUS, iccid);
809
810 /*дÈë°æ±¾ºÅ£¬ÎªfotaÉý¼¶ºó DM ×¢²áµÄÒÀ¾Ý*/
811 sc_cfg_set(DM_VERSION_PREVIOU, version);
812
813 dm_resource_clean(dmControlInfo, (void *) &dmMobileHttpsDataInfo);
814 return DM_ERR_SUCCESS;
815 }
816
817 dm_resource_clean(dmControlInfo, &dmMobileHttpsDataInfo);
818 log_debug("dm start register start: debug info as following ************\n");
819 log_debug("dm currentTimes(%d)\n", dmControlInfo->currentTimes);
820 log_debug("dm register secTimer(%d), , secsEveryTime(%d), netStatus(%d), globalRomaing(%d)\n",
821 dmControlInfo->secTimer,
822 dmControlInfo->secsEveryTime,
823 dmControlInfo->netStatus,
824 dmControlInfo->globalRomaing);
825
826 return DM_ERR_RETRY_ERROR;
827
828ErrRet:
829 free(dataBuf);
830 return ret;
831}
832
833/**
834* º¯ÊýÃû³Æ£ºdm_register_request_handle
835* ¹¦ÄÜÃèÊö£ºÒƶ¯dm ×¢²áÇëÇó´¦Àí
836* ²ÎÊý˵Ã÷£º
837* ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
838* ÆäËü˵Ã÷£º
839*/
840static int dm_mobile_register_request_handle(struct DM_CONTROl_INFO *dmControlInfo)
841{
842 CHECK_PARAM(dmControlInfo);
843
844 int ret = 0;
845 int checkTimes = 10;
846 char romaingStatus[DM_NV_ITEM_SIZE] = {0};
847 char netStatus[DM_NV_ITEM_SIZE] = {0};
848
849 /*»ñÈ¡ ״ֵ̬*/
850 CALL(sc_cfg_get(NV_PDP_STATUS, netStatus, sizeof(netStatus)));
851 CALL(sc_cfg_get(NV_SIMCARD_ROAM, romaingStatus, sizeof(romaingStatus)));
852 dmControlInfo->netStatus = atoi(netStatus);
853
854 if (0 == strcmp(romaingStatus, "Internal"))
855 {
856 dmControlInfo->globalRomaing = 1;
857 }
858 else if (0 == strcmp(romaingStatus, "Home"))
859 {
860 dmControlInfo->globalRomaing = 0;
861 }
862 else
863 {
864 log_err("dm global romaing some error, romaingStatus(%s) \n ", romaingStatus);
865 return DM_ERR_WAITING_NET_STATUS_CHANAGE;
866 }
867
868 if (dmControlInfo->currentTimes >= 10)
869 {
870 log_debug("dm mobile register 10 times now...");
871 return DM_ERR_MOBILE_OVER_RETRY_TMIES_ERROR;
872 }
873
874 /* 1¡¢Êý¾ÝÁ´Â·¹Ø±Õ£¬»ò
875 * 2¡¢Êý¾ÝÁ´Â·´ò¿ª£¬ÇÒÔÚ¹ú¼ÊÂþÓÎ
876 */
877 if (dmControlInfo->netStatus == 0 || (dmControlInfo->netStatus == 1 && dmControlInfo->globalRomaing == 1))
878 {
879 /*ÒÆ¶¯µÄ¹æ·¶ÖÐ˵Ã÷£¬´Ë´ÎÒ²¼ÆÈë³¢ÊÔ´ÎÊýÖÐ */
880 dmControlInfo->currentTimes++;
881
882 if (dmControlInfo->currentTimes < 10)
883 {
884 /*1¡¢Óû§Í¨¹ý¹¤³ÌÃüÁîÉèÖà ·½±ã²âÊÔÈËÔ±½øÐвâÊÔ£¬´ËÖµ´úÌæÐ­Ò鹿¶¨µÄÕæÊµµÄ´Î¼ä¸ôʱ¼ä£¬Ëõ¶Ì²âÊÔʱ¼ä
885 *2¡¢Ä¬ÈÏÖµ0,±íʾʹÓÃÕæÊµµÄ´Î¼ä¸ôʱ¼ä£¬·Ç0 ±íʾʹÓôËÉèÖõÄÖµ´úÌæ*/
886 if (0 != dmControlInfo->secsEveryRound)
887 {
888 dmControlInfo->secsEveryTime = dmControlInfo->secsEveryRound;
889 }
890 else
891 {
892 dmControlInfo->secsEveryTime = dmControlInfo->currentTimes * 10;
893 }
894
895 dm_timer_add(dmControlInfo->secsEveryTime * 60, DM_TIMER_ID_MOBILE_EVERY_TIMES);
896 }
897
898 log_debug(" startup_proc now, net status(%d), globalRomaing(%d), currentTimes(%d)\n", dmControlInfo->netStatus, dmControlInfo->globalRomaing, dmControlInfo->currentTimes);
899 return DM_ERR_WAITING_NET_STATUS_CHANAGE;
900 }
901
902 while (checkTimes-- > 0)
903 {
904 if (1 == default_route_check())
905 break;
906 usleep(1000 * 500);
907 log_debug("mobile startup check rout times(%d)\n", checkTimes);
908 if (checkTimes == 0)
909 {
910 log_err("dm net some error occur\n");
911 return DM_ERR_CHECK_ROUTE_ERROR;
912 }
913 }
914
915 dmControlInfo->currentTimes++; /*´ÎÊý½øÐмÆÊý */
916 /*·¢Æðhttp´«Êä¼ÓÃܵÈÁ÷³Ì */
917 if (DM_ERR_SUCCESS != (ret = dm_mobile_register_start(dmControlInfo)))
918 {
919 /* ³¢ÊÔ×¢²áµÄ´ÎÊýСÓÚ 10 ´Îʱ£¬¼ÌÐø³¢ÊÔ */
920 if (dmControlInfo->currentTimes < 10)
921 {
922 /*1¡¢dmControlInfo->secsEveryRound Óû§Í¨¹ý¹¤³ÌÃüÁîÉèÖÃ,Ä¿µÄÊÇ·½±ã²âÊÔÈËÔ±½øÐвâÊÔ£¬
923 * ´ËÖµ´úÌæÐ­Ò鹿¶¨µÄÕæÊµµÄ´Î¼ä¸ôʱ¼ä£¬Ëõ¶Ì²âÊÔʱ¼ä£»
924 *2¡¢Ä¬ÈÏÖµ0,±íʾʹÓÃÕæÊµµÄ´Î¼ä¸ôʱ¼ä£¬·Ç0 ±íʾʹÓôËÉèÖõÄÖµ´úÌæ²âÊÔ */
925 if (0 != dmControlInfo->secsEveryRound)
926 {
927 dmControlInfo->secsEveryTime = dmControlInfo->secsEveryRound;
928 }
929 else
930 {
931 dmControlInfo->secsEveryTime = dmControlInfo->currentTimes * 10;
932 }
933 /* ʧ°ÜÆô¶¯Ã¿´Î³¢ÊÔ¶¨Ê±Æ÷ */
934 dm_timer_add(dmControlInfo->secsEveryTime * 60, DM_TIMER_ID_MOBILE_EVERY_TIMES);
935 }
936
937 log_debug("dm mobile register error, ret(%d), currentTimes(%d), next-rtc-time(%d)\n", ret, dmControlInfo->currentTimes, dmControlInfo->secsEveryTime);
938 return ret;
939 }
940
941 return DM_ERR_SUCCESS;
942}
943
944/**
945 * º¯ÊýÃû³Æ£º dm_mobile_url_info_create
946 * ¹¦ÄÜÃèÊö£º ¹¹ÔìÒÆ¶¯DMµÄ·þÎñÆ÷ urlÐÅÏ¢£¬°üÀ¨ ·þÎñÆ÷µØÖ·£¬¶Ë¿ÚµÈÐÅÏ¢£¬
947 * ²ÎÊý˵Ã÷£º
948 * ·µ »Ø Öµ£º ³É¹¦ 0: ʧ°Ü ´íÎóÂë
949 * ÆäËü˵Ã÷£º
950 */
951static int dm_mobile_url_info_create(struct DM_CONTROl_INFO *dmControlInfo, struct DM_MOBILE_REGISTER_INFO *dmMobileRegInfo, DM_MOBILE_HTTPS_URL_INIO *dmMobileUrlInfo)
952{
953 char mobileAppkey[DM_NV_ITEM_SIZE] = {0};
954 CHECK_PARAM(dmControlInfo);
955 CHECK_PARAM(dmMobileRegInfo);
956 CHECK_PARAM(dmMobileUrlInfo);
957 CHECK_PARAM(dmMobileUrlInfo->urlBuffer);
958
959 sc_cfg_get("appKeyMobile", mobileAppkey, DM_NV_ITEM_SIZE);
960
961 memset(dmMobileUrlInfo, 0, sizeof(DM_MOBILE_HTTPS_URL_INIO));
962 snprintf(dmMobileUrlInfo->urlBuffer, DM_HTTPS_HEAD_DATA_LENGTH - 1, "/accept/featureService?func=tsdk:postotherreg&appkey=%s", mobileAppkey);
963
964 snprintf(dmMobileUrlInfo->hostName, DM_NV_ITEM_SIZE - 1, "%s", dmControlInfo->hostName);
965
966 snprintf(dmMobileUrlInfo->ipAddr, 31, "%s", dmControlInfo->ipAddr);
967
968 dmMobileUrlInfo->portNum = dmControlInfo->portNum;
969
970 log_debug("dm unicom url-info debug: ulr(%s), portNum(%ld), hostName(%s)\n ", dmMobileUrlInfo->urlBuffer, dmMobileUrlInfo->portNum, dmMobileUrlInfo->hostName);
971
972 return DM_ERR_SUCCESS;
973}
974
975/**
976 * º¯ÊýÃû³Æ£ºdm_unicom_json_info_create
977 * ¹¦ÄÜÃèÊö£º¹¹ÔìÁªÍ¨Ð­Ò鹿·¶json¸ñʽÊý¾Ý
978 * ²ÎÊý˵Ã÷£º
979 * ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
980 * ÆäËü˵Ã÷£º
981 */
982static int dm_unicom_json_info_create(struct DM_UNICOM_REGISTER_INFO *dmUnicomRegInfo, DM_UNICOM_HTTP_DATA_INFO *httpsDataInfo)
983{
984 CHECK_PARAM(dmUnicomRegInfo);
985 CHECK_PARAM(httpsDataInfo);
986
987 int i = 0;
988 char *pTmep = NULL;
989 int jsonSize = 0;
990 char *unicomItemName[] = {"Manuf", "Model", "HWVersion", "SWVersion",
991 "OS", "OSVersion", "IMEI1", "ICCID1",
992 "IMSI1", "MSISDN1", "MNC1", "NCLS1",
993 "CellID1", "LAC1", "AccType", "Time", "Tag"
994 };
995 /*json fromat as following
996 * {"key1":"key1Value","key2":"key2Value", xxxxx}*/
997 log_debug("dm unicom json infof ***********\n");
998
999 pTmep = httpsDataInfo->dataBuffer;
1000 memset(pTmep, 0, httpsDataInfo->dataLen);
1001 for (i = 0; i < DM_INFO_UNICOM_MAX; i++)
1002 {
1003 if (i == 0)
1004 sprintf(pTmep, "{\"%s\":\"%s\"", unicomItemName[i], dmUnicomRegInfo->value[i]);
1005 else if (i == DM_INFO_UNICOM_MAX - 1)
1006 sprintf(pTmep, ",\"%s\":\"%s\"}", unicomItemName[i], dmUnicomRegInfo->value[i]);
1007 else
1008 sprintf(pTmep, ",\"%s\":\"%s\"", unicomItemName[i], dmUnicomRegInfo->value[i]);
1009
1010 log_debug("json-value(%s)\n", pTmep);
1011 jsonSize = jsonSize + strlen(pTmep);
1012 pTmep = pTmep + strlen(pTmep);
1013
1014 if (jsonSize > httpsDataInfo->dataLen)
1015 log_err("json buffer memory overwrite now! please check memory size, jsonSize(%d), httpsDatainfo-size(%d) !!!\n", jsonSize, httpsDataInfo->dataLen);
1016 }
1017
1018 httpsDataInfo->dataLen = jsonSize;
1019 log_debug("create json info, json-szie(%d)\n", jsonSize);
1020
1021 return DM_ERR_SUCCESS;
1022}
1023
1024
1025/**
1026 * º¯ÊýÃû³Æ£ºdm_mobile_json_info_create
1027 * ¹¦ÄÜÃèÊö£º¹¹ÔìÒÆ¶¯Ð­Ò鹿·¶json¸ñʽÊý¾Ý
1028 * ²ÎÊý˵Ã÷£º
1029 * ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
1030 * ÆäËü˵Ã÷£º
1031 */
1032static int dm_mobile_json_info_create(struct DM_MOBILE_REGISTER_INFO *dmMobileRegInfo, DM_MOBILE_HTTPS_DATA_INFO *httpsDataInfo)
1033{
1034 CHECK_PARAM(dmMobileRegInfo);
1035 CHECK_PARAM(httpsDataInfo);
1036 CHECK_PARAM(httpsDataInfo->dataBuffer);
1037 int i = 0;
1038 char *pTmep = NULL;
1039 int jsonSize = 0;
1040
1041 /*Áªµ÷¹æ·¶Êý¾Ý£¬¶¨Öµ */
1042 char *mobileItemName[] = {"sdkVersion", "imei1", "imei2", "meid", "deviceId", "brand",
1043 "model", "firmwareVer", "systemVer", "cpu", "rom", "ram", "type", "iccid1", "iccid2", "imsi1", "imsi2",
1044 "mac", "cellId", "lac", "channel", "dataCard", "masterStatus", "sendTime", "soltQuantity",
1045 "dataCard2", "soltService1", "soltService2", "soltNetwork1", "soltNetwork2", "lac2", "cellId2", "Intype"
1046 };
1047
1048 log_debug("dm mobile json infof ***********\n");
1049 pTmep = httpsDataInfo->dataBuffer;
1050 memset(pTmep, 0, httpsDataInfo->dataLen);
1051 for (i = 0; i < DM_INFO_MOBILE_MAX; i++)
1052 {
1053 if (i == 0)
1054 sprintf(pTmep, "{\"%s\":\"%s\"", mobileItemName[i], dmMobileRegInfo->value[i]);
1055 else if (i == DM_INFO_MOBILE_MAX - 1)
1056 sprintf(pTmep, ",\"%s\":\"%s\"}", mobileItemName[i], dmMobileRegInfo->value[i]);
1057 else
1058 sprintf(pTmep, ",\"%s\":\"%s\"", mobileItemName[i], dmMobileRegInfo->value[i]);
1059
1060 log_debug("json-value[%d](%s)\n", i, pTmep);
1061 jsonSize = jsonSize + strlen(pTmep);
1062 pTmep = pTmep + strlen(pTmep);
1063
1064 if (jsonSize > httpsDataInfo->dataLen)
1065 {
1066 log_err("json buffer memory overwrite now! please check memory size, jsonSize(%d), httpsDatainfo-size(%d) !!!\n", jsonSize, httpsDataInfo->dataLen);
1067 return DM_ERR_CREATE_JSON_INFO_ERROR;
1068 }
1069 }
1070
1071 httpsDataInfo->dataLen = jsonSize;
1072 log_debug("json-szie(%d)\n", jsonSize);
1073
1074 return DM_ERR_SUCCESS;
1075}
1076
1077/**
1078 * º¯ÊýÃû³Æ£ºdm_set_register_tag
1079 * ¹¦ÄÜÃèÊö£ºÁªÍ¨DMµÄЭÒéTagÖµÉèÖÃ
1080 * ²ÎÊý˵Ã÷£º
1081 * ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
1082 * ÆäËü˵Ã÷£º
1083 */
1084static void dm_register_tag_set(struct DM_CONTROl_INFO *dmControlInfo, struct DM_UNICOM_REGISTER_INFO *dmUnicomRegInfo)
1085{
1086 snprintf(dmUnicomRegInfo->value[DM_INFO_TAG], 63, "%d,%d,%d", dmControlInfo->registeredRounds, dmControlInfo->currentRounds, dmControlInfo->currentTimes);
1087}
1088
1089/**
1090 * º¯ÊýÃû³Æ£ºdm_register_time_set
1091 * ¹¦ÄÜÃèÊö£ºDMЭÒé¸ñʽ¹æ¶¨µÄʱ¼ä¸ñʽÉèÖÃ
1092 * ²ÎÊý˵Ã÷£º
1093 * ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
1094 * ÆäËü˵Ã÷£º
1095 */
1096static int dm_register_time_set(struct DM_CONTROl_INFO *dmControlInfo, void *dataInfo)
1097{
1098 CHECK_PARAM(dataInfo);
1099 char timeBuf[DM_NV_ITEM_SIZE] = {0};
1100 struct DM_MOBILE_REGISTER_INFO *dmMobileRegInfo = NULL;
1101 struct DM_UNICOM_REGISTER_INFO *dmUnicomRegInfo = NULL;
1102 time_t t = {0};
1103 struct tm *area = NULL;
1104
1105 t = time(NULL);
1106 area = (struct tm *) localtime(&t);
1107
1108 if (!area)
1109 {
1110 log_err("dm set register time error\n");
1111 return DM_ERR_PARAM_NULL;
1112 }
1113 strftime(timeBuf, 63, "%Y-%m-%d %H:%M:%S", area);
1114
1115 if (DM_UNICOM == dmControlInfo->dmType)
1116 {
1117 dmUnicomRegInfo = (struct DM_UNICOM_REGISTER_INFO *) dataInfo;
1118 snprintf(dmUnicomRegInfo->value[DM_INFO_TIME], DM_NV_ITEM_SIZE - 1, "%s", timeBuf);
1119 }
1120
1121 if (DM_MOBILE == dmControlInfo->dmType)
1122 {
1123 dmMobileRegInfo = (struct DM_MOBILE_REGISTER_INFO *) dataInfo;
1124 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_SEND_TIME], DM_NV_ITEM_SIZE - 1, "%s", timeBuf);
1125 }
1126 return DM_ERR_SUCCESS;
1127}
1128
1129/**
1130 * º¯ÊýÃû³Æ£ºdm_unicom_register_info_create
1131 * ¹¦ÄÜÃèÊö: ¹¹ÔìÁªÍ¨DMЭÒ鹿·¶Ö¸¶¨µÄ×¢²áÐÅÏ¢
1132 * ²ÎÊý˵Ã÷£º
1133 * ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
1134 * ÆäËü˵Ã÷£º
1135 */
1136static int dm_unicom_register_info_create(struct DM_CONTROl_INFO *dmControlInfo, struct DM_UNICOM_REGISTER_INFO *dmUnicomRegInfo)
1137{
1138 CHECK_PARAM(dmUnicomRegInfo);
1139 char mmc[DM_NV_ITEM_SIZE] = {0};
1140 char dmUnicomNvInfo[DM_NV_ITEM_SIZE] = {0};
1141 int index = 0;
1142
1143 memset(dmUnicomRegInfo, 0, sizeof(struct DM_UNICOM_REGISTER_INFO));
1144
1145#ifndef DM_TEST_DEBUG
1146 /*³§ÉÌÐͺÅ*/
1147 CALL(sc_cfg_get(DM_MANUF, dmUnicomNvInfo, DM_NV_ITEM_SIZE));
1148 snprintf(dmUnicomRegInfo->value[DM_INFO_MANUF], DM_NV_ITEM_SIZE - 1, "%s", dmUnicomNvInfo);
1149
1150 /*³§ÉÌ´úÂë*/
1151 memset(dmUnicomNvInfo, 0, DM_NV_ITEM_SIZE);
1152 CALL(sc_cfg_get(DM_MODEL, dmUnicomNvInfo, DM_NV_ITEM_SIZE));
1153 snprintf(dmUnicomRegInfo->value[DM_INFO_MODEL], DM_NV_ITEM_SIZE - 1, "%s", dmUnicomNvInfo);
1154
1155 /*Ó²¼þ°æ±¾ºÅ*/
1156 memset(dmUnicomNvInfo, 0, DM_NV_ITEM_SIZE);
1157 CALL(sc_cfg_get(NV_HW_VERSION, dmUnicomNvInfo, DM_NV_ITEM_SIZE));
1158 snprintf(dmUnicomRegInfo->value[DM_INFO_HWVISION], DM_NV_ITEM_SIZE - 1, "%s", dmUnicomNvInfo);
1159
1160 /*Èí¼þ°æ±¾ºÅ*/
1161 memset(dmUnicomNvInfo, 0, DM_NV_ITEM_SIZE);
1162 CALL(sc_cfg_get(NV_WA_VERSION, dmUnicomNvInfo, DM_NV_ITEM_SIZE));
1163 snprintf(dmUnicomRegInfo->value[DM_INFO_SWVERSION], DM_NV_ITEM_SIZE - 1, "%s", dmUnicomNvInfo);
1164
1165 snprintf(dmUnicomRegInfo->value[DM_INFO_OS], DM_NV_ITEM_SIZE - 1, "%s", "TOS");
1166
1167 snprintf(dmUnicomRegInfo->value[DM_INFO_OSVISION], DM_NV_ITEM_SIZE - 1, "%s", "1.0");
1168
1169 memset(dmUnicomNvInfo, 0, DM_NV_ITEM_SIZE);
1170 CALL(sc_cfg_get(NV_IMEI, dmUnicomNvInfo, DM_NV_ITEM_SIZE));
1171 snprintf(dmUnicomRegInfo->value[DM_INFO_IMEI1], DM_NV_ITEM_SIZE - 1, "%s", dmUnicomNvInfo);
1172
1173 memset(dmUnicomNvInfo, 0, DM_NV_ITEM_SIZE);
1174 CALL(sc_cfg_get(NV_MCC, dmUnicomNvInfo, DM_NV_ITEM_SIZE));
1175 CALL(sc_cfg_get(NV_MNC, mmc, DM_NV_ITEM_SIZE));
1176 snprintf(dmUnicomRegInfo->value[DM_INFO_MNC1], DM_NV_ITEM_SIZE - 1, "%s%s", dmUnicomNvInfo, mmc);
1177
1178 /*ÍøÂçÀàÐÍ LTE, WCDMA, GSM, TD-CDMA, ÁªÍ¨ÐèÒª´óÖÆÊ½ */
1179 memset(dmUnicomNvInfo, 0, DM_NV_ITEM_SIZE);
1180 CALL(sc_cfg_get(NV_NETWORK_TYPE, dmUnicomNvInfo, DM_NV_ITEM_SIZE));
1181 if (!strcmp(dmUnicomNvInfo, "GPRS")) /* ЭÒ鹿·¶ GPRS->GSM */
1182 {
1183 snprintf(dmUnicomRegInfo->value[DM_INFO_NCLS1], DM_NV_ITEM_SIZE - 1, "%s", "GSM");
1184 }
1185 else
1186 {
1187 snprintf(dmUnicomRegInfo->value[DM_INFO_NCLS1], DM_NV_ITEM_SIZE - 1, "%s", dmUnicomNvInfo);
1188 }
1189
1190 if (1 == dmControlInfo->cardType) /* ÒÆ¶¯¿¨ ,ЭÒ鹿·¶Ö¸¶¨ Ϊ 1*/
1191 {
1192 snprintf(dmUnicomRegInfo->value[DM_INFO_ICCID1], DM_NV_ITEM_SIZE - 1, "%s", "11111111111111111111");
1193 snprintf(dmUnicomRegInfo->value[DM_INFO_IMSI1], DM_NV_ITEM_SIZE - 1, "%s", "111111111111111");
1194 snprintf(dmUnicomRegInfo->value[DM_INFO_MSISDN1], DM_NV_ITEM_SIZE - 1, "%s", "11111111111");
1195 snprintf(dmUnicomRegInfo->value[DM_INFO_CELLID1], DM_NV_ITEM_SIZE - 1, "%s", "1111");
1196 snprintf(dmUnicomRegInfo->value[DM_INFO_LAC1], DM_NV_ITEM_SIZE - 1, "%s", "1111");
1197
1198 }
1199 else if (3 == dmControlInfo->cardType) /*µçÐÅ¿¨£¬Ð­Ò鹿·¶Ö¸¶¨Îª 3*/
1200 {
1201 snprintf(dmUnicomRegInfo->value[DM_INFO_ICCID1], DM_NV_ITEM_SIZE - 1, "%s", "33333333333333333333");
1202 snprintf(dmUnicomRegInfo->value[DM_INFO_IMSI1], DM_NV_ITEM_SIZE - 1, "%s", "333333333333333");
1203 snprintf(dmUnicomRegInfo->value[DM_INFO_MSISDN1], DM_NV_ITEM_SIZE - 1, "%s", "33333333333");
1204 snprintf(dmUnicomRegInfo->value[DM_INFO_CELLID1], DM_NV_ITEM_SIZE - 1, "%s", "3333");
1205 snprintf(dmUnicomRegInfo->value[DM_INFO_LAC1], DM_NV_ITEM_SIZE - 1, "%s", "3333");
1206
1207 }
1208 else if (2 == dmControlInfo->cardType)
1209 {
1210 memset(dmUnicomNvInfo, 0, DM_NV_ITEM_SIZE);
1211 CALL(sc_cfg_get(NV_ZICCID, dmUnicomNvInfo, DM_NV_ITEM_SIZE));
1212 snprintf(dmUnicomRegInfo->value[DM_INFO_ICCID1], DM_NV_ITEM_SIZE - 1, "%s", dmUnicomNvInfo);
1213
1214 memset(dmUnicomNvInfo, 0, DM_NV_ITEM_SIZE);
1215 CALL(sc_cfg_get(NV_MSISDN, dmUnicomNvInfo, DM_NV_ITEM_SIZE));
1216 snprintf(dmUnicomRegInfo->value[DM_INFO_MSISDN1], DM_NV_ITEM_SIZE - 1, "%s", dmUnicomNvInfo);
1217
1218 memset(dmUnicomNvInfo, 0, DM_NV_ITEM_SIZE);
1219 CALL(sc_cfg_get(NV_SIM_IMSI, dmUnicomNvInfo, DM_NV_ITEM_SIZE));
1220 snprintf(dmUnicomRegInfo->value[DM_INFO_IMSI1], DM_NV_ITEM_SIZE - 1, "%s", dmUnicomNvInfo);
1221
1222 /*Ð¡ÇøÎ»ÖÃÐÅÏ¢1 */
1223 memset(dmUnicomNvInfo, 0, DM_NV_ITEM_SIZE);
1224 CALL(sc_cfg_get(NV_CELL_ID, dmUnicomNvInfo, DM_NV_ITEM_SIZE));
1225 snprintf(dmUnicomRegInfo->value[DM_INFO_CELLID1], DM_NV_ITEM_SIZE - 1, "%s", dmUnicomNvInfo);
1226
1227 /*Ð¡ÇøÎ»ÖÃÐÅÏ¢2 */
1228 memset(dmUnicomNvInfo, 0, DM_NV_ITEM_SIZE);
1229 sc_cfg_get(NV_NETWORK_TYPE, dmUnicomNvInfo, DM_NV_ITEM_SIZE);
1230 if (!strcmp(dmUnicomNvInfo, "LTE")) /* 4GÍøÂç */
1231 {
1232 memset(dmUnicomNvInfo, 0, DM_NV_ITEM_SIZE);
1233 sc_cfg_get(NV_TAC_CODE, dmUnicomNvInfo, DM_NV_ITEM_SIZE);
1234 snprintf(dmUnicomRegInfo->value[DM_INFO_LAC1], DM_NV_ITEM_SIZE - 1, "%s", dmUnicomNvInfo);
1235 }
1236 else /* ·Ç4GÍøÂç */
1237 {
1238 memset(dmUnicomNvInfo, 0, DM_NV_ITEM_SIZE);
1239 sc_cfg_get(NV_LAC_CODE, dmUnicomNvInfo, DM_NV_ITEM_SIZE);
1240 snprintf(dmUnicomRegInfo->value[DM_INFO_LAC1], DM_NV_ITEM_SIZE - 1, "%s", dmUnicomNvInfo);
1241 }
1242 }
1243 else
1244 {
1245 log_err("dm there is unknow card type\n");
1246 return DM_ERR_PARAM_NULL;
1247 }
1248#else // for test debug
1249 snprintf(dmUnicomRegInfo->value[DM_INFO_MANUF], DM_NV_ITEM_SIZE - 1, "%s", "BestSonny");
1250 snprintf(dmUnicomRegInfo->value[DM_INFO_MODEL], DM_NV_ITEM_SIZE - 1, "%s", "Best sonny LT589");
1251 snprintf(dmUnicomRegInfo->value[DM_INFO_HWVISION], DM_NV_ITEM_SIZE - 1, "%s", "K312-MB-V0.2A");
1252 snprintf(dmUnicomRegInfo->value[DM_INFO_SWVERSION], DM_NV_ITEM_SIZE - 1, "%s", "K312-HUASEN-BEST-SONNY-LT589-QVGA-SC-B10P02_170609_1700");
1253 snprintf(dmUnicomRegInfo->value[DM_INFO_OS], DM_NV_ITEM_SIZE - 1, "%s", "TOS");
1254 snprintf(dmUnicomRegInfo->value[DM_INFO_OSVISION], DM_NV_ITEM_SIZE - 1, "%s", "1.0");
1255 snprintf(dmUnicomRegInfo->value[DM_INFO_IMEI1], DM_NV_ITEM_SIZE - 1, "%s", "865062030001015");
1256 snprintf(dmUnicomRegInfo->value[DM_INFO_MNC1], DM_NV_ITEM_SIZE - 1, "%s", "46001");
1257 snprintf(dmUnicomRegInfo->value[DM_INFO_NCLS1], DM_NV_ITEM_SIZE - 1, "%s", "LTE");
1258
1259 if (1 == dmControlInfo->cardType) /*ÒÆ¶¯¿¨*/
1260 {
1261 snprintf(dmUnicomRegInfo->value[DM_INFO_ICCID1], DM_NV_ITEM_SIZE - 1, "%s", "11111111111111111111");
1262 snprintf(dmUnicomRegInfo->value[DM_INFO_IMSI1], DM_NV_ITEM_SIZE - 1, "%s", "111111111111111");
1263 snprintf(dmUnicomRegInfo->value[DM_INFO_MSISDN1], DM_NV_ITEM_SIZE - 1, "%s", "11111111111");
1264 snprintf(dmUnicomRegInfo->value[DM_INFO_CELLID1], DM_NV_ITEM_SIZE - 1, "%s", "1111");
1265 snprintf(dmUnicomRegInfo->value[DM_INFO_LAC1], DM_NV_ITEM_SIZE - 1, "%s", "1111");
1266
1267 }
1268 else if (3 == dmControlInfo->cardType) /*µçÐÅ¿¨*/
1269 {
1270 snprintf(dmUnicomRegInfo->value[DM_INFO_ICCID1], DM_NV_ITEM_SIZE - 1, "%s", "33333333333333333333");
1271 snprintf(dmUnicomRegInfo->value[DM_INFO_IMSI1], DM_NV_ITEM_SIZE - 1, "%s", "333333333333333");
1272 snprintf(dmUnicomRegInfo->value[DM_INFO_MSISDN1], DM_NV_ITEM_SIZE - 1, "%s", "33333333333");
1273 snprintf(dmUnicomRegInfo->value[DM_INFO_CELLID1], DM_NV_ITEM_SIZE - 1, "%s", "3333");
1274 snprintf(dmUnicomRegInfo->value[DM_INFO_LAC1], DM_NV_ITEM_SIZE - 1, "%s", "3333");
1275
1276 }
1277 else
1278 {
1279
1280 snprintf(dmUnicomRegInfo->value[DM_INFO_ICCID1], DM_NV_ITEM_SIZE - 1, "%s", "89860114834067295358");
1281 snprintf(dmUnicomRegInfo->value[DM_INFO_IMSI1], DM_NV_ITEM_SIZE - 1, "%s", "460011675515843");
1282 snprintf(dmUnicomRegInfo->value[DM_INFO_MSISDN1], DM_NV_ITEM_SIZE - 1, "%s", "18551770057");
1283 snprintf(dmUnicomRegInfo->value[DM_INFO_CELLID1], DM_NV_ITEM_SIZE - 1, "%s", "101387885");
1284 snprintf(dmUnicomRegInfo->value[DM_INFO_LAC1], DM_NV_ITEM_SIZE - 1, "%s", "53515");
1285 }
1286#endif
1287
1288 snprintf(dmUnicomRegInfo->value[DM_INFO_ACCTYPE], 10, "%s", "Mobile");
1289 CALL(dm_register_time_set(dmControlInfo, dmUnicomRegInfo));
1290 dm_register_tag_set(dmControlInfo, dmUnicomRegInfo);
1291
1292 log_debug("dm unicom get register from NV now ...\n");
1293 for (index = 0; index < DM_INFO_UNICOM_MAX; index++)
1294 {
1295 log_debug("Unicom info VALUE[%d] = %s\n", index, (dmUnicomRegInfo->value) [index]);
1296
1297 }
1298
1299 return DM_ERR_SUCCESS;
1300}
1301
1302/**
1303 * º¯ÊýÃû³Æ£ºdm_data_channel_set
1304 * ¹¦ÄÜÃèÊö£ºÒÀ¾ÝDMЭÒ鹿·¶£¬ÉèÖÃÊý¾ÝͨµÀÏî±ê¼Ç
1305 * ²ÎÊý˵Ã÷£º
1306 * ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
1307 * ÆäËü˵Ã÷£º
1308 */
1309static void dm_data_channel_set(struct DM_MOBILE_REGISTER_INFO *dmMobileRegInfo)
1310{
1311 char dmMobileNvInfo[DM_NV_ITEM_SIZE] = {0};
1312 memset(dmMobileNvInfo, 0, DM_NV_ITEM_SIZE);
1313 sc_cfg_get(NV_SUB_NETWORK_TYPE, dmMobileNvInfo, DM_NV_ITEM_SIZE);
1314
1315 if (strstr(dmMobileNvInfo, "GPRS"))
1316 {
1317 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_CHNL], DM_NV_ITEM_SIZE - 1, "%d", 1);
1318 }
1319 else if (strstr(dmMobileNvInfo, "EDGE"))
1320 {
1321 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_CHNL], DM_NV_ITEM_SIZE - 1, "%d", 2);
1322 }
1323 else if (strstr(dmMobileNvInfo, "UMTS"))
1324 {
1325 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_CHNL], DM_NV_ITEM_SIZE - 1, "%d", 3);
1326 }
1327 else if (strstr(dmMobileNvInfo, "CDMA"))
1328 {
1329 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_CHNL], DM_NV_ITEM_SIZE - 1, "%d", 4);
1330 }
1331 else if (strstr(dmMobileNvInfo, "EVDO_0"))
1332 {
1333 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_CHNL], DM_NV_ITEM_SIZE - 1, "%d", 5);
1334 }
1335 else if (strstr(dmMobileNvInfo, "EVDO_A"))
1336 {
1337 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_CHNL], DM_NV_ITEM_SIZE - 1, "%d", 6);
1338 }
1339 else if (strstr(dmMobileNvInfo, "HSDPA"))
1340 {
1341 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_CHNL], DM_NV_ITEM_SIZE - 1, "%d", 8);
1342 }
1343 else if (strstr(dmMobileNvInfo, "HSUPA"))
1344 {
1345 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_CHNL], DM_NV_ITEM_SIZE - 1, "%d", 9);
1346 }
1347 else if (strstr(dmMobileNvInfo, "HSPA"))
1348 {
1349 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_CHNL], DM_NV_ITEM_SIZE - 1, "%d", 10);
1350 }
1351 else if (strstr(dmMobileNvInfo, "IDEN"))
1352 {
1353 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_CHNL], DM_NV_ITEM_SIZE - 1, "%d", 11);
1354 }
1355 else if (strstr(dmMobileNvInfo, "EVDO_B"))
1356 {
1357 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_CHNL], DM_NV_ITEM_SIZE - 1, "%d", 12);
1358 }
1359 else if (strstr(dmMobileNvInfo, "LTE"))
1360 {
1361 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_CHNL], DM_NV_ITEM_SIZE - 1, "%d", 13);
1362 }
1363 else if (strstr(dmMobileNvInfo, "EHRPD"))
1364 {
1365 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_CHNL], DM_NV_ITEM_SIZE - 1, "%d", 14);
1366 }
1367 else if (strstr(dmMobileNvInfo, "HSPAP"))
1368 {
1369 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_CHNL], DM_NV_ITEM_SIZE - 1, "%d", 15);
1370 }
1371 else if (strstr(dmMobileNvInfo, "GSM"))
1372 {
1373 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_CHNL], DM_NV_ITEM_SIZE - 1, "%d", 16);
1374 }
1375 else if (strstr(dmMobileNvInfo, "TD-SCDMA"))
1376 {
1377 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_CHNL], DM_NV_ITEM_SIZE - 1, "%d", 17);
1378 }
1379 else
1380 {
1381 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_CHNL], DM_NV_ITEM_SIZE - 1, "%d", 0);
1382 log_debug("dm data channel set , unknow the network_type(%s)\n", dmMobileNvInfo);
1383 }
1384}
1385
1386/**
1387 * º¯ÊýÃû³Æ£ºdm_mobile_register_info_create
1388 * ¹¦ÄÜÃèÊö£º¹¹ÔìÒÆ¶¯Ð­Ò鹿·¶Ö¸¶¨µÄ×¢²áÐÅÏ¢
1389 * ²ÎÊý˵Ã÷£º
1390 * ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
1391 * ÆäËü˵Ã÷£º
1392 */
1393static int dm_mobile_register_info_create(struct DM_CONTROl_INFO *dmControlInfo, struct DM_MOBILE_REGISTER_INFO *dmMobileRegInfo)
1394{
1395 CHECK_PARAM(dmMobileRegInfo);
1396 char dmMobileNvInfo[DM_NV_ITEM_SIZE] = {0};
1397 int index = 0;
1398
1399 memset(dmMobileRegInfo, 0, sizeof(struct DM_MOBILE_REGISTER_INFO));
1400
1401#ifndef DM_TEST_DEBUG
1402 /*SDK °æ±¾*/
1403 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_SDKVERSION], DM_NV_ITEM_SIZE - 1, "%s", "1.0.1");
1404
1405 /*imei ºÅ*/
1406 memset(dmMobileNvInfo, 0, DM_NV_ITEM_SIZE);
1407 sc_cfg_get(NV_IMEI, dmMobileNvInfo, DM_NV_ITEM_SIZE);
1408 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_IMEI1], DM_NV_ITEM_SIZE - 1, "%s", dmMobileNvInfo);
1409
1410 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_IMEI2], DM_NV_ITEM_SIZE - 1, "%s", "unknow");
1411
1412 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_MEID], DM_NV_ITEM_SIZE - 1, "%s", "unknow");
1413
1414 /* ¹¦ÄÜ»úÎÞid ,ÓÃiemiºÅ´úÌæ */
1415 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_DEVICE_ID], DM_NV_ITEM_SIZE - 1, "%s", dmMobileRegInfo->value[DM_INFO_MOBILE_IMEI1]);
1416
1417 /*ÖÕ¶ËÆ·ÅÆ*/
1418 memset(dmMobileNvInfo, 0, DM_NV_ITEM_SIZE);
1419 sc_cfg_get(DM_BRAND, dmMobileNvInfo, DM_NV_ITEM_SIZE);
1420 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_BRAND], DM_NV_ITEM_SIZE - 1, "%s", dmMobileNvInfo);
1421
1422 /*ÖÕ¶ËÐͺÅ*/
1423 memset(dmMobileNvInfo, 0, DM_NV_ITEM_SIZE);
1424 sc_cfg_get(DM_MODEL, dmMobileNvInfo, DM_NV_ITEM_SIZE);
1425 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_MODEL], DM_NV_ITEM_SIZE - 1, "%s", dmMobileNvInfo);
1426
1427 /*Èí¼þ°æ±¾*/
1428 memset(dmMobileNvInfo, 0, DM_NV_ITEM_SIZE);
1429 sc_cfg_get(DM_SW_VERSION, dmMobileNvInfo, DM_NV_ITEM_SIZE);
1430 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_FIRMWARE_VERSION], DM_NV_ITEM_SIZE - 1, "%s", dmMobileNvInfo);
1431
1432 /*Èí¼þ°æ±¾ºÅ*/
1433 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_SYSTEM_VERSION], DM_NV_ITEM_SIZE - 1, "%s", "1.0");
1434
1435 /*ƽ̨CPUÐͺŠ*/
1436 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_CPU], DM_NV_ITEM_SIZE - 1, "%s", "ZX297520V3");
1437
1438 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_ROM], DM_NV_ITEM_SIZE - 1, "%s", "128MB");
1439
1440 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_RAM], DM_NV_ITEM_SIZE - 1, "%s", "128MB");
1441
1442 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_TYPE], DM_NV_ITEM_SIZE - 1, "%s", "1");
1443
1444 memset(dmMobileNvInfo, 0, DM_NV_ITEM_SIZE);
1445 sc_cfg_get(NV_ZICCID, dmMobileNvInfo, DM_NV_ITEM_SIZE);
1446 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_ICCID1], DM_NV_ITEM_SIZE - 1, "%s", dmMobileNvInfo);
1447
1448 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_ICCID2], DM_NV_ITEM_SIZE - 1, "%s", "unknow");
1449
1450 memset(dmMobileNvInfo, 0, DM_NV_ITEM_SIZE);
1451 sc_cfg_get(NV_SIM_IMSI, dmMobileNvInfo, DM_NV_ITEM_SIZE);
1452 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_IMSI1], DM_NV_ITEM_SIZE - 1, "%s", dmMobileNvInfo);
1453
1454 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_IMSI2], DM_NV_ITEM_SIZE - 1, "%s", "unknow");
1455
1456 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_MAC], DM_NV_ITEM_SIZE - 1, "%s", "unknow");
1457
1458 memset(dmMobileNvInfo, 0, DM_NV_ITEM_SIZE);
1459 sc_cfg_get(NV_CELL_ID, dmMobileNvInfo, DM_NV_ITEM_SIZE);
1460 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_CELLID], DM_NV_ITEM_SIZE - 1, "%s", dmMobileNvInfo);
1461
1462 memset(dmMobileNvInfo, 0, DM_NV_ITEM_SIZE);
1463 sc_cfg_get(NV_NETWORK_TYPE, dmMobileNvInfo, DM_NV_ITEM_SIZE);
1464 if (!strcmp(dmMobileNvInfo, "LTE")) /* 4GÍøÂç */
1465 {
1466 memset(dmMobileNvInfo, 0, DM_NV_ITEM_SIZE);
1467 sc_cfg_get(NV_TAC_CODE, dmMobileNvInfo, DM_NV_ITEM_SIZE);
1468 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_LAC], DM_NV_ITEM_SIZE - 1, "%s", dmMobileNvInfo);
1469 }
1470 else /* ·Ç4GÍøÂç */
1471 {
1472 memset(dmMobileNvInfo, 0, DM_NV_ITEM_SIZE);
1473 sc_cfg_get(NV_LAC_CODE, dmMobileNvInfo, DM_NV_ITEM_SIZE);
1474 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_LAC], DM_NV_ITEM_SIZE - 1, "%s", dmMobileNvInfo);
1475 }
1476
1477 /*ÍøÂçÊý¾ÝÀàÐÍ 4g 3G 2G*/
1478 dm_data_channel_set(dmMobileRegInfo);
1479
1480 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_DATA_CARD], DM_NV_ITEM_SIZE - 1, "%s", "2");
1481
1482 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_MASTER_STATUS], DM_NV_ITEM_SIZE - 1, "%s", "0");
1483
1484 /*ÉèÖÃÊý¾ÝͨµÀ*/
1485 CALL(dm_register_time_set(dmControlInfo, (void *) dmMobileRegInfo));
1486
1487 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_SLOT_QUANTITY], DM_NV_ITEM_SIZE - 1, "%s", "1");
1488
1489 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_DATA_CARD2], DM_NV_ITEM_SIZE - 1, "%s", "-1");
1490
1491 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_SLOT_SERVICE1], DM_NV_ITEM_SIZE - 1, "%s", "5");
1492
1493 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_SLOT_SERVICE2], DM_NV_ITEM_SIZE - 1, "%s", "unknow");
1494
1495 /* slot-network µÄÖµºÍÊý¾ÝͨµÀÖµÏàͬ(dmMobileRegInfo->value[DM_INFO_MOBILE_CHNL])*/
1496 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_SLOT_NETWORK1], DM_NV_ITEM_SIZE - 1, "%s", dmMobileRegInfo->value[DM_INFO_MOBILE_CHNL]);
1497
1498 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_SLOT_NETWORK2], DM_NV_ITEM_SIZE - 1, "%s", "unknow");
1499
1500 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_LAC2], DM_NV_ITEM_SIZE - 1, "%s", "unknow");
1501
1502 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_CELLID2], DM_NV_ITEM_SIZE - 1, "%s", "unknow");
1503
1504 memset(dmMobileNvInfo, 0, DM_NV_ITEM_SIZE);
1505 sc_cfg_get(DM_IN_TYPE, dmMobileNvInfo, DM_NV_ITEM_SIZE); /*ÈëÍøÐͺÅ*/
1506 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_TERMINAL_INTTYPE], DM_NV_ITEM_SIZE - 1, "%s", dmMobileNvInfo);
1507
1508 log_debug("dm mobile get register from NV now ...\n");
1509
1510 for (index = 0; index < DM_INFO_MOBILE_MAX; index++)
1511 {
1512 log_debug("Mobile info VALUE[%d] = %s\n", index, (dmMobileRegInfo->value) [index]);
1513 }
1514
1515#else
1516
1517 /*SDK °æ±¾*/
1518 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_SDKVERSION], DM_NV_ITEM_SIZE - 1, "%s", "1.0.1");
1519
1520 /*imei ºÅ*/
1521 memset(dmMobileNvInfo, 0, DM_NV_ITEM_SIZE);
1522 sc_cfg_get(NV_IMEI, dmMobileNvInfo, DM_NV_ITEM_SIZE);
1523 //snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_IMEI1], DM_NV_ITEM_SIZE - 1, "%s", dmMobileNvInfo);
1524 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_IMEI1], DM_NV_ITEM_SIZE - 1, "%s", "864023030000167");
1525
1526 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_IMEI2], DM_NV_ITEM_SIZE - 1, "%s", "unknow");
1527
1528 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_MEID], DM_NV_ITEM_SIZE - 1, "%s", "unknow");
1529
1530 /* ¹¦ÄÜ»úÎÞid ,ÓÃiemiºÅ´úÌæ */
1531 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_DEVICE_ID], DM_NV_ITEM_SIZE - 1, "%s", dmMobileRegInfo->value[DM_INFO_MOBILE_IMEI1]);
1532
1533 //memset(dmMobileNvInfo, 0, DM_NV_ITEM_SIZE);
1534 //sc_cfg_get(DM_BRAND, dmMobileNvInfo, DM_NV_ITEM_SIZE); // ÖÕ¶ËÆ·ÅÆ
1535 //snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_BRAND], DM_NV_ITEM_SIZE - 1, "%s", dmMobileNvInfo);
1536 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_BRAND], DM_NV_ITEM_SIZE - 1, "%s", "CFZZ");
1537
1538 //memset(dmMobileNvInfo, 0, DM_NV_ITEM_SIZE);
1539 //sc_cfg_get(DM_MODEL, dmMobileNvInfo, DM_NV_ITEM_SIZE); //ÖÕ¶ËÐͺÅ
1540 //snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_MODEL], DM_NV_ITEM_SIZE - 1, "%s", dmMobileNvInfo);
1541 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_MODEL], DM_NV_ITEM_SIZE - 1, "%s", "OK-W6");
1542
1543 memset(dmMobileNvInfo, 0, DM_NV_ITEM_SIZE);
1544 sc_cfg_get(DM_HW_VERSION, dmMobileNvInfo, DM_NV_ITEM_SIZE); // Ó²¼þ°æ±¾ºÅ
1545 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_FIRMWARE_VERSION], DM_NV_ITEM_SIZE - 1, "%s", dmMobileNvInfo);
1546
1547 /*Èí¼þ°æ±¾ºÅ*/
1548 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_SYSTEM_VERSION], DM_NV_ITEM_SIZE - 1, "%s", "1.0");
1549
1550 /*ƽ̨CPUÐͺŠ*/
1551 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_CPU], DM_NV_ITEM_SIZE - 1, "%s", "ZX297520V3");
1552
1553 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_ROM], DM_NV_ITEM_SIZE - 1, "%s", "128MB");
1554
1555 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_RAM], DM_NV_ITEM_SIZE - 1, "%s", "128MB");
1556
1557 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_TYPE], DM_NV_ITEM_SIZE - 1, "%s", "1");
1558
1559 //memset(dmMobileNvInfo, 0, DM_NV_ITEM_SIZE);
1560 //sc_cfg_get(NV_ZICCID, dmMobileNvInfo, DM_NV_ITEM_SIZE);
1561 //snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_ICCID1], DM_NV_ITEM_SIZE - 1, "%s", dmMobileNvInfo);
1562 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_ICCID1], DM_NV_ITEM_SIZE - 1, "%s", "89860065101750003921");
1563
1564 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_ICCID2], DM_NV_ITEM_SIZE - 1, "%s", "unknow");
1565
1566 memset(dmMobileNvInfo, 0, DM_NV_ITEM_SIZE);
1567 sc_cfg_get(NV_SIM_IMSI, dmMobileNvInfo, DM_NV_ITEM_SIZE);
1568 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_IMSI1], DM_NV_ITEM_SIZE - 1, "%s", dmMobileNvInfo);
1569
1570 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_IMSI2], DM_NV_ITEM_SIZE - 1, "%s", "unknow");
1571
1572 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_MAC], DM_NV_ITEM_SIZE - 1, "%s", "unknow");
1573
1574 memset(dmMobileNvInfo, 0, DM_NV_ITEM_SIZE);
1575 sc_cfg_get(NV_CELL_ID, dmMobileNvInfo, DM_NV_ITEM_SIZE);
1576 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_CELLID], DM_NV_ITEM_SIZE - 1, "%s", dmMobileNvInfo);
1577
1578 memset(dmMobileNvInfo, 0, DM_NV_ITEM_SIZE);
1579 sc_cfg_get(NV_LAC_CODE, dmMobileNvInfo, DM_NV_ITEM_SIZE);
1580 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_LAC], DM_NV_ITEM_SIZE - 1, "%s", dmMobileNvInfo);
1581
1582 /*ÍøÂçÊý¾ÝÀàÐÍ 4g 3G 2G*/
1583 dm_data_channel_set(dmMobileRegInfo);
1584
1585 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_DATA_CARD], DM_NV_ITEM_SIZE - 1, "%s", "2");
1586
1587 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_MASTER_STATUS], DM_NV_ITEM_SIZE - 1, "%s", "0");
1588
1589 CALL(dm_register_time_set(dmControlInfo, (void *) dmMobileRegInfo));
1590
1591 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_SLOT_QUANTITY], DM_NV_ITEM_SIZE - 1, "%s", "1");
1592
1593 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_DATA_CARD2], DM_NV_ITEM_SIZE - 1, "%s", "-1");
1594
1595 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_SLOT_SERVICE1], DM_NV_ITEM_SIZE - 1, "%s", "5");
1596
1597 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_SLOT_SERVICE2], DM_NV_ITEM_SIZE - 1, "%s", "unknow");
1598
1599 /* slot-network µÄÖµºÍÊý¾ÝͨµÀÖµÏàͬ(dmMobileRegInfo->value[DM_INFO_MOBILE_CHNL])*/
1600 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_SLOT_NETWORK1], DM_NV_ITEM_SIZE - 1, "%s", dmMobileRegInfo->value[DM_INFO_MOBILE_CHNL]);
1601
1602 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_SLOT_NETWORK2], DM_NV_ITEM_SIZE - 1, "%s", "unknow");
1603
1604 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_LAC2], DM_NV_ITEM_SIZE - 1, "%s", "unknow");
1605
1606 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_CELLID2], DM_NV_ITEM_SIZE - 1, "%s", "unknow");
1607
1608 //memset(dmMobileNvInfo, 0, DM_NV_ITEM_SIZE);
1609 //sc_cfg_get(DM_IN_TYPE, dmMobileNvInfo, DM_NV_ITEM_SIZE); /*ÈëÍøÐͺÅ*/
1610 //snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_TERMINAL_INTTYPE], DM_NV_ITEM_SIZE - 1, "%s", dmMobileNvInfo);
1611 snprintf(dmMobileRegInfo->value[DM_INFO_MOBILE_TERMINAL_INTTYPE], DM_NV_ITEM_SIZE - 1, "%s", "OK-W6");
1612
1613 log_debug("dm mobile get register from NV now ...\n");
1614
1615 for (index = 0; index < DM_INFO_MOBILE_MAX; index++)
1616 {
1617 log_debug("Mobile info VALUE[%d] = %s\n", index, (dmMobileRegInfo->value) [index]);
1618 }
1619#endif
1620 return DM_ERR_SUCCESS;
1621}
1622
1623/**
1624* º¯ÊýÃû³Æ£ºdm_unicom_url_info_create
1625* ¹¦ÄÜÃèÊö£º¹¹ÔìÁªÍ¨dm ulrÐÅÏ¢,°üÀ¨·þÎñÆ÷µØÖ·£¬¶Ë¿ÚºÅµÈ
1626* ²ÎÊý˵Ã÷£º
1627* ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
1628* ÆäËü˵Ã÷£º
1629*/
1630static int dm_unicom_url_info_create(struct DM_CONTROl_INFO *dmControlInfo, struct DM_UNICOM_REGISTER_INFO *dmUnicomRegInfo, DM_UNICOM_HTTP_URL_INFO *dmUnicomUrlInfo)
1631{
1632 int ret = 0;
1633 CHECK_PARAM(dmControlInfo);
1634 CHECK_PARAM(dmUnicomRegInfo);
1635 CHECK_PARAM(dmUnicomUrlInfo);
1636 CHECK_PARAM(dmUnicomUrlInfo->urlBuffer);
1637
1638 memset(dmUnicomUrlInfo, 0, sizeof(DM_UNICOM_HTTP_URL_INFO));
1639 ret = snprintf(dmUnicomUrlInfo->urlBuffer, URL_INFO_LINE_SIZE - 1, "http://%s:%ld/register?ver=1.1&model=%s&manuf=%s&sign=", dmControlInfo->hostName, dmControlInfo->portNum, & ((dmUnicomRegInfo->value) [DM_INFO_MODEL][0]), & ((dmUnicomRegInfo->value) [DM_INFO_MANUF][0]));
1640 if (ret <= 0)
1641 return DM_ERR_URL_INFO_CREATE_ERROR;
1642
1643 ret = snprintf(dmUnicomUrlInfo->hostName, DM_NV_ITEM_SIZE - 1, "%s", dmControlInfo->hostName);
1644 if (ret < 0)
1645 return DM_ERR_URL_INFO_CREATE_ERROR;
1646
1647 ret = snprintf(dmUnicomUrlInfo->ipAddr, 31, "%s", dmControlInfo->ipAddr);
1648 if (ret < 0)
1649 return DM_ERR_URL_INFO_CREATE_ERROR;
1650
1651 dmUnicomUrlInfo->portNum = dmControlInfo->portNum;
1652
1653 log_debug("dm unicom url-info debug: ulr(%s), portNum(%ld), hostName(%s)\n ", dmUnicomUrlInfo->urlBuffer, dmUnicomUrlInfo->portNum, dmUnicomUrlInfo->hostName);
1654 return DM_ERR_SUCCESS;
1655}
1656
1657
1658/**
1659* º¯ÊýÃû³Æ£ºdm_register_thread_release
1660* ¹¦ÄÜÃèÊö£ºÍ¨Öª×¢²áỊ̈߳¬Í˳öÏß³Ì
1661* ²ÎÊý˵Ã÷£º
1662* ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
1663* ÆäËü˵Ã÷£º²»ÄÜʹÓÃpthread_xxxÏà¹Øº¯ÊýÍ˳ö(ϵͳ˯ÃßËø´æÔÚ£¬Ðë±£Ö¤Åä¶ÔÖ´ÐÐÍê)
1664*/
1665static int dm_register_thread_release(struct DM_CONTROl_INFO *dmControlInfo)
1666{
1667 CHECK_PARAM(dmControlInfo);
1668 int ret = 0;
1669 long size = 0;
1670 MSG_BUF msgBuf = {0};
1671 msgBuf.usMsgCmd = DM_MSG_CMD_REGISTER_THREAD_RELEASE;
1672 size = sizeof(MSG_BUF) - sizeof(long);
1673 msgBuf.lMsgType = 1;
1674
1675 /* ·¢ËÍÏûÏ¢µ½ ×¢²áÏß³Ì ·¢Æð×¢²áÁ÷³Ì */
1676 ret = msgsnd(dmControlInfo->msgQueueIdReg, (void*) & (msgBuf), size, 0);
1677 if (ret < 0)
1678 {
1679 log_err("unicom thread release msg errro ret(%d) \n", ret);
1680 return DM_ERR_QUEUE_SEND_ERROR;
1681 }
1682
1683 return DM_ERR_SUCCESS;
1684}
1685
1686/**
1687* º¯ÊýÃû³Æ£ºdm_resource_clean
1688* ¹¦ÄÜÃèÊö£º×¢²áÍê³É£¬»ò³ö´í£¬ÄÚ´æµÄÊÍ·Å, ֪ͨÏß³ÌÍ˳ö
1689* ²ÎÊý˵Ã÷£º
1690* ·µ »Ø Öµ£ºÎÞ
1691* ÆäËü˵Ã÷£º
1692*/
1693static void dm_resource_clean(struct DM_CONTROl_INFO *dmControlInfo, void *dataInfo)
1694{
1695 DM_UNICOM_HTTP_DATA_INFO *dmUnicomHttpDataInfo = NULL;
1696 DM_MOBILE_HTTPS_DATA_INFO *dmMobileHttpsDataInfo = NULL;
1697
1698 if (DM_UNICOM == dmControlInfo->dmType)
1699 {
1700 dmUnicomHttpDataInfo = (DM_UNICOM_HTTP_DATA_INFO *) dataInfo;
1701 if (dmUnicomHttpDataInfo)
1702 {
1703 if (dmUnicomHttpDataInfo->dataBuffer)
1704 {
1705 free(dmUnicomHttpDataInfo->dataBuffer);
1706 dmUnicomHttpDataInfo->dataBuffer = NULL;
1707 dmUnicomHttpDataInfo->dataLen = 0;
1708 }
1709 }
1710 }
1711
1712 if (DM_MOBILE == dmControlInfo->dmType)
1713 {
1714 dmMobileHttpsDataInfo = (DM_MOBILE_HTTPS_DATA_INFO *) dataInfo;
1715 if (dmMobileHttpsDataInfo)
1716 {
1717 if (dmMobileHttpsDataInfo->dataBuffer)
1718 {
1719 free(dmMobileHttpsDataInfo->dataBuffer);
1720 dmMobileHttpsDataInfo->dataBuffer = NULL;
1721 dmMobileHttpsDataInfo->dataLen = 0;
1722 }
1723 }
1724 }
1725
1726 /*±£´æNV±ê¼Ç */
1727 if (DM_REGISTERED_YES == dmControlInfo->registerFlag)
1728 {
1729 char registerRounds[4] = {0};
1730 snprintf(registerRounds, 3, "%d", 0);
1731 sc_cfg_set(DM_REGISTERED_ROUND, registerRounds);
1732
1733 dm_rtc_timer_del();
1734 log_debug("dm register success now...\n");
1735 }
1736
1737 if ((DM_UNICOM == dmControlInfo->dmType) && (10 < dmControlInfo->registeredRounds || 3 < dmControlInfo->currentRounds))
1738 {
1739 dm_rtc_timer_del();
1740 log_debug("dm unicom have registered total registerRounds(%d) or rounds(%d) on starting up\n", dmControlInfo->registeredRounds, dmControlInfo->currentRounds);
1741 }
1742
1743 if ((DM_MOBILE == dmControlInfo->dmType) && (10 < dmControlInfo->currentTimes))
1744 {
1745 dm_rtc_timer_del();
1746 log_debug("dm unicom have registered total times(%d) on starting up\n", dmControlInfo->currentTimes);
1747 }
1748}
1749
1750/**
1751* º¯ÊýÃû³Æ£ºdm_unicom_register_start
1752* ¹¦ÄÜÃèÊö£ºÁªÍ¨DM×¢²áÁ÷³Ì¿ªÊ¼
1753* ²ÎÊý˵Ã÷£º
1754* ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
1755* ÆäËü˵Ã÷£ºÁªÍ¨DM×¢²áÌá½»¿ªÊ¼£¬·ÖÎö´úÂëÇë×¢ÒâÒÔÏÂϸ½Ú:
1756* ÁªÍ¨Ð­Ò鹿·¶Ö¸¶¨£¬Èç¹û×¢²á²»³É¹¦£¬ÐèÒª½øÐжà´Î³¢ÊÔ×¢²á
1757* 1¡¢¿ª»ú°ëСʱºó·¢Æð×¢²áÁ÷³Ì
1758* 2¡¢Ã¿´Î¿ª»ú³¢ÊÔ3ÂÖ£¬Ã¿ÂÖ¼ä¸ôÊÇ6¸öСʱ£¬Ã¿ÂÖÀïÃæÓÖ°üº¬Èý´Î£¬Ã¿´ÎµÄ¼ä¸ôÊÇ6·ÖÖÓ£¬¹ÊÒ»´Î¿ª»ú×î¶à³¢ÊÔ9´Î
1759* 3¡¢Ã¿Ò»ÂÖµÄÊýÄ¿£¬Ã¿Ò»´ÎÊýÄ¿£¬¶¼Òª±£´æ£¬×÷Ϊע²áÐÅÏ¢Ò»²¿·Ö£¬Ìá½»¸øÁªÍ¨·þÎñÆ÷¡£
1760* 4¡¢¶à´Î¿ª»úºó£¬µ±×¢²áµÄ×ܵÄÂÖÊý£¬´ïµ½10,²»³¬¹ý11ÂÖ£¬»¹Ã»ÓÐ×¢²á³É¹¦£¬±¾Öն˽«ÓÀÔ¶²»ÔÚ×¢²á¡£
1761*/
1762static int dm_unicom_register_start(struct DM_CONTROl_INFO *dmControlInfo)
1763{
1764 char *dataBuf = NULL;
1765 int dataSize = 0;
1766 int ret = 0;
1767 static int currentRounds = 1;
1768 static int currentTimes = 1;
1769 DM_UNICOM_HTTP_URL_INFO dmUnicomUrlInfo ;
1770 DM_UNICOM_HTTP_DATA_INFO dmUnicomHttpDataInfo ;
1771 struct DM_UNICOM_REGISTER_INFO dmUnicomRegInfo ;
1772
1773 dataSize = (DM_NV_ITEM_SIZE + DM_NV_ITEM_SIZE / 4 + 5) * DM_INFO_UNICOM_MAX;
1774
1775 if (!(dataBuf = (char *) malloc(dataSize)))
1776 {
1777 log_err("dm unicom start reg malloc mem error\n");
1778 return DM_ERR_PARAM_NULL;
1779 }
1780 memset(&dmUnicomHttpDataInfo, 0, sizeof(DM_UNICOM_HTTP_DATA_INFO));
1781 memset(dataBuf, 0, dataSize);
1782 dmUnicomHttpDataInfo.dataBuffer = dataBuf;
1783 dmUnicomHttpDataInfo.dataLen = dataSize;
1784
1785 /* Öն˳¢ÊÔ×ܵÄÂÖÊýСÓÚ 10ÂÖ £¬µ±Ç°¿ª»ú³¢ÊÔµÄÂÖÊý²»³¬¹ý3ÂÖ£¬ÇÒÿÂÖ²»³¬¹ý3´Î */
1786 if ((dmControlInfo->registeredRounds <= DM_ROUND_TOTAL) && (currentRounds <= 3))
1787 {
1788 /* ×¢²áµÄtag¸³Öµ²Ù×÷£¬(tag, ÁªÍ¨ÓÃÓں˶Ե±Ç°Öն˳¢ÊÔ×¢²áµÄ´ÎÊýºÍÂÖÊý) */
1789 dmControlInfo->currentTimes = currentTimes;
1790 dmControlInfo->currentRounds = currentRounds;
1791
1792 /*±£´æ×ܵÄÂÖÊý£¬×¢²áǰ½øÐб£´æ£¬Ð­Ò鹿·¶Ö¸¶¨¡£Ô¤·ÀÔÚijһÂÖÖУ¬Óû§¹Ø»úÁË£¬±¾ÂÖÐèÒª¼ÆÊý*/
1793 char registerRound[5] = {0};
1794 snprintf(registerRound, 4, "%d", dmControlInfo->registeredRounds);
1795 sc_cfg_set(DM_REGISTERED_ROUND, registerRound);
1796
1797 ret = dm_unicom_register_info_create(dmControlInfo, &dmUnicomRegInfo);
1798 if(DM_ERR_SUCCESS != ret)
1799 goto ErrRet;
1800
1801 ret = dm_unicom_json_info_create(&dmUnicomRegInfo, &dmUnicomHttpDataInfo);
1802
1803 ret = dm_unicom_url_info_create(dmControlInfo, &dmUnicomRegInfo, &dmUnicomUrlInfo);
1804 if(DM_ERR_SUCCESS != ret)
1805 goto ErrRet; //klockworks issue.
1806
1807 ret = dm_unicom_http_request(&dmUnicomUrlInfo, &dmUnicomHttpDataInfo);
1808 log_debug("dm register total rounds(%d), currentRounds(%d), currentTimes(%d), http-ret(%d)\n", dmControlInfo->registeredRounds, currentRounds, currentTimes, ret);
1809
1810 if (0 == ret)
1811 {
1812 char registerFlag[4] = {0};
1813 char registerRounds[4] = {0};
1814
1815 dmControlInfo->registerFlag = DM_REGISTERED_YES;
1816 snprintf(registerFlag, 3, "%d", dmControlInfo->registerFlag);
1817 sc_cfg_set("registerFlag", registerFlag);
1818
1819 snprintf(registerRounds, 3, "%d", 0);
1820 sc_cfg_set("registerRounds", registerRounds);
1821
1822 dm_resource_clean(dmControlInfo, (void *) &dmUnicomHttpDataInfo);
1823 return DM_ERR_SUCCESS;
1824 }
1825
1826 /* ·Ç·þÎñÆ÷·µ»Ø´íÎó£¬ÐèÒªÖØÊÔ£¬µ«´Ë´Î²»¼ÆÈë³¢ÊÔ´ÎÊý */
1827 if (ret == ERR_SOCKET_NO_IP)
1828 {
1829 /*·Ç·þÎñÆ÷´íÎ󣬵±Ç°±¾´Î ´ÎÊý²»ÄܼÆÈëͳ¼Æ */
1830 log_debug("dm start register£¬ some net's error occur \n");
1831 dm_resource_clean(dmControlInfo, &dmUnicomHttpDataInfo);
1832
1833 /*
1834 *´Î´íÎóÊÇÓÉÍøÂç´íÎ󣬽øÐйæ±Ü¡£ÒòΪÒѾ­check·ÓÉÊÇOk,¶ø·¢ÏÖ²»ÁËIPµØÖ·
1835 */
1836 dm_timer_add(3, 0);
1837 return DM_ERR_NET_ERROR;
1838 }
1839
1840 /* ÿÂÖÀïÃæ³¢ÊÔ3´Î£¬´¦Àíÿ´Î */
1841 if (currentTimes < 3)
1842 {
1843 currentTimes++;
1844 dmControlInfo->currentTimes = currentTimes;
1845 /* Æô¶¯Ã¿´Î³¢ÊÔ¶¨Ê±Æ÷ */
1846 dm_timer_add(dmControlInfo->secsEveryTime * 60, DM_TIMER_ID_UNICOM_EVERY_TIMES);
1847 }
1848 else /* ´¦ÀíÿÂÖ */
1849 {
1850 currentTimes = 1; /* ÿÂÖÖУ¬´ÎÊýÖØÐ´ÓÁ㿪ʼ¼ÆÊý */
1851 dmControlInfo->currentTimes = currentTimes;
1852
1853 currentRounds++;
1854 dmControlInfo->currentRounds = currentRounds;
1855
1856 /*ÒÀ¾ÝЭÒ鹿·¶£¬Ò»´Î¿ª»ú×î¶à³¢ÊÔ3ÂÖ*/
1857 if (dmControlInfo->currentRounds > 3)
1858 {
1859 dm_resource_clean(dmControlInfo, &dmUnicomHttpDataInfo);
1860 log_debug("dm unicom currentRound(%d)\n", dmControlInfo->currentRounds);
1861 return DM_ERR_SERVER_ERROR;
1862 }
1863
1864 dmControlInfo->registeredRounds++;
1865 if (10 < dmControlInfo->registeredRounds)
1866 {
1867 log_debug("dm unicom registeredRound(%d)\n", dmControlInfo->registeredRounds);
1868 dm_resource_clean(dmControlInfo, &dmUnicomHttpDataInfo);
1869 return DM_ERR_SERVER_ERROR;
1870 }
1871 /* Æô¶¯Ã¿ÂÖ³¢ÊÔ¶¨Ê±Æ÷ */
1872 dm_timer_add(dmControlInfo->secsEveryRound * 60, DM_TIMER_ID_UNICOM_EVERY_ROUND);
1873 }
1874
1875 log_debug("dm start register start: debug info as following ************\n");
1876 log_debug("dm total rounds-next(%d), currentRounds-next(%d), currentTimes-next(%d)\n", dmControlInfo->registeredRounds, currentRounds, currentTimes);
1877 log_debug("dm register secTimer(%d), secsEveryRound(%d) , secsEveryTime(%d), netStatus(%d), globalRomaing(%d)\n",
1878 dmControlInfo->secTimer,
1879 dmControlInfo->secsEveryRound,
1880 dmControlInfo->secsEveryTime,
1881 dmControlInfo->netStatus,
1882 dmControlInfo->globalRomaing);
1883
1884 dm_resource_clean(dmControlInfo, &dmUnicomHttpDataInfo);
1885 return DM_ERR_SERVER_ERROR;
1886 }
1887
1888 dm_resource_clean(dmControlInfo, &dmUnicomHttpDataInfo);
1889 return DM_ERR_RETRY_ERROR;
1890
1891ErrRet:
1892 free(dataBuf);
1893 return ret; //klockworks issue.
1894}
1895
1896/**
1897* º¯ÊýÃû³Æ£ºdm_unicom_register_request_handle
1898* ¹¦ÄÜÃèÊö£ºÁªÍ¨DM×¢²áÇëÇó´¦Àí
1899* ²ÎÊý˵Ã÷£º
1900* ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
1901* ÆäËü˵Ã÷£º
1902*/
1903static int dm_unicom_register_request_handle(struct DM_CONTROl_INFO *dmControlInfo)
1904{
1905 CHECK_PARAM(dmControlInfo);
1906
1907 int checkTimes = 10;
1908 char romaingStatus[DM_NV_ITEM_SIZE] = {0};
1909 char netStatus[DM_NV_ITEM_SIZE] = {0};
1910 char cardType[4] = {0};
1911
1912 /*cmt »ñÈ¡ ״ֵ̬*/
1913 CALL(sc_cfg_get(NV_PDP_STATUS, netStatus, sizeof(netStatus)));
1914 CALL(sc_cfg_get(NV_SIMCARD_ROAM, romaingStatus, sizeof(romaingStatus)));
1915 CALL(sc_cfg_get(NV_SIMCARD_TYPE, cardType, sizeof(cardType)));
1916
1917 dmControlInfo->netStatus = atoi(netStatus);
1918 dmControlInfo->cardType = atoi(cardType);
1919
1920 if (0 == strcmp(romaingStatus, "Internal"))
1921 {
1922 dmControlInfo->globalRomaing = 1;
1923 }
1924 else if (0 == strcmp(romaingStatus, "Home"))
1925 {
1926 dmControlInfo->globalRomaing = 0;
1927 }
1928 else
1929 {
1930 log_err("dm global romaing some error, romaingStatus(%s) \n ", romaingStatus);
1931 return DM_ERR_WAITING_NET_STATUS_CHANAGE;
1932 }
1933
1934 /* 1¡¢Êý¾ÝÁ´Â·¹Ø±Õ£¬»ò
1935 * 2¡¢Êý¾ÝÁ´Â·´ò¿ª£¬ÇÒÔÚ¹ú¼ÊÂþÓÎ
1936 * ²»½øÐÐ×¢²á¡£
1937 */
1938 if ((dmControlInfo->netStatus == 0) || ((dmControlInfo->netStatus == 1) && (dmControlInfo->globalRomaing == 1)))
1939 {
1940 /*±ê¼Ç¶¨Ê±Æ÷µ½Ê±£¬Êý¾ÝÁ´Â·Ã»Óдò¿ª£¬µÈ´ýÊý¾ÝÁ´Â·´ò¿ªÏûÏ¢, ´¥·¢×¢²áÁ÷³Ì */
1941 dmControlInfo->needRegForNetStatusChange = 1;
1942 log_debug(" startup_proc now, net status(%d), romaing status(%d), needRegForNetStatusChange(%d)\n", dmControlInfo->netStatus, dmControlInfo->globalRomaing, dmControlInfo->needRegForNetStatusChange);
1943 return DM_ERR_WAITING_NET_STATUS_CHANAGE;
1944 }
1945 dmControlInfo->needRegForNetStatusChange = 0;
1946
1947 /*ÓÉÓÚPDPÏûÏ¢Éϱ¨£¬Íø¿¨²»ÄÜÁ¢¼´Ê¹Óà £¬½øÐзÓɼì²é */
1948 while (checkTimes-- >= 0)
1949 {
1950 if (1 == default_route_check())
1951 break;
1952 usleep(1000 * 500);
1953 if (0 == checkTimes)
1954 {
1955 log_debug("unicom startup check rout times(%d)\n", checkTimes);
1956 return DM_ERR_CHECK_ROUTE_ERROR;
1957 }
1958 }
1959
1960 /*ctm ·¢Æð×¢²áÁ÷³Ì */
1961 CALL(dm_unicom_register_start(dmControlInfo));
1962
1963 return DM_ERR_SUCCESS;
1964}
1965
1966/**
1967* º¯ÊýÃû³Æ£ºdm_register_request_handle
1968* ¹¦ÄÜÃèÊö£ºDM×¢²áÇëÇó´¦Àí
1969* ²ÎÊý˵Ã÷£º
1970* ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
1971* ÆäËü˵Ã÷£º
1972*/
1973static int dm_register_request_handle(struct DM_CONTROl_INFO *dmControlInfo)
1974{
1975 CHECK_PARAM(dmControlInfo);
1976
1977 if (DM_MOBILE == dmControlInfo->dmType)
1978 {
1979 char imei[DM_NV_ITEM_SIZE] = {0};
1980 char iccid[DM_NV_ITEM_SIZE] = {0};
1981 char imeiPrevious[DM_NV_ITEM_SIZE] = {0};
1982 char iccidPrevious[DM_NV_ITEM_SIZE] = {0};
1983 char cardType[4] = {0};
1984 char versionPrevious[DM_NV_ITEM_SIZE] = {0};
1985 char version[DM_NV_ITEM_SIZE] = {0};
1986
1987 CALL(sc_cfg_get(NV_IMEI, imei, sizeof(imei)));
1988 CALL(sc_cfg_get(NV_ZICCID, iccid, sizeof(iccid)));
1989
1990 CALL(sc_cfg_get(DM_IMEI_PREVIOUS, imeiPrevious, sizeof(imeiPrevious)));
1991 CALL(sc_cfg_get(DM_ICCID_PREVIOUS, iccidPrevious, sizeof(iccidPrevious)));
1992 CALL(sc_cfg_get(NV_SIMCARD_TYPE, cardType, sizeof(cardType)));
1993
1994 CALL(sc_cfg_get(DM_VERSION_PREVIOU, versionPrevious, sizeof(versionPrevious)));
1995 CALL(sc_cfg_get(DM_SW_VERSION, version, sizeof(version)));
1996
1997 snprintf(dmControlInfo->imeiPrevious, sizeof(dmControlInfo->imeiPrevious)-1, "%s", imeiPrevious);
1998 snprintf(dmControlInfo->iccidPrevious, sizeof(dmControlInfo->iccidPrevious)-1, "%s", iccidPrevious); //klockworks issue.
1999
2000 dmControlInfo->cardType = atoi(cardType);
2001
2002 /*
2003 * 1¡¢Òƶ¯DM ÒѾ­×¢²á¹ý£¬µ«ÊǸü»»ÁË sim ¿¨£¬Ð­Ò鹿¶¨ÐèÒªÖØÐÂ×¢²á
2004 * 2¡¢Òƶ¯DM fotaÉý¼¶ÐèÒªÖØÐ·¢Æð×¢²á,ÒÀ¾ÝǰºóµÄ°æ±¾ºÅ½øÐÐÅжÏ
2005 * eg: B11 -> B12 -> B11 ÎÞÐè×¢²á
2006 */
2007 if ((DM_REGISTERED_YES == dmControlInfo->registerFlag)
2008 && (!strcmp(dmControlInfo->imeiPrevious, imei)
2009 && (!strcmp(dmControlInfo->iccidPrevious, iccid)))
2010 && (!strcmp(versionPrevious, version)))
2011 {
2012 log_debug("dm mobile imei and iccid have no change, system have no updated now (fota), versionPrevious(%s), vesion(%s)\n", versionPrevious, version);
2013 return DM_ERR_DEVICE_REGISTERED;
2014 }
2015
2016 /*ÒÆ¶¯DM ²åÈë·ÇÒÆ¶¯¿¨ ²»×¢²á */
2017 if (1 != dmControlInfo->cardType)
2018 {
2019 log_debug("dm mobile register, no-mobile-card cardType(%s) \n", cardType);
2020 return DM_ERR_NO_MOBILE_CARD_ERROR;
2021 }
2022
2023 CALL(dm_mobile_register_request_handle(dmControlInfo));
2024 }
2025 else if (DM_UNICOM == dmControlInfo->dmType)
2026 {
2027 CALL(dm_unicom_register_request_handle(dmControlInfo));
2028 }
2029 else if (DM_TELECOM == dmControlInfo->dmType)
2030 {
2031 CALL(dm_telecom_register_request_handle(dmControlInfo));
2032 }
2033 else
2034 {
2035 log_err("dm don't not know the register type(%d) now ...\n", dmControlInfo->dmType);
2036 }
2037 return DM_ERR_SUCCESS;
2038}
2039
2040
2041/**
2042 * º¯ÊýÃû³Æ£ºdm_main_thread_release
2043 * ¹¦ÄÜÃèÊö£ºÍ¨ÖªdmÄ£¿éÖ÷Ị̈߳¬Í˳öÏß³Ì
2044 * ²ÎÊý˵Ã÷£º
2045 * ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
2046 * ÆäËü˵Ã÷£º
2047 */
2048static int dm_main_thread_release(struct DM_CONTROl_INFO *dmControlInfo)
2049{
2050 CHECK_PARAM(dmControlInfo);
2051 int ret = 0;
2052 long size = 0;
2053 MSG_BUF msgBuf = {0};
2054 msgBuf.usMsgCmd = DM_MSG_CMD_MAIN_THREAD_EXIT;
2055 size = sizeof(MSG_BUF) - sizeof(long);
2056 msgBuf.lMsgType = 1;
2057
2058 dmControlInfo->registErThreadFlag = 0; /*×ÓÏß³ÌÍ˳ö±ê¼Ç£¬ ͬʱ·¢ËÍÏûÏ¢µ½Ö÷Ị̈߳¬ÈÃÖ÷Ïß³ÌÍ˳ö*/
2059
2060 ret = msgsnd(dmControlInfo->msgQueueId, (void*) & (msgBuf), size, 0);
2061 if (ret < 0)
2062 {
2063 log_err("main thread release msg errro \n");
2064 return DM_ERR_QUEUE_SEND_ERROR;
2065 }
2066
2067 return DM_ERR_SUCCESS;
2068}
2069
2070/**
2071* º¯ÊýÃû³Æ£ºdm_register_queue_msg_proc
2072* ¹¦ÄÜÃèÊö£ºDM×¢²áÏß³ÌÏûÏ¢´¦Àíº¯Êý
2073* ²ÎÊý˵Ã÷£º
2074* ·µ »Ø Öµ£ºÎÞ
2075* ÆäËü˵Ã÷£º×¢²áỊ̈߳¬ÓÃÓÚ½ÓÊÕÖ÷Ï̷߳¢Ë͵Ä×¢²áÇëÇóÏûÏ¢,ºÍÏß³ÌÍ˳öÏûÏ¢
2076* (×¢Òâ×¢²á¿ØÖÆÏà¹ØµÄ±äÁ¿µÄÉèÖ㬶¼ÔÚ´ÎÏß³ÌÖÐ
2077* ½øÐÐÉèÖã¬Ö÷Ïß³ÌÖв»ÄܶÔÉæ¼°µ½¶Ôͬ²½±äÁ¿µÄ¸³Öµ£¬Ö»ÄܶÁÈ¡)
2078*/
2079static void dm_register_queue_msg_proc(MSG_BUF *pstMsg, struct DM_CONTROl_INFO *dmControlInfo)
2080{
2081 switch (pstMsg->usMsgCmd)
2082 {
2083 case DM_MSG_CMD_REGISTER_REQUEST:
2084 {
2085 dm_register_request_handle(dmControlInfo);
2086 break;
2087 }
2088
2089 case DM_MSG_CMD_REGISTER_THREAD_RELEASE:
2090 {
2091 dm_main_thread_release(dmControlInfo);
2092 log_debug("dm register thread readly to exit...\n");
2093 break;
2094 }
2095
2096 default:
2097 log_debug("dm queue msg proc\n");
2098 }
2099}
2100
2101/**
2102 * º¯ÊýÃû³Æ£ºdm_server_thread_entry
2103 * ¹¦ÄÜÃèÊö£ºdm×¢²áÏß³ÌÈë¿Úº¯Êý
2104 * ²ÎÊý˵Ã÷£º
2105 * ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
2106 * ÆäËü˵Ã÷£º
2107 */
2108static void* dm_server_thread_entry(void* args)
2109{
2110 int ret = 0;
2111 MSG_BUF dmMsg = {0};
2112 long msgSize = 0;
2113 pthread_attr_t threadAttr;
2114
2115 if (!args)
2116 {
2117 log_err("dm register thread param error \n");
2118 return NULL;
2119 }
2120
2121 struct DM_CONTROl_INFO *dmControlInfo = (struct DM_CONTROl_INFO *) args;
2122
2123 pthread_attr_init(&threadAttr);
2124 pthread_attr_setstacksize(&threadAttr, 16 * 1024);
2125 prctl(PR_SET_NAME, "dm_register_server", 0, 0, 0);
2126
2127 log_debug("dm register thread start now...\n");
2128 dmControlInfo->registErThreadFlag = 1;
2129 while (dmControlInfo->registErThreadFlag)
2130 {
2131 memset((void*)(&dmMsg), 0, sizeof(dmMsg));
2132 msgSize = sizeof(MSG_BUF) - sizeof(long);
2133 if (0 < (ret = msgrcv(dmControlInfo->msgQueueIdReg, &dmMsg, msgSize, 0, MSG_NOERROR)))
2134 {
2135 log_debug("dm register thread recv msg now: ret(%d), dmMsg.src_id(%ld), dmMsg.usMsgCmd(0x%08x), dmMsg.usDatalen(%d), dmMsg.auDataBuffer(%s)\n",
2136 ret, dmMsg.src_id, dmMsg.usMsgCmd, dmMsg.usDataLen, dmMsg.aucDataBuf);
2137 dm_wake_lock("dm_lock_dm");
2138 dm_register_queue_msg_proc(&dmMsg, dmControlInfo);
2139 dm_wake_unlock("dm_lock_dm");
2140 }
2141 else
2142 {
2143 log_err(" dm server thread rec data error ,err-code\n");
2144 }
2145 }
2146
2147 pthread_attr_destroy(&threadAttr); //klockworks issue.
2148 log_debug("dm reg server exit now... \n");
2149 return NULL;
2150}
2151
2152/**
2153 * º¯ÊýÃû³Æ£ºdm_register_thread_init
2154 * ¹¦ÄÜÃèÊö£ºDM×¢²áÏ̳߳õʼ»¯
2155 * ²ÎÊý˵Ã÷£º
2156 * ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
2157 * ÆäËü˵Ã÷£º
2158 */
2159static int dm_register_thread_init(struct DM_CONTROl_INFO *dmControlInfo)
2160{
2161 CHECK_PARAM(dmControlInfo);
2162
2163 if (-1 == ((dmControlInfo->msgQueueIdReg) = msgget(IPC_PRIVATE, IPC_CREAT | 0600)))
2164 {
2165 log_err("Create MSG_ID_DMREG queue faild! (*msgId)(%d)\n", dmControlInfo->msgQueueIdReg);
2166 return DM_ERR_CREATE_MSG_QUEUE_ERROR;
2167 }
2168
2169 if (0 != pthread_create(& (dmControlInfo->pid), NULL, dm_server_thread_entry, dmControlInfo))
2170 {
2171 log_err("dm servers pthread_create error\n");
2172 return DM_ERR_CREATE_THERAD_ERROR;
2173 }
2174
2175 return DM_ERR_SUCCESS;
2176}
2177
2178/**
2179 * º¯ÊýÃû³Æ£ºdm_init_unicom_control_info
2180 * ¹¦ÄÜÃèÊö£º³õʼ»¯Áªµ÷DM¿ØÖÆÐÅÏ¢
2181 * ²ÎÊý˵Ã÷£º
2182 * ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
2183 * ÆäËü˵Ã÷£º
2184 */
2185static int dm_unicom_control_info_init(struct DM_CONTROl_INFO *dmControlInfo)
2186{
2187 char secsEveryRound[DM_NV_ITEM_SIZE] = {0};
2188 char secsEveryTime[DM_NV_ITEM_SIZE] = {0};
2189 char registeredRounds[DM_NV_ITEM_SIZE] = {0};
2190 char secTimer[DM_NV_ITEM_SIZE] = {0};
2191 char hostName[DM_NV_ITEM_SIZE] = {0};
2192 char portNum[12] = {0};
2193 char netStatus[4] = {0};
2194
2195 CHECK_PARAM(dmControlInfo);
2196
2197 CALL(sc_cfg_get(DM_SECS_EVERY_ROUND, secsEveryRound, DM_NV_ITEM_SIZE));
2198 CALL(sc_cfg_get(DM_SECS_EVERY_TIME, secsEveryTime, DM_NV_ITEM_SIZE));
2199 CALL(sc_cfg_get(DM_REGISTERED_ROUND, registeredRounds, DM_NV_ITEM_SIZE));
2200 CALL(sc_cfg_get(DM_SEC_TIMER, secTimer, DM_NV_ITEM_SIZE));
2201 CALL(sc_cfg_get(DM_HOST_NAME, hostName, DM_NV_ITEM_SIZE));
2202 CALL(sc_cfg_get(DM_PORT_NUM, portNum, sizeof(portNum))); //klockworks issue.
2203 CALL(sc_cfg_get(NV_PDP_STATUS, netStatus, 4));
2204
2205 dmControlInfo->secsEveryRound = atoi(secsEveryRound);
2206 dmControlInfo->secsEveryTime = atoi(secsEveryTime);
2207 dmControlInfo->registeredRounds = atoi(registeredRounds);
2208 /*klocwork 3 SV.TAINTED.BINOP, add if condition*/
2209 if((dmControlInfo->registeredRounds >= 0) && (dmControlInfo->registeredRounds < 100))
2210 {
2211 dmControlInfo->registeredRounds = dmControlInfo->registeredRounds + 1;
2212 }
2213
2214 dmControlInfo->secTimer = atoi(secTimer);
2215 dmControlInfo->netStatus = atoi(netStatus);
2216
2217 dmControlInfo->portNum = atol(portNum);
2218 snprintf(dmControlInfo->hostName, DM_NV_ITEM_SIZE - 1, "%s", hostName);
2219
2220 log_debug("dm unicom init control info: secsEveryTime(%d), secsEveryRound(%d), registeredRounds(%d), secTimer(%d), hostName(%s), portNum(%ld), netStatus(%d) \n",
2221 dmControlInfo->secsEveryTime,
2222 dmControlInfo->secsEveryRound,
2223 dmControlInfo->registeredRounds,
2224 dmControlInfo->secTimer,
2225 dmControlInfo->hostName,
2226 dmControlInfo->portNum,
2227 dmControlInfo->netStatus);
2228
2229 return DM_ERR_SUCCESS;
2230}
2231
2232/**
2233 * º¯ÊýÃû³Æ£ºdm_init_mobile_control_info
2234 * ¹¦ÄÜÃèÊö£º³õʼ»¯Òƶ¯DM¿ØÖÆÐÅÏ¢
2235 * ²ÎÊý˵Ã÷£º
2236 * ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
2237 * ÆäËü˵Ã÷£º
2238 */
2239static int dm_mobile_control_info_init(struct DM_CONTROl_INFO * dmControlInfo)
2240{
2241 char secTimer[DM_NV_ITEM_SIZE] = {0};
2242 char hostName[DM_NV_ITEM_SIZE] = {0};
2243 char portNum[DM_NV_ITEM_SIZE] = {0};
2244 char imeiPrevious[DM_NV_ITEM_SIZE] = {0};
2245 char iccidPrevious[DM_NV_ITEM_SIZE] = {0};
2246 char cardType[4] = {0};
2247 char secsEveryRound[DM_NV_ITEM_SIZE] = {0};
2248
2249 CHECK_PARAM(dmControlInfo);
2250 CHECK_PARAM(dmControlInfo);
2251
2252 CALL(sc_cfg_get(DM_SEC_TIMER, secTimer, sizeof(secTimer)));
2253 CALL(sc_cfg_get(DM_HOST_NAME, hostName, sizeof(hostName)));
2254 CALL(sc_cfg_get(DM_PORT_NUM, portNum, sizeof(portNum)));
2255 CALL(sc_cfg_get(NV_SIMCARD_TYPE, cardType, sizeof(cardType)));
2256 CALL(sc_cfg_get(DM_IMEI_PREVIOUS, imeiPrevious, sizeof(imeiPrevious)));
2257 CALL(sc_cfg_get(DM_ICCID_PREVIOUS, iccidPrevious, sizeof(iccidPrevious)));
2258 CALL(sc_cfg_get(DM_SECS_EVERY_ROUND, secsEveryRound, sizeof(secsEveryRound)));
2259
2260 dmControlInfo->secTimer = atoi(secTimer);
2261 dmControlInfo->portNum = atoi(portNum);
2262 snprintf(dmControlInfo->hostName, 31, "%s", hostName);
2263 dmControlInfo->cardType = atoi(cardType);
2264 dmControlInfo->secsEveryRound = atoi(secsEveryRound);
2265
2266 snprintf(dmControlInfo->imeiPrevious, 31, "%s", imeiPrevious);
2267 snprintf(dmControlInfo->iccidPrevious, 31, "%s", iccidPrevious);
2268
2269 log_debug("dm init mobile control info: secsEveryRound(%d),secTimer(%d), cardType(%d), portNum(%d), hostName(%s), iccidPrevious(%s), imeiPrevious(%s)\n",
2270 dmControlInfo->secsEveryRound,
2271 dmControlInfo->secTimer,
2272 dmControlInfo->cardType,
2273 dmControlInfo->portNum,
2274 dmControlInfo->hostName,
2275 dmControlInfo->iccidPrevious,
2276 dmControlInfo->imeiPrevious);
2277 return DM_ERR_SUCCESS;
2278}
2279
2280/**
2281 * º¯ÊýÃû³Æ£ºdm_telecom_control_info_init
2282 * ¹¦ÄÜÃèÊö£º³õʼ»¯µçÐÅDM¿ØÖÆÐÅÏ¢
2283 * ²ÎÊý˵Ã÷£º
2284 * ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
2285 * ÆäËü˵Ã÷£º
2286 */
2287static int dm_telecom_control_info_init(struct DM_CONTROl_INFO * dmControlInfo)
2288{
2289 char hostName[DM_NV_ITEM_SIZE] = {0};
2290 char portNum[DM_NV_ITEM_SIZE] = {0};
2291
2292 char imeiPrevious[DM_NV_ITEM_SIZE] = {0};
2293 char iccidPrevious[DM_NV_ITEM_SIZE] = {0};
2294 char cardType[4] = {0};
2295 char secsEveryRound[DM_NV_ITEM_SIZE] = {0};
2296 char secsEveryTime[DM_NV_ITEM_SIZE] = {0};
2297
2298 CHECK_PARAM(dmControlInfo);
2299
2300 CALL(sc_cfg_get(DM_HOST_NAME, hostName, sizeof(hostName)));
2301 CALL(sc_cfg_get(DM_PORT_NUM, portNum, sizeof(portNum)));
2302 //CALL(sc_cfg_get(NV_SIMCARD_TYPE, cardType, sizeof(cardType)));
2303 CALL(sc_cfg_get(DM_IMEI_PREVIOUS, imeiPrevious, sizeof(imeiPrevious)));
2304 CALL(sc_cfg_get(DM_ICCID_PREVIOUS, iccidPrevious, sizeof(iccidPrevious)));
2305 CALL(sc_cfg_get(DM_SECS_EVERY_ROUND, secsEveryRound, sizeof(secsEveryRound)));
2306 CALL(sc_cfg_get(DM_SECS_EVERY_TIME, secsEveryTime, sizeof(secsEveryTime)));
2307
2308 dmControlInfo->portNum = atoi(portNum);
2309 snprintf(dmControlInfo->hostName, 31, "%s", hostName);
2310 dmControlInfo->cardType = atoi(cardType);
2311 dmControlInfo->secsEveryRound = atoi(secsEveryRound);
2312 dmControlInfo->secsEveryTime = atoi(secsEveryTime);
2313
2314 snprintf(dmControlInfo->imeiPrevious, 31, "%s", imeiPrevious);
2315 snprintf(dmControlInfo->iccidPrevious, 31, "%s", iccidPrevious);
2316
2317 log_debug("dm init mobile control info: secsEveryRound(%d),secTimer(%d), cardType(%d), portNum(%d), hostName(%s), iccidPrevious(%s), imeiPrevious(%s)\n",
2318 dmControlInfo->secsEveryRound,
2319 dmControlInfo->secTimer,
2320 dmControlInfo->cardType,
2321 dmControlInfo->portNum,
2322 dmControlInfo->hostName,
2323 dmControlInfo->iccidPrevious,
2324 dmControlInfo->imeiPrevious);
2325 return DM_ERR_SUCCESS;
2326}
2327
2328/**
2329 * º¯ÊýÃû³Æ£ºdm_control_info_init
2330 * ¹¦ÄÜÃèÊö£º³õʼ»¯DM¿ØÖÆÐÅÏ¢
2331 * ²ÎÊý˵Ã÷£º
2332 * ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
2333 * ÆäËü˵Ã÷£º
2334 */
2335static int dm_control_info_init(struct DM_CONTROl_INFO *dmControlInfo)
2336{
2337 CHECK_PARAM(dmControlInfo);
2338 memset((void*) dmControlInfo, 0, sizeof(struct DM_CONTROl_INFO));
2339
2340 CALL(dm_get_device_type(dmControlInfo));
2341
2342 if (DM_MOBILE == dmControlInfo->dmType)
2343 {
2344 CALL(dm_mobile_control_info_init(dmControlInfo));
2345 }
2346 else if (DM_UNICOM == dmControlInfo->dmType)
2347 {
2348 CALL(dm_unicom_control_info_init(dmControlInfo));
2349 }
2350 else if (DM_TELECOM == dmControlInfo->dmType)
2351 {
2352 CALL(dm_telecom_control_info_init(dmControlInfo));
2353 }
2354 else
2355 {
2356 log_err("the device type is none \n");
2357 return DM_ERR_DEVICE_TYPE_IS_NONE;
2358 }
2359
2360 log_debug("dm control info init success, device dmType(%d),registeredRounds(%d), secsEveryTime(%d), secsEveryRound(%d) ,cardType(%d), hostNameUnicom(%s), portNum(%u), imeiPrevious(%s), iccidPrevious(%s)\n",
2361 dmControlInfo->dmType,
2362 dmControlInfo->registeredRounds,
2363 dmControlInfo->secsEveryTime,
2364 dmControlInfo->secsEveryRound,
2365 dmControlInfo->cardType,
2366 dmControlInfo->hostName,
2367 dmControlInfo->portNum,
2368 dmControlInfo->imeiPrevious,
2369 dmControlInfo->iccidPrevious);
2370 return DM_ERR_SUCCESS;
2371}
2372
2373BOOL dm_telecom_check_iccid_registed(void)
2374{
2375 char iccid[DM_NV_ITEM_SIZE] = {0};
2376 char iccidPrevious[DM_NV_ITEM_SIZE] = {0};
2377 char versionPrevious[DM_NV_ITEM_SIZE] = {0};
2378 char version[DM_NV_ITEM_SIZE] = {0};
2379
2380 CALL(sc_cfg_get(NV_ZICCID, iccid, sizeof(iccid)));
2381 CALL(sc_cfg_get(DM_ICCID_PREVIOUS, iccidPrevious, sizeof(iccidPrevious)));
2382 CALL(sc_cfg_get(DM_VERSION_PREVIOU, versionPrevious, sizeof(versionPrevious)));
2383 CALL(sc_cfg_get(DM_SW_VERSION, version, sizeof(version)));
2384
2385 if (0 != strcmp("", versionPrevious) &&
2386 0 != strcmp(versionPrevious, version))
2387 {
2388 log_debug("[dm_telecom] software version update!\n");
2389 sc_cfg_set(DM_ICCID_PREVIOUS, "0");
2390 return FALSE;
2391 }
2392
2393 if (0 != strcmp("", iccidPrevious) &&
2394 0 == strcmp(iccid, iccidPrevious))
2395 {
2396 log_debug("[dm_telecom] check_ueiccid same!\n");
2397 return TRUE;
2398 }
2399
2400 return FALSE;
2401}
2402
2403BOOL dm_check_is_chinatelecom(void)
2404{
2405 char num_oper[DM_NV_ITEM_SIZE] = {0};
2406 sc_cfg_get(NV_OPER_NUM, num_oper, sizeof(num_oper));
2407 if (strcmp(num_oper, "46003") == 0 ||
2408 strcmp(num_oper, "46005") == 0 ||
2409 strcmp(num_oper, "46011") == 0)
2410 {
2411 return TRUE;
2412 }
2413
2414 return FALSE;
2415}
2416
2417/**
2418 * º¯ÊýÃû³Æ£ºdm_unicom_register_info_create
2419 * ¹¦ÄÜÃèÊö: ¹¹ÔìÁªÍ¨DMЭÒ鹿·¶Ö¸¶¨µÄ×¢²áÐÅÏ¢
2420 * ²ÎÊý˵Ã÷£º
2421 * ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
2422 * ÆäËü˵Ã÷£º
2423 */
2424static int dm_telecom_register_info_create(struct DM_CONTROl_INFO *dmControlInfo, struct DM_TELECOM_REGISTER_INFO *dmTelecomRegInfo)
2425{
2426 CHECK_PARAM(dmTelecomRegInfo);
2427 (void)dmControlInfo;
2428
2429 sc_cfg_get(DM_REGVER, dmTelecomRegInfo->value[DM_INFO_REGVER], DM_NV_ITEM_SIZE);
2430 sc_cfg_get(DM_MEID, dmTelecomRegInfo->value[DM_INFO_MEID], DM_NV_ITEM_SIZE);
2431 sc_cfg_get(DM_MODEL, dmTelecomRegInfo->value[DM_INFO_MODELSMS], DM_NV_ITEM_SIZE);
2432 sc_cfg_get(NV_CR_VERSION, dmTelecomRegInfo->value[DM_INFO_SWVER], DM_NV_ITEM_SIZE);
2433 //sc_cfg_get(NV_SIM_IMSI, dmTelecomRegInfo->value[DM_INFO_SIM1CDMAIMSI], DM_NV_ITEM_SIZE);
2434 sc_cfg_get(DM_UETYPE, dmTelecomRegInfo->value[DM_INFO_UETYPE], DM_NV_ITEM_SIZE);
2435 sc_cfg_get(NV_ZICCID, dmTelecomRegInfo->value[DM_INFO_SIM1ICCID], DM_NV_ITEM_SIZE);
2436 sc_cfg_get(NV_SIM_IMSI, dmTelecomRegInfo->value[DM_INFO_SIM1LTEIMSI], DM_NV_ITEM_SIZE);
2437
2438 sc_cfg_get(NV_IMEI, dmTelecomRegInfo->value[DM_INFO_IMEI], DM_NV_ITEM_SIZE);
2439 strcpy(dmTelecomRegInfo->value[DM_INFO_SIM1TYPE], "2"); //TODO
2440
2441 return DM_ERR_SUCCESS;
2442}
2443
2444
2445/**
2446 * º¯ÊýÃû³Æ£ºdm_unicom_json_info_create
2447 * ¹¦ÄÜÃèÊö£º¹¹ÔìÁªÍ¨Ð­Ò鹿·¶json¸ñʽÊý¾Ý
2448 * ²ÎÊý˵Ã÷£º
2449 * ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
2450 * ÆäËü˵Ã÷£º
2451 */
2452static int dm_telecom_json_info_create(struct DM_TELECOM_REGISTER_INFO *dmTelecomRegInfo, DM_TELECOM_HTTP_DATA_INFO *httpsDataInfo)
2453{
2454 CHECK_PARAM(dmTelecomRegInfo);
2455 CHECK_PARAM(httpsDataInfo);
2456
2457 int i = 0;
2458 char *pTmep = NULL;
2459 int jsonSize = 0;
2460 char *telecomItemName[] = {"REGVER", "MEID", "MODELSMS", "SWVER",
2461 "SIM1CDMAIMSI", "UETYPE", "SIM1ICCID", "SIM1LTEIMSI",
2462 "IMEI1", "BASEID", "SIM1TYPE", "SID",
2463 "NID"
2464 };
2465 /*json fromat as following
2466 * {"key1":"key1Value","key2":"key2Value", xxxxx}*/
2467 log_debug("dm unicom json infof ***********\n");
2468
2469 pTmep = httpsDataInfo->dataBuffer;
2470 memset(pTmep, 0, httpsDataInfo->dataLen);
2471 for (i = 0; i < DM_INFO_TELECOM_MAX; i++)
2472 {
2473 if (i == 0)
2474 sprintf(pTmep, "{\"%s\":\"%s\"", telecomItemName[i], dmTelecomRegInfo->value[i]);
2475 else if (i == DM_INFO_TELECOM_MAX - 1)
2476 sprintf(pTmep, ",\"%s\":\"%s\"}", telecomItemName[i], dmTelecomRegInfo->value[i]);
2477 else
2478 sprintf(pTmep, ",\"%s\":\"%s\"", telecomItemName[i], dmTelecomRegInfo->value[i]);
2479
2480 log_debug("json-value(%s)\n", pTmep);
2481 jsonSize = jsonSize + strlen(pTmep);
2482 pTmep = pTmep + strlen(pTmep);
2483
2484 if (jsonSize > httpsDataInfo->dataLen)
2485 log_err("json buffer memory overwrite now! please check memory size, jsonSize(%d), httpsDatainfo-size(%d) !!!\n", jsonSize, httpsDataInfo->dataLen);
2486 }
2487
2488 httpsDataInfo->dataLen = jsonSize;
2489 log_debug("create json info, json-szie(%d)\n", jsonSize);
2490
2491 return DM_ERR_SUCCESS;
2492}
2493
2494/**
2495 * º¯ÊýÃû³Æ£º dm_telecom_url_info_create
2496 * ¹¦ÄÜÃèÊö£º ¹¹ÔìÒÆ¶¯DMµÄ·þÎñÆ÷ urlÐÅÏ¢£¬°üÀ¨ ·þÎñÆ÷µØÖ·£¬¶Ë¿ÚµÈÐÅÏ¢£¬
2497 * ²ÎÊý˵Ã÷£º
2498 * ·µ »Ø Öµ£º ³É¹¦ 0: ʧ°Ü ´íÎóÂë
2499 * ÆäËü˵Ã÷£º
2500 */
2501static int dm_telecom_url_info_create(struct DM_CONTROl_INFO *dmControlInfo, struct DM_TELECOM_REGISTER_INFO *dmMobileRegInfo, DM_TELECOM_HTTP_URL_INFO *dmMobileUrlInfo)
2502{
2503 CHECK_PARAM(dmControlInfo);
2504 CHECK_PARAM(dmMobileRegInfo);
2505 CHECK_PARAM(dmMobileUrlInfo);
2506 CHECK_PARAM(dmMobileUrlInfo->urlBuffer);
2507
2508 memset(dmMobileUrlInfo, 0, sizeof(DM_TELECOM_HTTP_URL_INFO));
2509
2510 snprintf(dmMobileUrlInfo->hostName, DM_NV_ITEM_SIZE - 1, "%s", dmControlInfo->hostName);
2511
2512 snprintf(dmMobileUrlInfo->ipAddr, 31, "%s", dmControlInfo->ipAddr);
2513
2514 dmMobileUrlInfo->portNum = dmControlInfo->portNum;
2515
2516 log_debug("dm unicom url-info debug: ulr(%s), portNum(%ld), hostName(%s)\n ", dmMobileUrlInfo->urlBuffer, dmMobileUrlInfo->portNum, dmMobileUrlInfo->hostName);
2517
2518 return DM_ERR_SUCCESS;
2519}
2520
2521BOOL dm_telecom_need_reg_check(struct DM_CONTROl_INFO *dmControlInfo)
2522{
2523 char sim_imsi[DM_NV_ITEM_SIZE] = {0};
2524 char cardType[4] = {0};
2525
2526 /*¼ì²âÊÇ·ñΪµçÐÅ¿¨*/
2527 if (FALSE == dm_check_is_chinatelecom())
2528 {
xf.libdd93d52023-05-12 07:10:14 -07002529 log_debug("[dm_telecom] selfreg_check, not telecom sim or network, return!!\n");
lh9ed821d2023-04-07 01:36:19 -07002530 return FALSE;
2531 }
2532
2533 CALL(sc_cfg_get(NV_SIMCARD_TYPE, cardType, sizeof(cardType)));
2534 dmControlInfo->cardType = atoi(cardType);
2535 /*µçÐÅDM ²åÈë·ÇµçÐÅ¿¨ ²»×¢²á */
2536 if (3 != dmControlInfo->cardType)
2537 {
xf.libdd93d52023-05-12 07:10:14 -07002538 log_debug("[dm_telecom] selfreg_check, no-telecom-card cardType(%s) \n", cardType);
lh9ed821d2023-04-07 01:36:19 -07002539 return FALSE;
2540 }
2541 /*ÒѾ­³É¹¦×¢²á*/
2542 if (TRUE == dm_telecom_check_iccid_registed())
2543 {
xf.libdd93d52023-05-12 07:10:14 -07002544 log_debug("[dm_telecom] selfreg_check, selfreg success, return!!\n");
lh9ed821d2023-04-07 01:36:19 -07002545 return FALSE;
2546 }
2547 /*ÖØÊÔ´ÎÊý´óÓÚ10*/
2548 if (dmControlInfo->currentTimes >= DM_TELECOM_RETRY_TIMES)
2549 {
xf.libdd93d52023-05-12 07:10:14 -07002550 log_debug("[dm_telecom] selfreg_check, selfreg retry over, return!!\n");
lh9ed821d2023-04-07 01:36:19 -07002551 return FALSE;
2552 }
2553
2554 sc_cfg_get(NV_SIM_IMSI, sim_imsi, sizeof(sim_imsi) - 1);
2555 if (0 == strcmp(sim_imsi, ""))
2556 {
xf.libdd93d52023-05-12 07:10:14 -07002557 log_debug("[dm_telecom] selfreg_check, sim_imsi is null, return!!\n");
lh9ed821d2023-04-07 01:36:19 -07002558 return FALSE;
2559 }
2560
2561 return TRUE;
2562}
2563
2564/**
2565* º¯ÊýÃû³Æ£º dm_telecom_register_start
2566* ¹¦ÄÜÃèÊö£º µçÐÅDM×¢²áÁ÷³Ì¿ªÊ¼
2567* ²ÎÊý˵Ã÷£º
2568* ·µ »Ø Öµ£º ³É¹¦ 0: ʧ°Ü ´íÎóÂë
2569* ÆäËü˵Ã÷£º
2570*/
2571static int dm_telecom_register_start(struct DM_CONTROl_INFO *dmControlInfo)
2572{
2573 char *dataBuf = NULL;
2574 int dataSize = 0;
2575 int ret = 0;
2576 char imei[DM_NV_ITEM_SIZE] = {0};
2577 char iccid[DM_NV_ITEM_SIZE] = {0};
2578 char version[DM_NV_ITEM_SIZE] = {0};
2579 DM_TELECOM_HTTP_URL_INFO dmTelecomUrlInfo = {{0}, {0}, {0}, 0};
2580 DM_TELECOM_HTTP_DATA_INFO dmTelecomHttpsDataInfo = {0};
2581 struct DM_TELECOM_REGISTER_INFO dmTelecomRegInfo ;
2582 printf("dm_telecom_register_start enter!\n");
2583 dataSize = (DM_NV_ITEM_SIZE + DM_NV_ITEM_SIZE / 4 + 5) * DM_INFO_TELECOM_MAX;
2584
2585 if (!(dataBuf = (char *) malloc(dataSize)))
2586 {
2587 log_err("dm unicom start reg malloc mem error\n");
2588 return DM_ERR_PARAM_NULL;
2589 }
2590 memset(dataBuf, 0, dataSize);
2591 dmTelecomHttpsDataInfo.dataBuffer = dataBuf;
2592 dmTelecomHttpsDataInfo.dataLen = dataSize;
2593
2594 ret = dm_telecom_register_info_create(dmControlInfo, &dmTelecomRegInfo);
2595
2596 ret = dm_telecom_json_info_create(&dmTelecomRegInfo, &dmTelecomHttpsDataInfo);
2597
2598 ret = dm_telecom_url_info_create(dmControlInfo, &dmTelecomRegInfo, &dmTelecomUrlInfo);
2599 if(DM_ERR_SUCCESS != ret)
2600 {
2601 free(dataBuf);
2602 return ret;
2603 } //klockworks issue.
2604
2605 printf("dm_telecom_register_start enter: telecom_https_request!\n");
2606 ret = telecom_https_request(&dmTelecomUrlInfo, &dmTelecomHttpsDataInfo);
2607
2608 if (0 == ret)
2609 {
2610 /*×¢²á³É¹¦£¬±£´æNV */
2611 char buf[4] = {0};
2612 dmControlInfo->registerFlag = DM_REGISTERED_YES;
2613 snprintf(buf, 3, "%d", dmControlInfo->registerFlag);
2614 sc_cfg_set("registerFlag", buf); //ctm
2615
2616 /*дÈëIMEI ICCID ºÅ*/
2617 sc_cfg_get(NV_IMEI, imei, sizeof(imei));
2618 sc_cfg_get(NV_ZICCID, iccid, sizeof(iccid));
2619 sc_cfg_get(DM_SW_VERSION, version, sizeof(version));
2620
2621 sc_cfg_set(DM_IMEI_PREVIOUS, imei);
2622 sc_cfg_set(DM_ICCID_PREVIOUS, iccid);
2623
2624 /*дÈë°æ±¾ºÅ£¬ÎªfotaÉý¼¶ºó DM ×¢²áµÄÒÀ¾Ý*/
2625 sc_cfg_set(DM_VERSION_PREVIOU, version);
2626
2627 dm_resource_clean(dmControlInfo, (void *) &dmTelecomHttpsDataInfo);
2628 return DM_ERR_SUCCESS;
2629 }
2630
2631 dm_resource_clean(dmControlInfo, &dmTelecomHttpsDataInfo);
2632 log_debug("dm start register start: debug info as following ************\n");
2633 log_debug("dm currentTimes(%d)\n", dmControlInfo->currentTimes);
2634 log_debug("dm register secTimer(%d), , secsEveryTime(%d), netStatus(%d), globalRomaing(%d)\n",
2635 dmControlInfo->secTimer,
2636 dmControlInfo->secsEveryTime,
2637 dmControlInfo->netStatus,
2638 dmControlInfo->globalRomaing);
2639
2640 return DM_ERR_RETRY_ERROR;
2641}
2642
2643/**
2644* º¯ÊýÃû³Æ£ºdm_telecom_register_request_handle
2645* ¹¦ÄÜÃèÊö£ºµçÐÅDM×¢²áÇëÇó´¦Àí
2646* ²ÎÊý˵Ã÷£º
2647* ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
2648* ÆäËü˵Ã÷£º
2649*/
2650static int dm_telecom_register_request_handle(struct DM_CONTROl_INFO *dmControlInfo)
2651{
2652 int ret = 0;
2653 int checkTimes = 100;
2654 char romaingStatus[DM_NV_ITEM_SIZE] = {0};
2655 char netStatus[DM_NV_ITEM_SIZE] = {0};
2656
2657 printf("dm_telecom_register_request_handle enter!\n");
2658 CHECK_PARAM(dmControlInfo);
2659
2660 if(FALSE == dm_telecom_need_reg_check(dmControlInfo)) //²»Âú×ã×¢²áÌõ¼þ
2661 {
2662 log_debug("dm_telecom_register_request_handle: reg condition check fail! \n");
2663 return DM_ERR_RETRY_ERROR;
2664 }
2665 /*»ñÈ¡ ״ֵ̬*/
2666 CALL(sc_cfg_get(NV_PDP_STATUS, netStatus, sizeof(netStatus)));
2667 CALL(sc_cfg_get(NV_SIMCARD_ROAM, romaingStatus, sizeof(romaingStatus)));
2668
2669 dmControlInfo->netStatus = atoi(netStatus);
2670
2671 printf("dm_telecom_register_request_handle netStatus = %d!\n", dmControlInfo->netStatus);
2672 if (0 == strcmp(romaingStatus, "Internal"))
2673 {
2674 dmControlInfo->globalRomaing = 1;
2675 }
2676 else if (0 == strcmp(romaingStatus, "Home"))
2677 {
2678 dmControlInfo->globalRomaing = 0;
2679 }
2680 else
2681 {
2682 log_err("dm global romaing some error, romaingStatus(%s) \n ", romaingStatus);
2683 return DM_ERR_WAITING_NET_STATUS_CHANAGE;
2684 }
2685 /* ×î¶àÖØÊÔ10´Î*/
2686 log_debug("dm_telecom_register_request_handle default_route_check = %d\n", default_route_check());
2687 if(0 == default_route_check()) //PDPδ¼¤»î
2688 {
2689 if((0 == dmControlInfo->currentTimes) && (g_retrytimes_before_netactived < DM_TELECOM_RETRYTIMES_BEFORE_ACTIVED)) //´ÓÀ´Ã»Ó줻î¹ý
2690 {
2691 g_retrytimes_before_netactived++;
2692 CALL(dm_timer_add(10, DM_TIMER_ID_MOBILE_START));//10SºóÖØÊÔ
2693 log_debug("dm_telecom_register_request_handle addtimer: g_retrytimes_before_netactived = %d, dmType(%d), secTimer(%d)\n", g_retrytimes_before_netactived, dmControlInfo->dmType, 10);
2694 }
2695 else
2696 {
2697 dmControlInfo->currentTimes++; /*´ÎÊý½øÐмÆÊý */
2698 /* ʧ°ÜÆô¶¯Ã¿´Î³¢ÊÔ¶¨Ê±Æ÷ */
2699 dm_timer_add(dmControlInfo->secsEveryTime * 60, DM_TIMER_ID_MOBILE_EVERY_TIMES);
2700 }
2701 return DM_ERR_NET_ERROR;
2702 }
2703
2704 while (checkTimes-- > 0)
2705 {
2706 if (1 == default_route_check())
2707 break;
2708 usleep(1000 * 400);
2709 log_debug("mobile startup check rout times(%d)\n", checkTimes);
2710 if (checkTimes == 0)
2711 {
2712 log_err("dm net some error occur\n");
2713 return DM_ERR_CHECK_ROUTE_ERROR;
2714 }
2715 }
2716 dmControlInfo->currentTimes++; /*´ÎÊý½øÐмÆÊý */
2717 /*·¢Æðhttp´«ÊäÁ÷³Ì */
2718 if (DM_ERR_SUCCESS != dm_telecom_register_start(dmControlInfo))
2719 {
2720
2721 /* ³¢ÊÔ×¢²áµÄ´ÎÊýСÓÚ 10 ´Îʱ£¬¼ÌÐø³¢ÊÔ */
2722 if (dmControlInfo->currentTimes < DM_TELECOM_RETRY_TIMES)
2723 {
2724 /*1¡¢dmControlInfo->secsEveryRound Óû§Í¨¹ý¹¤³ÌÃüÁîÉèÖÃ,Ä¿µÄÊÇ·½±ã²âÊÔÈËÔ±½øÐвâÊÔ£¬
2725 * ´ËÖµ´úÌæÐ­Ò鹿¶¨µÄÕæÊµµÄ´Î¼ä¸ôʱ¼ä£¬Ëõ¶Ì²âÊÔʱ¼ä£»
2726 *2¡¢Ä¬ÈÏÖµ0,±íʾʹÓÃÕæÊµµÄ´Î¼ä¸ôʱ¼ä£¬·Ç0 ±íʾʹÓôËÉèÖõÄÖµ´úÌæ²âÊÔ */
2727 if (0 != dmControlInfo->secsEveryRound)
2728 {
2729 dmControlInfo->secsEveryTime = dmControlInfo->secsEveryRound;
2730
2731 }
2732 /* ʧ°ÜÆô¶¯Ã¿´Î³¢ÊÔ¶¨Ê±Æ÷ */
2733 dm_timer_add(dmControlInfo->secsEveryTime * 60, DM_TIMER_ID_MOBILE_EVERY_TIMES);
2734 }
2735
2736 log_debug("dm mobile register error, ret(%d), currentTimes(%d), next-rtc-time(%d)\n", ret, dmControlInfo->currentTimes, dmControlInfo->secsEveryTime);
2737 return ret;
2738 }
2739
2740 return DM_ERR_SUCCESS;
2741}
2742
2743/**
2744 * º¯ÊýÃû³Æ£ºdm_net_global_romaing_proc
2745 * ¹¦ÄÜÃèÊö£ºÂþÓÎÏûÏ¢´¦Àíº¯Êý , ÓÉbl²ãÉϱ¨
2746 * ²ÎÊý˵Ã÷£º
2747 * ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
2748 * ÆäËü˵Ã÷£º
2749 */
2750static int dm_net_global_romaing_proc(struct DM_CONTROl_INFO *dmControlInfo)
2751{
2752 CHECK_PARAM(dmControlInfo);
2753 char romaingStatus[DM_NV_ITEM_SIZE] = {0};
2754 char netStatus[4] = {0};
2755
2756 CALL(sc_cfg_get(NV_PDP_STATUS, netStatus, sizeof(netStatus)));
2757 CALL(sc_cfg_get(NV_SIMCARD_ROAM, romaingStatus, sizeof(romaingStatus)));
2758
2759 dmControlInfo->netStatus = atoi(netStatus);
2760
2761 if (0 == strcmp(romaingStatus, "Internal"))
2762 {
2763 dmControlInfo->globalRomaing = 1;
2764 }
2765 else if (0 == strcmp(romaingStatus, "Home"))
2766 {
2767 dmControlInfo->globalRomaing = 0;
2768 }
2769 else
2770 {
2771 log_err("dm global romaing some error, romaingStatus(%s) \n ", romaingStatus);
2772 return DM_ERR_ROMAING_STATUS_ERROR;
2773 }
2774
2775 /* ÍøÂçÊý¾Ý¿ª¹Ø´ò¿ª£¬ Çҷǹú¼ÊÂþÓÎ */
2776 if (dmControlInfo->netStatus && !dmControlInfo->globalRomaing)
2777 {
2778 /* ÏÂÃæ±ê¼ÇµÄ¹¦ÄÜÊÇ: ¶¨Ê±Æ÷³¬Ê±£¬¶øÓÉÓÚÍøÂç¹Ø±Õ£¬±ØÐëµÈ´ýÍøÂ翪¹Ø´ò¿ª½øÐÐ×¢²á
2779 * Ðë±£Ö¤´Î±êÖ¾Ö»ÄÜÔÚ×¢²áÏß³ÌÖнøÐÐÐ޸ģ¬(Ô¤·À±äÁ¿¶àÏ߳̽»²æÐÞ¸Ä)
2780 */
2781 if (dmControlInfo->needRegForNetStatusChange == 1)
2782 {
2783 /* ÏûÏ¢·¢ËÍ£¬¿ªÊ¼×¢²áÁ÷³Ì */
2784 CALL(dm_register_msg_send(dmControlInfo));
2785 }
2786 }
2787
2788 log_debug("dm global-roaming change now, romaingStatus(%s)\n", romaingStatus);
2789 return DM_ERR_SUCCESS;
2790}
2791
2792/**
2793 * º¯ÊýÃû³Æ£ºdm_config_info_msg_prc
2794 * ¹¦ÄÜÃèÊö£ºCp²àµÄ¹¤³ÌÃüÁîÏûÏ¢´¦Àíº¯Êý
2795 * ²ÎÊý˵Ã÷£º
2796 * ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
2797 * ÆäËü˵Ã÷£º
2798 */
2799static int dm_config_info_msg_prc(MSG_BUF *pstMsg, struct DM_CONTROl_INFO *dmControlInfo)
2800{
2801 CHECK_PARAM(pstMsg);
2802 CHECK_PARAM(dmControlInfo);
2803 CHECK_PARAM(pstMsg->aucDataBuf);
2804
2805 unsigned short dataSize = 0;
2806 char *buf = NULL;
2807
2808 dataSize = pstMsg->usDataLen;
2809 if (pstMsg->usDataLen <= 0)
2810 {
2811 log_err("dm msg some err now, data-len(%d)\n", dataSize);
2812 return DM_ERR_PARAM_NULL;
2813 }
2814
2815 if (strstr((char *) pstMsg->aucDataBuf, "AT+DM_REGISTER_SERVER=")) /*CP ²àµÄ¹¤³ÌÃüÁîÏûÏ¢£¬ÉèÖÃÁªÍ¨·þÎñÆ÷µØÖ·¡¢¶Ë¿ÚÏûÏ¢ */
2816 {
2817 CALL(dm_server_domain_config_set(pstMsg, dmControlInfo));
2818
2819 if (strstr((char *) pstMsg->aucDataBuf, "AT+DM_REGISTER_PORT_NUM="))
2820 {
2821 CALL(dm_server_port_num_set(pstMsg, dmControlInfo));
2822 }
2823 }
2824 else if (strstr((char *) pstMsg->aucDataBuf, "AT+DM_REGISTER_FLAG="))/*CP ²àµÄ¹¤³ÌÃüÁîÏûÏ¢£¬Çå³ý×¢²á±ê¼Ç */
2825 {
2826 dm_register_flag_clean(dmControlInfo);
2827 }
2828 else if (strstr((char *) pstMsg->aucDataBuf, "AT+DM_REGISTER_SECS_ROUND=")) /*CP ²àµÄ¹¤³ÌÃüÁî, ÉèÖÃÿÂÖµÄʱ¼ä¼ä¸ô */
2829 {
2830 CALL(dm_time_every_round_set(pstMsg, dmControlInfo));
2831 }
2832 else if ((buf = strstr((char *) pstMsg->aucDataBuf, "AT+DM_REGISTER_W_ONLY="))) /*CP ²àµÄ¹¤³ÌÃüÁ ±£´æÖÆÊ½*/
2833 {
2834 /*Ô¤·ÀbufÄÚÈݹý´ó£¬µ¼ÖÂдNVʧ°Ü */
2835 char bufData[4] = {0};
2836 buf = buf + strlen("AT+DM_REGISTER_W_ONLY=");
2837 sscanf(buf, "%3[^,]", bufData);
2838 sc_cfg_set("wcdmaModel", bufData);
2839 }
2840
2841 log_debug("dm config info set now: info(%s), info-size(%d)\n", pstMsg->aucDataBuf, pstMsg->usDataLen);
2842 return DM_ERR_SUCCESS;
2843}
2844
2845/**
2846 * º¯ÊýÃû³Æ£ºdm_queue_msg_proc
2847 * ¹¦ÄÜÃèÊö£ºDMÄ£¿éÖ÷Ïß³ÌÏûÏ¢´¦Àíº¯Êý£¬ Ïß³ÌÓÃÓÚ½ÓÊÕ¶à·½ÏûÏ¢(°üÀ¨£¬CP²à¸÷ÖÖ¹¤³ÌÃüÁîµÄÏûÏ¢£¬×ÓÏ̵߳ÄÏûÏ¢£¬¶¨Ê±Æ÷ÏûÏ¢)
2848 * ²ÎÊý˵Ã÷£º
2849 * ·µ »Ø Öµ£ºÎÞ
2850 * ÆäËü˵Ã÷£º
2851 */
2852static void dm_queue_msg_proc(MSG_BUF *pstMsg, struct DM_CONTROl_INFO *dmControlInfo)
2853{
2854 switch (pstMsg->usMsgCmd)
2855 {
2856 case RTC_MSG_ALARM_ELAPSED:
2857 {
2858 /* rtc¶¨Ê±Æ÷³¬Ê±ÏûÏ¢ */
2859 char simCardStatus[DM_NV_ITEM_SIZE] = {0};
2860 char cardType[DM_NV_ITEM_SIZE] = {0};
2861 char ceregStatus[DM_NV_ITEM_SIZE] = {0};
2862 sc_cfg_get(DM_SIM_CARD_STATUS, simCardStatus, sizeof(simCardStatus));
2863 sc_cfg_get(NV_SIMCARD_TYPE, cardType, sizeof(cardType));
2864 sc_cfg_get(DM_CEREG_STATUS, ceregStatus, sizeof(ceregStatus));
2865 log_debug("dm_queue_msg_proc: time out now, simCardStatus(%s), cardType(%s)\n", simCardStatus, cardType);
2866 /*
2867 * simCardStatus nv Öµ 1 »òÕß 5, ±íÃ÷×¢Íø³É¹¦£¬carType¿Õ£¬ÍøÂç¿Ï¶¨Ã»ÓÐ×¼±¸ºÃ
2868 */
2869 if ((!strcmp(simCardStatus, "1") || !strcmp(simCardStatus, "5")) && (strcmp(cardType, "")))
2870 {
2871 dm_register_msg_send(dmControlInfo);
2872 }
2873 else if((!strcmp(ceregStatus, "1") || !strcmp(ceregStatus, "5")) && (strcmp(cardType, "")) )
2874 {
2875 dm_register_msg_send(dmControlInfo);
2876 }
2877 else
2878 {
2879 /*
2880 *µÈ´ý10s, ÖØÐ³¢ÊÔ£¬ Ö±µ½nvÐÅÏ¢×¼±¸ºÃ; pin Â뿪»ú×ß·ÖÖ§
2881 */
2882 dm_timer_add(10, 0);
2883 log_debug("dm queue msg proc have add 10s timer now \n");
2884 }
2885 break;
2886 }
2887
2888 case MSG_CMD_DM_CONFIG_REQ: /*CP ²àµÄ¹¤³ÌÃüÁîÏûÏ¢£¬ÉèÖÃdm²¿·Ö¿ØÖÆÐÅÏ¢ */
2889 {
2890 dm_config_info_msg_prc(pstMsg, dmControlInfo);
2891 break;
2892 }
2893
2894 case MSG_CMD_ROAM_STATUS_IND: /*Êý¾ÝÂþÓÎÏûÏ¢ */
2895 {
2896 dm_net_global_romaing_proc(dmControlInfo);
2897 break;
2898 }
2899
2900 case MSG_CMD_PDP_STATUS_IND: /*pdpÁ´Â·ÏûÏ¢, ÒÆ¶¯²»ÎÞÐè¹Ø×¢*/
2901 {
2902 printf("dm_queue_msg_proc: MSG_CMD_PDP_STATUS_IND \n");
2903 dm_net_status_change_proc(dmControlInfo);
2904 break;
2905 }
2906
2907 case DM_MSG_CMD_MAIN_THREAD_EXIT:
2908 {
2909 dmControlInfo->mainThreadFlag = 0;
2910 log_debug("dm main thread ready to exit now \n");
2911 break;
2912 }
2913
2914 default:
2915 log_debug("dm queue msg default proc£¬\n");
2916 }
2917
2918}
2919
2920
2921/**
2922 * º¯ÊýÃû³Æ£ºdm_server_init
2923 * ¹¦ÄÜÃèÊö£ºDMÄ£¿éÖ÷Ï̷߳þÎñ³õʼ»¯
2924 * ²ÎÊý˵Ã÷£º
2925 * ·µ »Ø Öµ£º³É¹¦ 0: ʧ°Ü ´íÎóÂë
2926 * ÆäËü˵Ã÷£º
2927 */
2928static int dm_server_init(struct DM_CONTROl_INFO *dmControlInfo)
2929{
2930 CHECK_PARAM(dmControlInfo);
2931 int ret = 0;
2932 MSG_BUF dmMsg = {0};
2933 long msgSize = 0;
2934
2935 dmControlInfo->serverId = pthread_self();
2936 if (-1 == ((dmControlInfo->msgQueueId) = msgget(MODULE_ID_DMREG, IPC_CREAT | 0600)))
2937 {
2938 log_err("Create MSG_ID_DMREG queue faild! (*msgId)(%d)\n", dmControlInfo->msgQueueIdReg);
2939 return DM_ERR_CREATE_MSG_QUEUE_ERROR;
2940 }
2941
2942 /*´´½¨¶¨Ê±Æ÷*/
2943 if (DM_ERR_SUCCESS != (ret = dm_timer_create(dmControlInfo)))
2944 {
2945 log_err("dm timer create error...\n");
2946 return DM_ERR_CREATE_MSG_QUEUE_ERROR;
2947 }
2948
2949 log_debug("dm main thread start now...\n");
2950 dmControlInfo->mainThreadFlag = 1;
2951 while (dmControlInfo->mainThreadFlag)
2952 {
2953 memset((void*)(&dmMsg), 0, sizeof(MSG_BUF));
2954 msgSize = sizeof(MSG_BUF) - sizeof(long);
2955 if (0 < (ret = msgrcv(dmControlInfo->msgQueueId, &dmMsg, msgSize, 0, MSG_NOERROR)))
2956 {
2957 log_debug("dm main queue recv msg now: ret(%d), dmMsg.src_id(0x%08x), dmMsg.usMsgCmd(0x%08x), dmMsg.usDatalen(%d), dmMsg.auDataBuffer(%s)\n",
2958 ret, dmMsg.src_id, dmMsg.usMsgCmd, dmMsg.usDataLen, dmMsg.aucDataBuf);
2959 dm_queue_msg_proc(&dmMsg, dmControlInfo);
2960 }
2961 }
2962
2963 if (msgctl(dmControlInfo->msgQueueId, IPC_RMID, NULL) < 0)
2964 log_err("dm remove msg now error \n");
2965
2966 log_debug("dm main thread exit...\n");
2967 return DM_ERR_SUCCESS;
2968}
2969
2970/*******************************************************************************
2971 * È«¾Öº¯Êý¶¨Òå *
2972 ******************************************************************************/
2973/**
2974 * º¯ÊýÃû³Æ£ºmain
2975 * ¹¦ÄÜÃèÊö£ºDMÄ£¿éÈë¿Úº¯Êý
2976 * ²ÎÊý˵Ã÷£º
2977 * ·µ »Ø Öµ£º
2978 * ÆäËü˵Ã÷£º
2979 */
2980int main(void)
2981{
2982 int ret = DM_ERR_SUCCESS;
2983 struct DM_CONTROl_INFO dmControlInfo = {0};
2984
2985 //¸ù¾ÝNV³õʼ»¯´òÓ¡¼¶±ð£¬²¢×¢²á¶¯Ì¬µ÷Õû´òÓ¡¼¶±ðÐźÅÁ¿
2986 loglevel_init();
2987
2988 /* ³õʼ»¯DM¿ØÖÆÏà¹ØÐÅÏ¢ */
2989 ret = dm_control_info_init(&dmControlInfo);
2990 if (DM_ERR_SUCCESS != ret)
2991 {
2992 log_err("dm init control info error...\n");
2993 exit(EXIT_FAILURE);
2994 }
2995
2996 /* ´´½¨×¢²áỊ̈߳¬ ÓÃÓÚÏòÔËÓªÉÌ·þÎñÆ÷½øÐÐÌá½»×¢²á (Ö»½ÓÊÜÖ÷Ï̷߳¢Ë͵ÄÏûÏ¢£¬
2997 * ÓÉÓÚ×¢²áºÄʱ£¬Ðë¶ÀÁ¢Ï̴߳¦Àí£©*/
2998 if (DM_ERR_SUCCESS != (ret = dm_register_thread_init(&dmControlInfo)))
2999 {
3000 log_err("dm register thread start error...\n");
3001 exit(EXIT_FAILURE);
3002 }
3003
3004 /* DM·þÎñÖ÷Ị̈߳¬ÓÃÓÚ½ÓÊÕ¸÷ÖÖÏûÏ¢(°üÀ¨CP£¬¶¨Ê±Æ÷ÏûÏ¢£¬APµÄÏûÏ¢) */
3005 if (DM_ERR_SUCCESS != (ret = dm_server_init(&dmControlInfo)))
3006 {
3007 log_err("dm server start error ...\n");
3008 exit(EXIT_FAILURE);
3009 }
3010
3011 pthread_join(dmControlInfo.pid, NULL);
3012 return 0;
3013}
3014