1 /*
2  * Copyright (C) 2015-2018 Alibaba Group Holding Limited
3  */
4 #include "iotx_dm_internal.h"
5 
6 #ifdef DEPRECATED_LINKKIT
7 
8 #include "linkkit_export.h"
9 #include "impl_solo.h"
10 
11 #ifdef INFRA_MEM_STATS
12 #include "linkkit/infra/infra_mem_stats.h"
13 #define IMPL_SOLO_MALLOC(size) LITE_malloc(size, MEM_MAGIC, "impl.solo")
14 #define IMPL_SOLO_FREE(ptr)    LITE_free(ptr)
15 #else
16 #define IMPL_SOLO_MALLOC(size) HAL_Malloc(size)
17 #define IMPL_SOLO_FREE(ptr)    \
18     {                          \
19         HAL_Free((void *)ptr); \
20         ptr = NULL;            \
21     }
22 #endif
23 
24 #ifdef INFRA_LOG
25 #include "linkkit/infra/infra_log.h"
26 #define impl_solo_err(...)   log_err("impl.solo", __VA_ARGS__)
27 #define impl_solo_info(...)  log_info("impl.solo", __VA_ARGS__)
28 #define impl_solo_debug(...) log_debug("impl.solo", __VA_ARGS__)
29 #else
30 #define impl_solo_err(...)
31 #define impl_solo_info(...)
32 #define impl_solo_debug(...)
33 #endif
34 
35 linkkit_solo_legacy_ctx_t g_linkkit_solo_legacy_ctx = { 0 };
36 
_linkkit_solo_legacy_get_ctx(void)37 static being_deprecated linkkit_solo_legacy_ctx_t *_linkkit_solo_legacy_get_ctx(
38     void)
39 {
40     return &g_linkkit_solo_legacy_ctx;
41 }
42 
_linkkit_solo_mutex_lock(void)43 static void _linkkit_solo_mutex_lock(void)
44 {
45     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
46         _linkkit_solo_legacy_get_ctx();
47     if (linkkit_solo_ctx->mutex) {
48         HAL_MutexLock(linkkit_solo_ctx->mutex);
49     }
50 }
51 
_linkkit_solo_mutex_unlock(void)52 static void _linkkit_solo_mutex_unlock(void)
53 {
54     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
55         _linkkit_solo_legacy_get_ctx();
56     if (linkkit_solo_ctx->mutex) {
57         HAL_MutexUnlock(linkkit_solo_ctx->mutex);
58     }
59 }
60 
_linkkit_solo_upstream_mutex_lock(void)61 static void _linkkit_solo_upstream_mutex_lock(void)
62 {
63     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
64         _linkkit_solo_legacy_get_ctx();
65     if (linkkit_solo_ctx->upstream_mutex) {
66         HAL_MutexLock(linkkit_solo_ctx->upstream_mutex);
67     }
68 }
69 
_linkkit_solo_upstream_mutex_unlock(void)70 static void _linkkit_solo_upstream_mutex_unlock(void)
71 {
72     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
73         _linkkit_solo_legacy_get_ctx();
74     if (linkkit_solo_ctx->upstream_mutex) {
75         HAL_MutexUnlock(linkkit_solo_ctx->upstream_mutex);
76     }
77 }
78 
_impl_copy(_IN_ void * input,_IN_ int input_len,_OU_ void ** output,_IN_ int output_len)79 static int _impl_copy(_IN_ void *input, _IN_ int input_len, _OU_ void **output,
80                       _IN_ int output_len)
81 {
82     if (input == NULL || output == NULL || *output != NULL) {
83         return DM_INVALID_PARAMETER;
84     }
85 
86     *output = IMPL_SOLO_MALLOC(output_len);
87     if (*output == NULL) {
88         return DM_MEMORY_NOT_ENOUGH;
89     }
90     memset(*output, 0, output_len);
91     memcpy(*output, input, input_len);
92 
93     return SUCCESS_RETURN;
94 }
95 
_linkkit_solo_upstream_callback_list_insert(int msgid,handle_post_cb_fp_t callback)96 static int _linkkit_solo_upstream_callback_list_insert(
97     int msgid, handle_post_cb_fp_t callback)
98 {
99     int count = 0;
100     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
101         _linkkit_solo_legacy_get_ctx();
102     linkkit_solo_upstream_callback_node_t *search_node = NULL;
103 
104     list_for_each_entry(search_node, &linkkit_solo_ctx->callback_list,
105                         linked_list, linkkit_solo_upstream_callback_node_t)
106     {
107         count++;
108         if (search_node->msgid == msgid) {
109             impl_solo_info("Message ID Already Exist: %d", msgid);
110             return FAIL_RETURN;
111         }
112     }
113 
114     impl_solo_info("linkkit_solo_upstream_callback_list node count: %d", count);
115 
116     search_node =
117         IMPL_SOLO_MALLOC(sizeof(linkkit_solo_upstream_callback_node_t));
118     if (search_node == NULL) {
119         return FAIL_RETURN;
120     }
121     memset(search_node, 0, sizeof(linkkit_solo_upstream_callback_node_t));
122 
123     search_node->msgid = msgid;
124     search_node->callback = callback;
125     search_node->callback = callback;
126     INIT_LIST_HEAD(&search_node->linked_list);
127 
128     list_add(&search_node->linked_list, &linkkit_solo_ctx->callback_list);
129 
130     return SUCCESS_RETURN;
131 }
132 
_linkkit_solo_upstream_callback_list_remove(int msgid)133 static int _linkkit_solo_upstream_callback_list_remove(int msgid)
134 {
135     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
136         _linkkit_solo_legacy_get_ctx();
137     linkkit_solo_upstream_callback_node_t *search_node = NULL;
138 
139     list_for_each_entry(search_node, &linkkit_solo_ctx->callback_list,
140                         linked_list, linkkit_solo_upstream_callback_node_t)
141     {
142         if (search_node->msgid == msgid) {
143             list_del(&search_node->linked_list);
144             IMPL_SOLO_FREE(search_node);
145             return SUCCESS_RETURN;
146         }
147     }
148 
149     return FAIL_RETURN;
150 }
151 
_linkkit_solo_upstream_callback_list_search(int msgid,linkkit_solo_upstream_callback_node_t ** node)152 static int _linkkit_solo_upstream_callback_list_search(
153     int msgid, linkkit_solo_upstream_callback_node_t **node)
154 {
155     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
156         _linkkit_solo_legacy_get_ctx();
157     linkkit_solo_upstream_callback_node_t *search_node = NULL;
158 
159     list_for_each_entry(search_node, &linkkit_solo_ctx->callback_list,
160                         linked_list, linkkit_solo_upstream_callback_node_t)
161     {
162         if (search_node->msgid == msgid) {
163             *node = search_node;
164             return SUCCESS_RETURN;
165         }
166     }
167 
168     return FAIL_RETURN;
169 }
170 
_linkkit_solo_upstream_callback_list_destroy(void)171 static int _linkkit_solo_upstream_callback_list_destroy(void)
172 {
173     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
174         _linkkit_solo_legacy_get_ctx();
175     linkkit_solo_upstream_callback_node_t *search_node = NULL,
176                                           *next_node = NULL;
177 
178     list_for_each_entry_safe(search_node, next_node,
179                              &linkkit_solo_ctx->callback_list, linked_list,
180                              linkkit_solo_upstream_callback_node_t)
181     {
182         list_del(&search_node->linked_list);
183         IMPL_SOLO_FREE(search_node);
184     }
185 
186     return FAIL_RETURN;
187 }
188 
linkkit_dispatch(void)189 void *linkkit_dispatch(void)
190 {
191     iotx_dm_dispatch();
192     return NULL;
193 }
194 
linkkit_is_try_leave(void)195 int being_deprecated linkkit_is_try_leave(void)
196 {
197     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
198         _linkkit_solo_legacy_get_ctx();
199     return linkkit_solo_ctx->is_leaved;
200 }
201 
linkkit_set_opt(linkkit_opt_t opt,void * data)202 int being_deprecated linkkit_set_opt(linkkit_opt_t opt, void *data)
203 {
204     int res = 0;
205 
206     if (data == NULL) {
207         return FAIL_RETURN;
208     }
209 
210     _linkkit_solo_mutex_lock();
211     res = iotx_dm_set_opt(opt, data);
212     _linkkit_solo_mutex_unlock();
213 
214     return res;
215 }
216 
_linkkit_solo_event_callback(iotx_dm_event_types_t type,char * payload)217 static void _linkkit_solo_event_callback(iotx_dm_event_types_t type,
218                                          char *payload)
219 {
220     int res = 0;
221     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
222         _linkkit_solo_legacy_get_ctx();
223     lite_cjson_t lite, lite_item_id, lite_item_code, lite_item_devid,
224         lite_item_payload, lite_item_serviceid;
225     lite_cjson_t lite_item_propertyid, lite_item_eventid, lite_item_configid,
226         lite_item_configsize, lite_item_gettype;
227     lite_cjson_t lite_item_sign, lite_item_signmethod, lite_item_url,
228         lite_item_version;
229 
230     impl_solo_info("Receive Message Type: %d", type);
231     if (payload) {
232         impl_solo_info("Receive Message: %s", payload);
233         res =
234             dm_utils_json_parse(payload, strlen(payload), cJSON_Invalid, &lite);
235         if (res != SUCCESS_RETURN) {
236             return;
237         }
238         dm_utils_json_object_item(&lite, LINKKIT_SOLO_LEGACY_KEY_ID,
239                                   strlen(LINKKIT_SOLO_LEGACY_KEY_ID),
240                                   cJSON_Invalid, &lite_item_id);
241         dm_utils_json_object_item(&lite, LINKKIT_SOLO_LEGACY_KEY_CODE,
242                                   strlen(LINKKIT_SOLO_LEGACY_KEY_CODE),
243                                   cJSON_Invalid, &lite_item_code);
244         dm_utils_json_object_item(&lite, LINKKIT_SOLO_LEGACY_KEY_DEVID,
245                                   strlen(LINKKIT_SOLO_LEGACY_KEY_DEVID),
246                                   cJSON_Invalid, &lite_item_devid);
247         dm_utils_json_object_item(&lite, LINKKIT_SOLO_LEGACY_KEY_PAYLOAD,
248                                   strlen(LINKKIT_SOLO_LEGACY_KEY_PAYLOAD),
249                                   cJSON_Invalid, &lite_item_payload);
250         dm_utils_json_object_item(&lite, LINKKIT_SOLO_LEGACY_KEY_SERVICEID,
251                                   strlen(LINKKIT_SOLO_LEGACY_KEY_SERVICEID),
252                                   cJSON_Invalid, &lite_item_serviceid);
253         dm_utils_json_object_item(&lite, LINKKIT_SOLO_LEGACY_KEY_PROPERTYID,
254                                   strlen(LINKKIT_SOLO_LEGACY_KEY_PROPERTYID),
255                                   cJSON_Invalid, &lite_item_propertyid);
256         dm_utils_json_object_item(&lite, LINKKIT_SOLO_LEGACY_KEY_EVENTID,
257                                   strlen(LINKKIT_SOLO_LEGACY_KEY_EVENTID),
258                                   cJSON_Invalid, &lite_item_eventid);
259         dm_utils_json_object_item(&lite, LINKKIT_SOLO_LEGACY_KEY_CONFIG_ID,
260                                   strlen(LINKKIT_SOLO_LEGACY_KEY_CONFIG_ID),
261                                   cJSON_Invalid, &lite_item_configid);
262         dm_utils_json_object_item(&lite, LINKKIT_SOLO_LEGACY_KEY_CONFIG_SIZE,
263                                   strlen(LINKKIT_SOLO_LEGACY_KEY_CONFIG_SIZE),
264                                   cJSON_Invalid, &lite_item_configsize);
265         dm_utils_json_object_item(&lite, LINKKIT_SOLO_LEGACY_KEY_GET_TYPE,
266                                   strlen(LINKKIT_SOLO_LEGACY_KEY_GET_TYPE),
267                                   cJSON_Invalid, &lite_item_gettype);
268         dm_utils_json_object_item(&lite, LINKKIT_SOLO_LEGACY_KEY_SIGN,
269                                   strlen(LINKKIT_SOLO_LEGACY_KEY_SIGN),
270                                   cJSON_Invalid, &lite_item_sign);
271         dm_utils_json_object_item(&lite, LINKKIT_SOLO_LEGACY_KEY_SIGN_METHOD,
272                                   strlen(LINKKIT_SOLO_LEGACY_KEY_SIGN_METHOD),
273                                   cJSON_Invalid, &lite_item_signmethod);
274         dm_utils_json_object_item(&lite, LINKKIT_SOLO_LEGACY_KEY_URL,
275                                   strlen(LINKKIT_SOLO_LEGACY_KEY_URL),
276                                   cJSON_Invalid, &lite_item_url);
277         dm_utils_json_object_item(&lite, LINKKIT_SOLO_LEGACY_KEY_VERSION,
278                                   strlen(LINKKIT_SOLO_LEGACY_KEY_VERSION),
279                                   cJSON_Invalid, &lite_item_version);
280     }
281 
282     switch (type) {
283     case IOTX_DM_EVENT_CLOUD_CONNECTED:
284         {
285             if (linkkit_solo_ctx->user_callback->on_connect) {
286                 linkkit_solo_ctx->user_callback->on_connect(
287                     linkkit_solo_ctx->user_context);
288             }
289         }
290         break;
291     case IOTX_DM_EVENT_CLOUD_DISCONNECT:
292         {
293             if (linkkit_solo_ctx->user_callback->on_disconnect) {
294                 linkkit_solo_ctx->user_callback->on_disconnect(
295                     linkkit_solo_ctx->user_context);
296             }
297         }
298         break;
299     case IOTX_DM_EVENT_MODEL_DOWN_RAW:
300         {
301             int res = 0, raw_data_len = 0;
302             void *thing_id = NULL;
303             unsigned char *raw_data = NULL;
304 
305             if (payload == NULL || lite_item_devid.type != cJSON_Number ||
306                 lite_item_payload.type != cJSON_String) {
307                 return;
308             }
309 
310             impl_solo_debug("Current Devid: %d", lite_item_devid.value_int);
311             impl_solo_debug("Current Raw Data: %.*s",
312                             lite_item_payload.value_length,
313                             lite_item_payload.value);
314 
315             res = iotx_dm_deprecated_legacy_get_thingid_by_devid(
316                 lite_item_devid.value_int, &thing_id);
317             if (res != SUCCESS_RETURN) {
318                 return;
319             }
320 
321             res = dm_utils_str_to_hex(lite_item_payload.value,
322                                       lite_item_payload.value_length, &raw_data,
323                                       &raw_data_len);
324             if (res != SUCCESS_RETURN) {
325                 return;
326             }
327             HEXDUMP_DEBUG(raw_data, raw_data_len);
328 
329             if (linkkit_solo_ctx->user_callback->raw_data_arrived) {
330                 linkkit_solo_ctx->user_callback->raw_data_arrived(
331                     thing_id, raw_data, raw_data_len,
332                     linkkit_solo_ctx->user_context);
333             }
334 
335             IMPL_SOLO_FREE(raw_data);
336         }
337         break;
338     case IOTX_DM_EVENT_THING_SERVICE_REQUEST:
339         {
340             int res = 0;
341             void *thing_id = NULL;
342             char *service = NULL;
343 
344             if (payload == NULL || lite_item_id.type != cJSON_Number ||
345                 lite_item_devid.type != cJSON_Number ||
346                 lite_item_serviceid.type != cJSON_String) {
347                 return;
348             }
349 
350             impl_solo_debug("Current Id: %d", lite_item_id.value_int);
351             impl_solo_debug("Current Devid: %d", lite_item_devid.value_int);
352             impl_solo_debug("Current ServiceID: %.*s",
353                             lite_item_serviceid.value_length,
354                             lite_item_serviceid.value);
355 
356             res = iotx_dm_deprecated_legacy_get_thingid_by_devid(
357                 lite_item_devid.value_int, &thing_id);
358             if (res != SUCCESS_RETURN) {
359                 return;
360             }
361 
362             service = IMPL_SOLO_MALLOC(lite_item_serviceid.value_length + 1);
363             if (service == NULL) {
364                 return;
365             }
366             memset(service, 0, lite_item_serviceid.value_length + 1);
367             memcpy(service, lite_item_serviceid.value,
368                    lite_item_serviceid.value_length);
369 
370             if (linkkit_solo_ctx->user_callback->thing_call_service) {
371                 linkkit_solo_ctx->user_callback->thing_call_service(
372                     thing_id, (const char *)service, lite_item_id.value_int,
373                     linkkit_solo_ctx->user_context);
374             }
375 
376             IMPL_SOLO_FREE(service);
377         }
378         break;
379     case IOTX_DM_EVENT_LEGACY_THING_CREATED:
380         {
381             int res = 0;
382             void *thing_id = NULL;
383 
384             if (payload == NULL || lite_item_devid.type != cJSON_Number) {
385                 return;
386             }
387 
388             impl_solo_debug("Current Devid: %d", lite_item_devid.value_int);
389 
390             res = iotx_dm_deprecated_legacy_get_thingid_by_devid(
391                 lite_item_devid.value_int, &thing_id);
392             if (res != SUCCESS_RETURN) {
393                 return;
394             }
395 
396             if (linkkit_solo_ctx->user_callback->thing_create) {
397                 linkkit_solo_ctx->user_callback->thing_create(
398                     thing_id, linkkit_solo_ctx->user_context);
399             }
400         }
401         break;
402     case IOTX_DM_EVENT_THING_DISABLE:
403         {
404             int res = 0;
405             void *thing_id = NULL;
406 
407             if (payload == NULL || lite_item_devid.type != cJSON_Number) {
408                 return;
409             }
410 
411             impl_solo_debug("Current Devid: %d", lite_item_devid.value_int);
412 
413             res = iotx_dm_deprecated_legacy_get_thingid_by_devid(
414                 lite_item_devid.value_int, &thing_id);
415             if (res != SUCCESS_RETURN) {
416                 return;
417             }
418 
419             if (linkkit_solo_ctx->user_callback->thing_disable) {
420                 linkkit_solo_ctx->user_callback->thing_disable(
421                     thing_id, linkkit_solo_ctx->user_context);
422             }
423         }
424         break;
425     case IOTX_DM_EVENT_THING_ENABLE:
426         {
427             int res = 0;
428             void *thing_id = NULL;
429 
430             if (payload == NULL || lite_item_devid.type != cJSON_Number) {
431                 return;
432             }
433 
434             impl_solo_debug("Current Devid: %d", lite_item_devid.value_int);
435 
436             res = iotx_dm_deprecated_legacy_get_thingid_by_devid(
437                 lite_item_devid.value_int, &thing_id);
438             if (res != SUCCESS_RETURN) {
439                 return;
440             }
441 
442             if (linkkit_solo_ctx->user_callback->thing_enable) {
443                 linkkit_solo_ctx->user_callback->thing_enable(
444                     thing_id, linkkit_solo_ctx->user_context);
445             }
446         }
447         break;
448     case IOTX_DM_EVENT_PROPERTY_SET:
449         {
450             int res = 0;
451             void *thing_id = NULL;
452             char *propertyid = NULL;
453 
454             if (payload == NULL || lite_item_devid.type != cJSON_Number ||
455                 lite_item_propertyid.type != cJSON_String) {
456                 return;
457             }
458 
459             impl_solo_debug("Current Devid: %d", lite_item_devid.value_int);
460             impl_solo_debug("Current PropertyID: %.*s",
461                             lite_item_propertyid.value_length,
462                             lite_item_propertyid.value);
463 
464             res = iotx_dm_deprecated_legacy_get_thingid_by_devid(
465                 lite_item_devid.value_int, &thing_id);
466             if (res != SUCCESS_RETURN) {
467                 return;
468             }
469 
470             propertyid =
471                 IMPL_SOLO_MALLOC(lite_item_propertyid.value_length + 1);
472             if (propertyid == NULL) {
473                 return;
474             }
475             memset(propertyid, 0, lite_item_propertyid.value_length + 1);
476             memcpy(propertyid, lite_item_propertyid.value,
477                    lite_item_propertyid.value_length);
478 
479             if (linkkit_solo_ctx->user_callback->thing_prop_changed) {
480                 linkkit_solo_ctx->user_callback->thing_prop_changed(
481                     thing_id, propertyid, linkkit_solo_ctx->user_context);
482             }
483 
484             IMPL_SOLO_FREE(propertyid);
485         }
486         break;
487     case IOTX_DM_EVENT_EVENT_PROPERTY_POST_REPLY:
488         {
489             int res = 0;
490             void *thing_id = NULL;
491             linkkit_solo_upstream_callback_node_t *node = NULL;
492             handle_post_cb_fp_t callback = NULL;
493 
494             if (payload == NULL || lite_item_id.type != cJSON_Number ||
495                 lite_item_code.type != cJSON_Number ||
496                 lite_item_devid.type != cJSON_Number) {
497                 return;
498             }
499 
500             impl_solo_debug("Current Id: %d", lite_item_id.value_int);
501             impl_solo_debug("Current Code: %d", lite_item_code.value_int);
502             impl_solo_debug("Current Devid: %d", lite_item_devid.value_int);
503 
504             res = iotx_dm_deprecated_legacy_get_thingid_by_devid(
505                 lite_item_devid.value_int, &thing_id);
506             if (res != SUCCESS_RETURN) {
507                 return;
508             }
509 
510             _linkkit_solo_upstream_mutex_lock();
511             res = _linkkit_solo_upstream_callback_list_search(
512                 lite_item_id.value_int, &node);
513             if (res == SUCCESS_RETURN) {
514                 callback = node->callback;
515             }
516             _linkkit_solo_upstream_mutex_unlock();
517             if (res == SUCCESS_RETURN) {
518                 if (callback) {
519                     callback(thing_id, lite_item_id.value_int,
520                              lite_item_code.value_int, NULL,
521                              linkkit_solo_ctx->user_context);
522                 }
523                 _linkkit_solo_upstream_mutex_lock();
524                 _linkkit_solo_upstream_callback_list_remove(
525                     lite_item_id.value_int);
526                 _linkkit_solo_upstream_mutex_unlock();
527             }
528         }
529         break;
530     case IOTX_DM_EVENT_EVENT_SPECIFIC_POST_REPLY:
531         {
532             int res = 0;
533             void *thing_id = NULL;
534             linkkit_solo_upstream_callback_node_t *node = NULL;
535             handle_post_cb_fp_t callback = NULL;
536 
537             if (payload == NULL || lite_item_id.type != cJSON_Number ||
538                 lite_item_code.type != cJSON_Number ||
539                 lite_item_devid.type != cJSON_Number ||
540                 lite_item_eventid.type != cJSON_String) {
541                 return;
542             }
543 
544             impl_solo_debug("Current Id: %d", lite_item_id.value_int);
545             impl_solo_debug("Current Code: %d", lite_item_code.value_int);
546             impl_solo_debug("Current Devid: %d", lite_item_devid.value_int);
547             impl_solo_debug("Current EventID: %.*s",
548                             lite_item_eventid.value_length,
549                             lite_item_eventid.value);
550 
551             res = iotx_dm_deprecated_legacy_get_thingid_by_devid(
552                 lite_item_devid.value_int, &thing_id);
553             if (res != SUCCESS_RETURN) {
554                 return;
555             }
556 
557             _linkkit_solo_upstream_mutex_lock();
558             res = _linkkit_solo_upstream_callback_list_search(
559                 lite_item_id.value_int, &node);
560             if (res == SUCCESS_RETURN) {
561                 callback = node->callback;
562             }
563             _linkkit_solo_upstream_mutex_unlock();
564             if (res == SUCCESS_RETURN) {
565                 if (callback) {
566                     callback(thing_id, lite_item_id.value_int,
567                              lite_item_code.value_int, NULL,
568                              linkkit_solo_ctx->user_context);
569                 }
570                 _linkkit_solo_upstream_mutex_lock();
571                 _linkkit_solo_upstream_callback_list_remove(
572                     lite_item_id.value_int);
573                 _linkkit_solo_upstream_mutex_unlock();
574             }
575         }
576         break;
577     case IOTX_DM_EVENT_COTA_NEW_CONFIG:
578         {
579             char *config_id = NULL, *get_type = NULL, *sign = NULL,
580                  *sign_method = NULL, *url = NULL;
581 
582             if (payload == NULL || lite_item_configid.type != cJSON_String ||
583                 lite_item_configsize.type != cJSON_Number ||
584                 lite_item_gettype.type != cJSON_String ||
585                 lite_item_sign.type != cJSON_String ||
586                 lite_item_signmethod.type != cJSON_String ||
587                 lite_item_url.type != cJSON_String) {
588                 return;
589             }
590 
591             impl_solo_debug("Current Config ID: %.*s",
592                             lite_item_configid.value_length,
593                             lite_item_configid.value);
594             impl_solo_debug("Current Config Size: %d",
595                             lite_item_configsize.value_int);
596             impl_solo_debug("Current Get Type: %.*s",
597                             lite_item_gettype.value_length,
598                             lite_item_gettype.value);
599             impl_solo_debug("Current Sign: %.*s", lite_item_sign.value_length,
600                             lite_item_sign.value);
601             impl_solo_debug("Current Sign Method: %.*s",
602                             lite_item_signmethod.value_length,
603                             lite_item_signmethod.value);
604             impl_solo_debug("Current URL: %.*s", lite_item_url.value_length,
605                             lite_item_url.value);
606 
607             _impl_copy(lite_item_configid.value,
608                        lite_item_configid.value_length, (void **)&config_id,
609                        lite_item_configid.value_length + 1);
610             _impl_copy(lite_item_gettype.value, lite_item_gettype.value_length,
611                        (void **)&get_type, lite_item_gettype.value_length + 1);
612             _impl_copy(lite_item_sign.value, lite_item_sign.value_length,
613                        (void **)&sign, lite_item_sign.value_length + 1);
614             _impl_copy(lite_item_signmethod.value,
615                        lite_item_signmethod.value_length, (void **)&sign_method,
616                        lite_item_signmethod.value_length + 1);
617             _impl_copy(lite_item_url.value, lite_item_url.value_length,
618                        (void **)&url, lite_item_url.value_length + 1);
619 
620             if (config_id == NULL || get_type == NULL || sign == NULL ||
621                 sign_method == NULL || url == NULL) {
622                 if (config_id) {
623                     IMPL_SOLO_FREE(config_id);
624                 }
625                 if (get_type) {
626                     IMPL_SOLO_FREE(get_type);
627                 }
628                 if (sign) {
629                     IMPL_SOLO_FREE(sign);
630                 }
631                 if (sign_method) {
632                     IMPL_SOLO_FREE(sign_method);
633                 }
634                 if (url) {
635                     IMPL_SOLO_FREE(url);
636                 }
637                 return;
638             }
639 
640             if (linkkit_solo_ctx->cota_callback) {
641                 linkkit_solo_ctx->cota_callback(
642                     service_cota_callback_type_new_version_detected, config_id,
643                     lite_item_configsize.value_int, get_type, sign, sign_method,
644                     url);
645             }
646 
647             if (config_id) {
648                 IMPL_SOLO_FREE(config_id);
649             }
650             if (get_type) {
651                 IMPL_SOLO_FREE(get_type);
652             }
653             if (sign) {
654                 IMPL_SOLO_FREE(sign);
655             }
656             if (sign_method) {
657                 IMPL_SOLO_FREE(sign_method);
658             }
659             if (url) {
660                 IMPL_SOLO_FREE(url);
661             }
662         }
663         break;
664     case IOTX_DM_EVENT_FOTA_NEW_FIRMWARE:
665         {
666             char *version = NULL;
667 
668             if (payload == NULL || lite_item_version.type != cJSON_String) {
669                 return;
670             }
671 
672             impl_solo_debug("Current Firmware Version: %.*s",
673                             lite_item_version.value_length,
674                             lite_item_version.value);
675 
676             _impl_copy(lite_item_version.value, lite_item_version.value_length,
677                        (void **)&version, lite_item_version.value_length + 1);
678             if (version == NULL) {
679                 return;
680             }
681 
682             if (linkkit_solo_ctx->fota_callback) {
683                 linkkit_solo_ctx->fota_callback(
684                     service_fota_callback_type_new_version_detected, version);
685             }
686 
687             if (version) {
688                 IMPL_SOLO_FREE(version);
689             }
690         }
691         break;
692 #ifdef LOCAL_CONN_ENABLE
693     case IOTX_DM_EVENT_LOCAL_CONNECTED:
694         {
695             if (linkkit_solo_ctx->on_connect) {
696                 linkkit_solo_ctx->on_connect(context, 0);
697             }
698         }
699         break;
700     case IOTX_DM_EVENT_LOCAL_DISCONNECT:
701         {
702             if (linkkit_solo_ctx->on_connect) {
703                 linkkit_solo_ctx->on_connect(context, 0);
704             }
705         }
706         break;
707 #endif
708     default:
709         break;
710     }
711 }
712 
linkkit_start(int max_buffered_msg,int get_tsl_from_cloud,linkkit_loglevel_t log_level,linkkit_ops_t * ops,linkkit_cloud_domain_type_t domain_type,void * user_context)713 int being_deprecated linkkit_start(int max_buffered_msg, int get_tsl_from_cloud,
714                                    linkkit_loglevel_t log_level,
715                                    linkkit_ops_t *ops,
716                                    linkkit_cloud_domain_type_t domain_type,
717                                    void *user_context)
718 {
719     int res = 0;
720     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
721         _linkkit_solo_legacy_get_ctx();
722     iotx_dm_init_params_t dm_init_params;
723 
724     if (linkkit_solo_ctx->is_started == 1) {
725         return FAIL_RETURN;
726     }
727     linkkit_solo_ctx->is_started = 1;
728 
729     if (max_buffered_msg <= 0 || ops == NULL || log_level > LOG_DEBUG_LEVEL ||
730         domain_type >= linkkit_cloud_domain_max) {
731         impl_solo_err("Invalid Parameter");
732         linkkit_solo_ctx->is_started = 0;
733         return FAIL_RETURN;
734     }
735 
736     /* Create Mutex */
737     linkkit_solo_ctx->mutex = HAL_MutexCreate();
738     if (linkkit_solo_ctx->mutex == NULL) {
739         linkkit_solo_ctx->is_started = 0;
740         return FAIL_RETURN;
741     }
742 
743     linkkit_solo_ctx->upstream_mutex = HAL_MutexCreate();
744     if (linkkit_solo_ctx->upstream_mutex == NULL) {
745         HAL_MutexDestroy(linkkit_solo_ctx->mutex);
746         linkkit_solo_ctx->is_started = 0;
747         return FAIL_RETURN;
748     }
749 
750     /* Set Linkkit Log Level */
751     IOT_SetLogLevel(log_level);
752 
753     /* Set Region */
754     IOT_Ioctl(IOTX_IOCTL_SET_REGION, &domain_type);
755 
756     /* Initialize Device Manager */
757     memset(&dm_init_params, 0, sizeof(iotx_dm_init_params_t));
758     dm_init_params.secret_type = IOTX_DM_DEVICE_SECRET_DEVICE;
759     dm_init_params.domain_type = (iotx_dm_cloud_domain_types_t)domain_type;
760     dm_init_params.event_callback = _linkkit_solo_event_callback;
761 
762     res = iotx_dm_open();
763     if (res != SUCCESS_RETURN) {
764         HAL_MutexDestroy(linkkit_solo_ctx->mutex);
765         HAL_MutexDestroy(linkkit_solo_ctx->upstream_mutex);
766         linkkit_solo_ctx->is_started = 0;
767         return FAIL_RETURN;
768     }
769 
770     res = iotx_dm_connect(&dm_init_params);
771     if (res != SUCCESS_RETURN) {
772         HAL_MutexDestroy(linkkit_solo_ctx->mutex);
773         HAL_MutexDestroy(linkkit_solo_ctx->upstream_mutex);
774         iotx_dm_close();
775         linkkit_solo_ctx->is_started = 0;
776         return FAIL_RETURN;
777     }
778 
779     res = iotx_dm_subscribe(IOTX_DM_LOCAL_NODE_DEVID);
780     if (res != SUCCESS_RETURN) {
781         HAL_MutexDestroy(linkkit_solo_ctx->mutex);
782         HAL_MutexDestroy(linkkit_solo_ctx->upstream_mutex);
783         iotx_dm_close();
784         linkkit_solo_ctx->is_started = 0;
785         return FAIL_RETURN;
786     }
787 
788     /* Get TSL From Cloud If Need */
789     if (get_tsl_from_cloud != 0) {
790         res = iotx_dm_deprecated_set_tsl(IOTX_DM_LOCAL_NODE_DEVID,
791                                          IOTX_DM_TSL_SOURCE_CLOUD, NULL, 0);
792         if (res < SUCCESS_RETURN) {
793             HAL_MutexDestroy(linkkit_solo_ctx->mutex);
794             HAL_MutexDestroy(linkkit_solo_ctx->upstream_mutex);
795             iotx_dm_close();
796             linkkit_solo_ctx->is_started = 0;
797             return FAIL_RETURN;
798         }
799     }
800 
801     /* Init Message Callback List */
802     INIT_LIST_HEAD(&linkkit_solo_ctx->callback_list);
803 
804     linkkit_solo_ctx->user_callback = ops;
805     linkkit_solo_ctx->user_context = user_context;
806     linkkit_solo_ctx->is_leaved = 0;
807 
808     return SUCCESS_RETURN;
809 }
810 
linkkit_end(void)811 int being_deprecated linkkit_end(void)
812 {
813     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
814         _linkkit_solo_legacy_get_ctx();
815 
816     if (linkkit_solo_ctx->is_started == 0) {
817         return FAIL_RETURN;
818     }
819 
820     _linkkit_solo_mutex_lock();
821     _linkkit_solo_upstream_mutex_lock();
822     linkkit_solo_ctx->is_started = 0;
823     _linkkit_solo_upstream_callback_list_destroy();
824     _linkkit_solo_upstream_mutex_unlock();
825 
826     iotx_dm_close();
827     _linkkit_solo_mutex_unlock();
828 
829     HAL_MutexDestroy(linkkit_solo_ctx->upstream_mutex);
830     HAL_MutexDestroy(linkkit_solo_ctx->mutex);
831 
832     linkkit_solo_ctx->mutex = NULL;
833     linkkit_solo_ctx->upstream_mutex = NULL;
834     linkkit_solo_ctx->user_callback = NULL;
835     linkkit_solo_ctx->user_context = NULL;
836     linkkit_solo_ctx->cota_callback = NULL;
837     linkkit_solo_ctx->fota_callback = NULL;
838     INIT_LIST_HEAD(&linkkit_solo_ctx->callback_list);
839 
840     return SUCCESS_RETURN;
841 }
842 
linkkit_set_tsl(const char * tsl,int tsl_len)843 void *linkkit_set_tsl(const char *tsl, int tsl_len)
844 {
845     int res = 0;
846     void *thing_id = NULL;
847     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
848         _linkkit_solo_legacy_get_ctx();
849 
850     if (tsl == NULL || tsl_len <= 0) {
851         impl_solo_err("Invalid Parameter");
852         return NULL;
853     }
854 
855     if (linkkit_solo_ctx->is_started == 0) {
856         return NULL;
857     }
858 
859     _linkkit_solo_mutex_lock();
860     res = iotx_dm_deprecated_set_tsl(IOTX_DM_LOCAL_NODE_DEVID,
861                                      IOTX_DM_TSL_SOURCE_LOCAL, tsl, tsl_len);
862     if (res != SUCCESS_RETURN) {
863         _linkkit_solo_mutex_unlock();
864         return NULL;
865     }
866 
867     res = iotx_dm_deprecated_legacy_get_thingid_by_devid(
868         IOTX_DM_LOCAL_NODE_DEVID, &thing_id);
869     if (res != SUCCESS_RETURN) {
870         _linkkit_solo_mutex_unlock();
871         return NULL;
872     }
873 
874     _linkkit_solo_mutex_unlock();
875     return thing_id;
876 }
877 
linkkit_set_value(linkkit_method_set_t method_set,const void * thing_id,const char * identifier,const void * value,const char * value_str)878 int being_deprecated linkkit_set_value(linkkit_method_set_t method_set,
879                                        const void *thing_id,
880                                        const char *identifier,
881                                        const void *value, const char *value_str)
882 {
883     int res = 0, devid = 0;
884     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
885         _linkkit_solo_legacy_get_ctx();
886 
887     if (thing_id == NULL || identifier == NULL ||
888         (value == NULL && value_str == NULL)) {
889         impl_solo_err("Invalid Parameter");
890         return FAIL_RETURN;
891     }
892 
893     if (linkkit_solo_ctx->is_started == 0) {
894         return FAIL_RETURN;
895     }
896 
897     _linkkit_solo_mutex_lock();
898     res = iotx_dm_deprecated_legacy_get_devid_by_thingid((void *)thing_id,
899                                                          &devid);
900     if (res != SUCCESS_RETURN) {
901         _linkkit_solo_mutex_unlock();
902         return FAIL_RETURN;
903     }
904 
905     switch (method_set) {
906     case linkkit_method_set_property_value:
907         {
908             res = iotx_dm_deprecated_legacy_set_property_value(
909                 devid, (char *)identifier, strlen(identifier), (void *)value,
910                 (char *)value_str);
911         }
912         break;
913     case linkkit_method_set_event_output_value:
914         {
915             res = iotx_dm_deprecated_legacy_set_event_output_value(
916                 devid, (char *)identifier, strlen(identifier), (void *)value,
917                 (char *)value_str);
918         }
919         break;
920     case linkkit_method_set_service_output_value:
921         {
922             res = iotx_dm_deprecated_legacy_set_service_output_value(
923                 devid, (char *)identifier, strlen(identifier), (void *)value,
924                 (char *)value_str);
925         }
926         break;
927     default:
928         {
929             impl_solo_err("Invalid Parameter");
930             res = FAIL_RETURN;
931         }
932         break;
933     }
934 
935     if (res < SUCCESS_RETURN) {
936         _linkkit_solo_mutex_unlock();
937         return FAIL_RETURN;
938     }
939 
940     _linkkit_solo_mutex_unlock();
941 
942     return SUCCESS_RETURN;
943 }
944 
linkkit_get_value(linkkit_method_get_t method_get,const void * thing_id,const char * identifier,void * value,char ** value_str)945 int being_deprecated linkkit_get_value(linkkit_method_get_t method_get,
946                                        const void *thing_id,
947                                        const char *identifier, void *value,
948                                        char **value_str)
949 {
950     int res = 0, devid = 0;
951     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
952         _linkkit_solo_legacy_get_ctx();
953 
954     if (thing_id == NULL || identifier == NULL ||
955         (value == NULL && value_str == NULL)) {
956         impl_solo_err("Invalid Parameter");
957         return FAIL_RETURN;
958     }
959 
960     if (linkkit_solo_ctx->is_started == 0) {
961         return FAIL_RETURN;
962     }
963 
964     _linkkit_solo_mutex_lock();
965     res = iotx_dm_deprecated_legacy_get_devid_by_thingid((void *)thing_id,
966                                                          &devid);
967     if (res != SUCCESS_RETURN) {
968         _linkkit_solo_mutex_unlock();
969         return FAIL_RETURN;
970     }
971 
972     switch (method_get) {
973     case linkkit_method_get_property_value:
974         {
975             res = iotx_dm_deprecated_legacy_get_property_value(
976                 devid, (char *)identifier, strlen(identifier), value,
977                 value_str);
978         }
979         break;
980     case linkkit_method_get_event_output_value:
981         {
982             res = iotx_dm_deprecated_legacy_get_event_output_value(
983                 devid, (char *)identifier, strlen(identifier), value,
984                 value_str);
985         }
986         break;
987     case linkkit_method_get_service_input_value:
988         {
989             res = iotx_dm_deprecated_legacy_get_service_input_value(
990                 devid, (char *)identifier, strlen(identifier), value,
991                 value_str);
992         }
993         break;
994     case linkkit_method_get_service_output_value:
995         {
996             res = iotx_dm_deprecated_legacy_get_service_output_value(
997                 devid, (char *)identifier, strlen(identifier), value,
998                 value_str);
999         }
1000         break;
1001     default:
1002         {
1003             impl_solo_err("Invalid Parameter");
1004             res = FAIL_RETURN;
1005         }
1006         break;
1007     }
1008 
1009     if (res < SUCCESS_RETURN) {
1010         _linkkit_solo_mutex_unlock();
1011         return FAIL_RETURN;
1012     }
1013 
1014     _linkkit_solo_mutex_unlock();
1015 
1016     return SUCCESS_RETURN;
1017 }
1018 
linkkit_answer_service(const void * thing_id,const char * service_identifier,int response_id,int code)1019 int being_deprecated linkkit_answer_service(const void *thing_id,
1020                                             const char *service_identifier,
1021                                             int response_id, int code)
1022 {
1023     int res = 0, devid = 0;
1024 
1025     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
1026         _linkkit_solo_legacy_get_ctx();
1027 
1028     if (thing_id == NULL || service_identifier == NULL) {
1029         impl_solo_err("Invalid Parameter");
1030         return FAIL_RETURN;
1031     }
1032 
1033     if (linkkit_solo_ctx->is_started == 0) {
1034         return FAIL_RETURN;
1035     }
1036 
1037     _linkkit_solo_mutex_lock();
1038     res = iotx_dm_deprecated_legacy_get_devid_by_thingid((void *)thing_id,
1039                                                          &devid);
1040     if (res != SUCCESS_RETURN) {
1041         _linkkit_solo_mutex_unlock();
1042         return FAIL_RETURN;
1043     }
1044 
1045     res = iotx_dm_deprecated_send_service_response(
1046         devid, response_id, (iotx_dm_error_code_t)code,
1047         (char *)service_identifier, strlen(service_identifier));
1048     if (res < SUCCESS_RETURN) {
1049         _linkkit_solo_mutex_unlock();
1050         return FAIL_RETURN;
1051     }
1052 
1053     _linkkit_solo_mutex_unlock();
1054 
1055     return SUCCESS_RETURN;
1056 }
1057 
linkkit_invoke_raw_service(const void * thing_id,int is_up_raw,void * raw_data,int raw_data_length)1058 int being_deprecated linkkit_invoke_raw_service(const void *thing_id,
1059                                                 int is_up_raw, void *raw_data,
1060                                                 int raw_data_length)
1061 {
1062     int res = 0, devid = 0;
1063     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
1064         _linkkit_solo_legacy_get_ctx();
1065 
1066     if (thing_id == NULL || raw_data == NULL || raw_data_length <= 0) {
1067         impl_solo_err("Invalid Parameter");
1068         return FAIL_RETURN;
1069     }
1070 
1071     if (linkkit_solo_ctx->is_started == 0) {
1072         return FAIL_RETURN;
1073     }
1074 
1075     _linkkit_solo_mutex_lock();
1076     res = iotx_dm_deprecated_legacy_get_devid_by_thingid((void *)thing_id,
1077                                                          &devid);
1078     if (res != SUCCESS_RETURN) {
1079         _linkkit_solo_mutex_unlock();
1080         return FAIL_RETURN;
1081     }
1082 
1083     res = iotx_dm_post_rawdata(devid, raw_data, raw_data_length);
1084     if (res < SUCCESS_RETURN) {
1085         _linkkit_solo_mutex_unlock();
1086         return FAIL_RETURN;
1087     }
1088 
1089     _linkkit_solo_mutex_unlock();
1090 
1091     return SUCCESS_RETURN;
1092 }
1093 
linkkit_trigger_extended_info_operate(const void * thing_id,const char * params,linkkit_extended_info_operate_t linkkit_extended_info_operation)1094 int being_deprecated linkkit_trigger_extended_info_operate(
1095     const void *thing_id, const char *params,
1096     linkkit_extended_info_operate_t linkkit_extended_info_operation)
1097 {
1098     int res = 0, devid = 0;
1099     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
1100         _linkkit_solo_legacy_get_ctx();
1101 
1102     if (thing_id == NULL || params == NULL) {
1103         impl_solo_err("Invalid Parameter");
1104         return FAIL_RETURN;
1105     }
1106 
1107     if (linkkit_solo_ctx->is_started == 0) {
1108         return FAIL_RETURN;
1109     }
1110 
1111     _linkkit_solo_mutex_lock();
1112     res = iotx_dm_deprecated_legacy_get_devid_by_thingid((void *)thing_id,
1113                                                          &devid);
1114     if (res != SUCCESS_RETURN) {
1115         _linkkit_solo_mutex_unlock();
1116         return FAIL_RETURN;
1117     }
1118 
1119     switch (linkkit_extended_info_operation) {
1120     case linkkit_extended_info_operate_update:
1121         {
1122             res = iotx_dm_deviceinfo_update(devid, (char *)params,
1123                                             strlen(params));
1124         }
1125         break;
1126     case linkkit_extended_info_operate_delete:
1127         {
1128             res = iotx_dm_deviceinfo_delete(devid, (char *)params,
1129                                             strlen(params));
1130         }
1131         break;
1132     default:
1133         {
1134             impl_solo_err("Invalid Parameter");
1135             res = FAIL_RETURN;
1136         }
1137         break;
1138     }
1139 
1140     if (res < SUCCESS_RETURN) {
1141         _linkkit_solo_mutex_unlock();
1142         return FAIL_RETURN;
1143     }
1144 
1145     _linkkit_solo_mutex_unlock();
1146 
1147     return SUCCESS_RETURN;
1148 }
1149 
linkkit_trigger_event(const void * thing_id,const char * event_identifier,handle_post_cb_fp_t cb)1150 int being_deprecated linkkit_trigger_event(const void *thing_id,
1151                                            const char *event_identifier,
1152                                            handle_post_cb_fp_t cb)
1153 {
1154     int res = 0, devid = 0, msgid = 0, post_event_reply = 0;
1155     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
1156         _linkkit_solo_legacy_get_ctx();
1157 
1158     if (thing_id == NULL || event_identifier == NULL) {
1159         impl_solo_err("Invalid Parameter");
1160         return FAIL_RETURN;
1161     }
1162 
1163     if (linkkit_solo_ctx->is_started == 0) {
1164         return FAIL_RETURN;
1165     }
1166 
1167     _linkkit_solo_mutex_lock();
1168     res = iotx_dm_deprecated_legacy_get_devid_by_thingid((void *)thing_id,
1169                                                          &devid);
1170     if (res != SUCCESS_RETURN) {
1171         _linkkit_solo_mutex_unlock();
1172         return FAIL_RETURN;
1173     }
1174 
1175     res = iotx_dm_deprecated_post_event(devid, (char *)event_identifier,
1176                                         strlen((char *)event_identifier));
1177     if (res < SUCCESS_RETURN) {
1178         _linkkit_solo_mutex_unlock();
1179         return FAIL_RETURN;
1180     }
1181     msgid = res;
1182 
1183     res = iotx_dm_get_opt(linkkit_opt_event_post_reply, &post_event_reply);
1184     if (cb != NULL && post_event_reply) {
1185         /* Insert Message ID Into Linked List */
1186         _linkkit_solo_upstream_mutex_lock();
1187         res = _linkkit_solo_upstream_callback_list_insert(msgid, cb);
1188         _linkkit_solo_upstream_mutex_unlock();
1189         if (res != SUCCESS_RETURN) {
1190             _linkkit_solo_mutex_unlock();
1191             return FAIL_RETURN;
1192         }
1193     }
1194 
1195     _linkkit_solo_mutex_unlock();
1196 
1197     return SUCCESS_RETURN;
1198 }
1199 
linkkit_post_property(const void * thing_id,const char * property_identifier,handle_post_cb_fp_t cb)1200 int being_deprecated linkkit_post_property(const void *thing_id,
1201                                            const char *property_identifier,
1202                                            handle_post_cb_fp_t cb)
1203 {
1204     int res = 0, devid = 0, msgid = 0, property_identifier_len = 0,
1205         post_property_reply = 0;
1206     void *property_handle = NULL;
1207     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
1208         _linkkit_solo_legacy_get_ctx();
1209 
1210     if (thing_id == NULL) {
1211         impl_solo_err("Invalid Parameter");
1212         return FAIL_RETURN;
1213     }
1214 
1215     if (linkkit_solo_ctx->is_started == 0) {
1216         return FAIL_RETURN;
1217     }
1218 
1219     _linkkit_solo_mutex_lock();
1220     res = iotx_dm_deprecated_legacy_get_devid_by_thingid((void *)thing_id,
1221                                                          &devid);
1222     if (res != SUCCESS_RETURN) {
1223         _linkkit_solo_mutex_unlock();
1224         return FAIL_RETURN;
1225     }
1226 
1227     res = iotx_dm_deprecated_post_property_start(devid, &property_handle);
1228     if (res != SUCCESS_RETURN) {
1229         _linkkit_solo_mutex_unlock();
1230         return FAIL_RETURN;
1231     }
1232 
1233     property_identifier_len =
1234         (property_identifier) ? (strlen((char *)property_identifier)) : (0);
1235     res = iotx_dm_deprecated_post_property_add(
1236         property_handle, (char *)property_identifier, property_identifier_len);
1237     if (res != SUCCESS_RETURN) {
1238         iotx_dm_deprecated_post_property_end(&property_handle);
1239         _linkkit_solo_mutex_unlock();
1240         return FAIL_RETURN;
1241     }
1242 
1243     res = iotx_dm_deprecated_post_property_end(&property_handle);
1244     if (res < SUCCESS_RETURN) {
1245         _linkkit_solo_mutex_unlock();
1246         return FAIL_RETURN;
1247     }
1248     msgid = res;
1249 
1250     res =
1251         iotx_dm_get_opt(linkkit_opt_property_post_reply, &post_property_reply);
1252     if (cb != NULL && post_property_reply) {
1253         /* Insert Message ID Into Linked List */
1254         _linkkit_solo_upstream_mutex_lock();
1255         res = _linkkit_solo_upstream_callback_list_insert(msgid, cb);
1256         _linkkit_solo_upstream_mutex_unlock();
1257         if (res != SUCCESS_RETURN) {
1258             _linkkit_solo_mutex_unlock();
1259             return FAIL_RETURN;
1260         }
1261     }
1262 
1263     _linkkit_solo_mutex_unlock();
1264 
1265     return SUCCESS_RETURN;
1266 }
1267 
linkkit_yield(int timeout_ms)1268 int being_deprecated linkkit_yield(int timeout_ms)
1269 {
1270     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
1271         _linkkit_solo_legacy_get_ctx();
1272 
1273     if (timeout_ms <= 0) {
1274         impl_solo_err("Invalid Parameter");
1275         return FAIL_RETURN;
1276     }
1277 
1278     if (linkkit_solo_ctx->is_started == 0) {
1279         return FAIL_RETURN;
1280     }
1281 
1282     return iotx_dm_yield(timeout_ms);
1283 }
1284 
1285 int being_deprecated
linkkit_cota_init(handle_service_cota_callback_fp_t callback_fp)1286 linkkit_cota_init(handle_service_cota_callback_fp_t callback_fp)
1287 {
1288     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
1289         _linkkit_solo_legacy_get_ctx();
1290 
1291     if (linkkit_solo_ctx->is_started == 0) {
1292         return FAIL_RETURN;
1293     }
1294 
1295     linkkit_solo_ctx->cota_callback = callback_fp;
1296 
1297     return SUCCESS_RETURN;
1298 }
1299 
linkkit_invoke_cota_service(void * data_buf,int data_buf_length)1300 int being_deprecated linkkit_invoke_cota_service(void *data_buf,
1301                                                  int data_buf_length)
1302 {
1303     int res = 0;
1304     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
1305         _linkkit_solo_legacy_get_ctx();
1306 
1307     if (data_buf == NULL || data_buf_length <= 0) {
1308         impl_solo_err("Invalid Parameter");
1309         return FAIL_RETURN;
1310     }
1311 
1312     if (linkkit_solo_ctx->is_started == 0) {
1313         return FAIL_RETURN;
1314     }
1315 
1316     _linkkit_solo_mutex_lock();
1317     res = iotx_dm_cota_perform_sync(data_buf, data_buf_length);
1318     _linkkit_solo_mutex_unlock();
1319 
1320     return res;
1321 }
1322 
linkkit_invoke_cota_get_config(const char * config_scope,const char * get_type,const char * attribute_Keys,void * option)1323 int being_deprecated linkkit_invoke_cota_get_config(const char *config_scope,
1324                                                     const char *get_type,
1325                                                     const char *attribute_Keys,
1326                                                     void *option)
1327 {
1328     int res = 0;
1329     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
1330         _linkkit_solo_legacy_get_ctx();
1331 
1332     if (config_scope == NULL || get_type == NULL || attribute_Keys == NULL) {
1333         impl_solo_err("Invalid Parameter");
1334         return FAIL_RETURN;
1335     }
1336 
1337     if (linkkit_solo_ctx->is_started == 0) {
1338         return FAIL_RETURN;
1339     }
1340 
1341     _linkkit_solo_mutex_lock();
1342     res = iotx_dm_cota_get_config(config_scope, get_type, attribute_Keys);
1343     _linkkit_solo_mutex_unlock();
1344 
1345     return res;
1346 }
1347 
1348 int being_deprecated
linkkit_fota_init(handle_service_fota_callback_fp_t callback_fp)1349 linkkit_fota_init(handle_service_fota_callback_fp_t callback_fp)
1350 {
1351     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
1352         _linkkit_solo_legacy_get_ctx();
1353 
1354     if (linkkit_solo_ctx->is_started == 0) {
1355         return FAIL_RETURN;
1356     }
1357 
1358     linkkit_solo_ctx->fota_callback = callback_fp;
1359 
1360     return SUCCESS_RETURN;
1361 }
1362 
linkkit_invoke_fota_service(void * data_buf,int data_buf_length)1363 int being_deprecated linkkit_invoke_fota_service(void *data_buf,
1364                                                  int data_buf_length)
1365 {
1366     int res = 0;
1367     linkkit_solo_legacy_ctx_t *linkkit_solo_ctx =
1368         _linkkit_solo_legacy_get_ctx();
1369 
1370     if (data_buf == NULL || data_buf_length <= 0) {
1371         impl_solo_err("Invalid Parameter");
1372         return FAIL_RETURN;
1373     }
1374 
1375     if (linkkit_solo_ctx->is_started == 0) {
1376         return FAIL_RETURN;
1377     }
1378 
1379     _linkkit_solo_mutex_lock();
1380     res = iotx_dm_fota_perform_sync(data_buf, data_buf_length);
1381     _linkkit_solo_mutex_unlock();
1382 
1383     return res;
1384 }
1385 #endif
1386