1 #include "iotx_dm_internal.h"
2
3 #ifdef DEV_BIND_ENABLED
4 #include "linkkit/dev_bind_api.h"
5 #endif
6 #ifdef LOG_REPORT_TO_CLOUD
7 #include "iotx_log_report.h"
8 #endif
9
10 static dm_client_uri_map_t g_dm_client_uri_map[] = {
11 #if !defined(DEVICE_MODEL_RAWDATA_SOLO)
12 { DM_URI_THING_EVENT_POST_REPLY_WILDCARD, DM_URI_SYS_PREFIX,
13 IOTX_DM_DEVICE_ALL, (void *)dm_client_thing_event_post_reply },
14 #ifdef DEVICE_MODEL_SHADOW
15 { DM_URI_THING_PROPERTY_DESIRED_DELETE_REPLY, DM_URI_SYS_PREFIX,
16 IOTX_DM_DEVICE_ALL,
17 (void *)dm_client_thing_property_desired_delete_reply },
18 { DM_URI_THING_PROPERTY_DESIRED_GET_REPLY, DM_URI_SYS_PREFIX,
19 IOTX_DM_DEVICE_ALL, (void *)dm_client_thing_property_desired_get_reply },
20 { DM_URI_THING_SERVICE_PROPERTY_GET, DM_URI_SYS_PREFIX, IOTX_DM_DEVICE_ALL,
21 (void *)dm_client_thing_service_property_get },
22 #endif
23 { DM_URI_THING_SERVICE_PROPERTY_SET, DM_URI_SYS_PREFIX, IOTX_DM_DEVICE_ALL,
24 (void *)dm_client_thing_service_property_set },
25 { DM_URI_THING_SERVICE_REQUEST_WILDCARD, DM_URI_SYS_PREFIX,
26 IOTX_DM_DEVICE_ALL, (void *)dm_client_thing_service_request },
27 { DM_URI_THING_DEVICEINFO_UPDATE_REPLY, DM_URI_SYS_PREFIX,
28 IOTX_DM_DEVICE_ALL, (void *)dm_client_thing_deviceinfo_update_reply },
29 { DM_URI_THING_DEVICEINFO_DELETE_REPLY, DM_URI_SYS_PREFIX,
30 IOTX_DM_DEVICE_ALL, (void *)dm_client_thing_deviceinfo_delete_reply },
31 { DM_URI_THING_DYNAMICTSL_GET_REPLY, DM_URI_SYS_PREFIX, IOTX_DM_DEVICE_ALL,
32 (void *)dm_client_thing_dynamictsl_get_reply },
33 { DM_URI_THING_EVENT_NOTIFY, DM_URI_SYS_PREFIX, IOTX_DM_DEVICE_ALL,
34 (void *)dm_client_thing_event_notify },
35 { DM_URI_RRPC_REQUEST_WILDCARD, DM_URI_SYS_PREFIX, IOTX_DM_DEVICE_ALL,
36 (void *)dm_client_rrpc_request_wildcard },
37 // {DM_URI_NTP_RESPONSE, DM_URI_EXT_NTP_PREFIX,
38 // IOTX_DM_DEVICE_ALL, (void *)dm_client_ntp_response },
39 { NULL, DM_URI_EXT_ERROR_PREFIX, IOTX_DM_DEVICE_ALL,
40 (void *)dm_client_ext_error },
41 #endif
42 { DM_URI_THING_MODEL_DOWN_RAW, DM_URI_SYS_PREFIX, IOTX_DM_DEVICE_ALL,
43 (void *)dm_client_thing_model_down_raw },
44 { DM_URI_THING_MODEL_UP_RAW_REPLY, DM_URI_SYS_PREFIX, IOTX_DM_DEVICE_ALL,
45 (void *)dm_client_thing_model_up_raw_reply },
46
47 #ifdef DEVICE_MODEL_GATEWAY
48 { DM_URI_THING_TOPO_ADD_NOTIFY, DM_URI_SYS_PREFIX, IOTX_DM_DEVICE_GATEWAY,
49 (void *)dm_client_thing_topo_add_notify },
50 { DM_URI_THING_GATEWAY_PERMIT, DM_URI_SYS_PREFIX, IOTX_DM_DEVICE_GATEWAY,
51 (void *)dm_client_thing_gateway_permit },
52 { DM_URI_THING_SUB_REGISTER_REPLY, DM_URI_SYS_PREFIX,
53 IOTX_DM_DEVICE_GATEWAY, (void *)dm_client_thing_sub_register_reply },
54 { DM_URI_THING_PROXY_PRODUCT_REGISTER_REPLY, DM_URI_SYS_PREFIX,
55 IOTX_DM_DEVICE_GATEWAY,
56 (void *)dm_client_thing_proxy_product_register_reply },
57 { DM_URI_THING_SUB_UNREGISTER_REPLY, DM_URI_SYS_PREFIX,
58 IOTX_DM_DEVICE_GATEWAY, (void *)dm_client_thing_sub_unregister_reply },
59 { DM_URI_THING_TOPO_ADD_REPLY, DM_URI_SYS_PREFIX, IOTX_DM_DEVICE_GATEWAY,
60 (void *)dm_client_thing_topo_add_reply },
61 { DM_URI_THING_TOPO_DELETE_REPLY, DM_URI_SYS_PREFIX, IOTX_DM_DEVICE_GATEWAY,
62 (void *)dm_client_thing_topo_delete_reply },
63 { DM_URI_THING_TOPO_GET_REPLY, DM_URI_SYS_PREFIX, IOTX_DM_DEVICE_GATEWAY,
64 (void *)dm_client_thing_topo_get_reply },
65 { DM_URI_THING_LIST_FOUND_REPLY, DM_URI_SYS_PREFIX, IOTX_DM_DEVICE_GATEWAY,
66 (void *)dm_client_thing_list_found_reply },
67 { DM_URI_COMBINE_LOGIN_REPLY, DM_URI_EXT_SESSION_PREFIX,
68 IOTX_DM_DEVICE_GATEWAY, (void *)dm_client_combine_login_reply },
69 { DM_URI_COMBINE_LOGOUT_REPLY, DM_URI_EXT_SESSION_PREFIX,
70 IOTX_DM_DEVICE_GATEWAY, (void *)dm_client_combine_logout_reply },
71 { DM_URI_THING_DISABLE, DM_URI_SYS_PREFIX, IOTX_DM_DEVICE_GATEWAY,
72 (void *)dm_client_thing_disable },
73 { DM_URI_THING_ENABLE, DM_URI_SYS_PREFIX, IOTX_DM_DEVICE_GATEWAY,
74 (void *)dm_client_thing_enable },
75 { DM_URI_THING_DELETE, DM_URI_SYS_PREFIX, IOTX_DM_DEVICE_GATEWAY,
76 (void *)dm_client_thing_delete },
77 #endif
78 };
79
80 #if !defined(DEVICE_MODEL_RAWDATA_SOLO)
81 /* property/event post reply filter */
_dm_client_subscribe_filter(char * uri,iotx_cm_data_handle_cb cb)82 static int _dm_client_subscribe_filter(char *uri, iotx_cm_data_handle_cb cb)
83 {
84 int res = 0;
85 int event_post_reply_opt = 0;
86 int retry_cnt = IOTX_DM_CLIENT_SUB_RETRY_MAX_COUNTS;
87
88 res = dm_opt_get(DM_OPT_DOWNSTREAM_EVENT_POST_REPLY, &event_post_reply_opt);
89 if (res != SUCCESS_RETURN) {
90 return FAIL_RETURN;
91 }
92
93 if (event_post_reply_opt == 0) {
94 res = dm_client_unsubscribe(uri);
95 return (res >= 0) ? SUCCESS_RETURN : FAIL_RETURN;
96 } else {
97 res = FAIL_RETURN;
98 while (res < SUCCESS_RETURN && retry_cnt--) {
99 res = dm_client_subscribe(uri, cb, 0);
100 }
101 return res;
102 }
103 }
104 #endif /* #if !defined(DEVICE_MODEL_RAWDATA_SOLO) */
105
dm_client_subscribe_all(int devid,char product_key[IOTX_PRODUCT_KEY_LEN+1],char device_name[IOTX_DEVICE_NAME_LEN+1],int dev_type)106 int dm_client_subscribe_all(int devid,
107 char product_key[IOTX_PRODUCT_KEY_LEN + 1],
108 char device_name[IOTX_DEVICE_NAME_LEN + 1],
109 int dev_type)
110 {
111 int res = 0, index = 0;
112 int number = sizeof(g_dm_client_uri_map) / sizeof(dm_client_uri_map_t);
113 char *uri = NULL;
114 uint8_t local_sub = 0;
115
116 #if !defined(DEVICE_MODEL_RAWDATA_SOLO)
117 /* index 0 must be DM_URI_THING_EVENT_POST_REPLY_WILDCARD */
118 res = dm_utils_service_name((char *)g_dm_client_uri_map[0].uri_prefix,
119 (char *)g_dm_client_uri_map[0].uri_name,
120 product_key, device_name, &uri);
121 if (res == SUCCESS_RETURN) {
122 _dm_client_subscribe_filter(
123 uri, (iotx_cm_data_handle_cb)g_dm_client_uri_map[0].callback);
124 DM_free(uri);
125 }
126 index = 1;
127 #else
128 index = 0;
129 #endif
130
131 #ifdef MQTT_AUTO_SUBSCRIBE
132 if (devid != 0) {
133 dm_log_info("Devid %d bypass Subscribe", devid);
134 return SUCCESS_RETURN;
135 }
136 #else
137 (void)devid;
138 #endif /* #ifdef MQTT_AUTO_SUBSCRIBE */
139
140 for (; index < number; index++) {
141 if ((g_dm_client_uri_map[index].dev_type & dev_type) == 0) {
142 continue;
143 }
144 dm_log_info("index: %d", index);
145
146 #ifdef MQTT_AUTO_SUBSCRIBE
147 res = dm_utils_service_name(
148 (char *)g_dm_client_uri_map[index].uri_prefix,
149 (char *)g_dm_client_uri_map[index].uri_name, "+", "+",
150 &uri); /* plus sign wildcards used */
151 if (res < SUCCESS_RETURN) {
152 continue;
153 }
154
155 local_sub = 1;
156 res = dm_client_subscribe(
157 uri, (iotx_cm_data_handle_cb)g_dm_client_uri_map[index].callback,
158 &local_sub);
159 DM_free(uri);
160 #else
161 res =
162 dm_utils_service_name((char *)g_dm_client_uri_map[index].uri_prefix,
163 (char *)g_dm_client_uri_map[index].uri_name,
164 product_key, device_name, &uri);
165 if (res < SUCCESS_RETURN) {
166 continue;
167 }
168
169 {
170 int retry_cnt = IOTX_DM_CLIENT_SUB_RETRY_MAX_COUNTS;
171 local_sub = 0;
172 do {
173 res = dm_client_subscribe(
174 uri,
175 (iotx_cm_data_handle_cb)g_dm_client_uri_map[index].callback,
176 &local_sub);
177 } while (res < SUCCESS_RETURN && --retry_cnt);
178 DM_free(uri);
179 }
180 #endif /* MQTT_AUTO_SUBSCRIBE */
181 }
182
183 return SUCCESS_RETURN;
184 }
185
_dm_client_event_cloud_connected_handle(void)186 static void _dm_client_event_cloud_connected_handle(void)
187 {
188 dm_log_info("IOTX_CM_EVENT_CLOUD_CONNECTED");
189 dm_msg_cloud_connected();
190 }
191
_dm_client_event_cloud_disconnect_handle(void)192 static void _dm_client_event_cloud_disconnect_handle(void)
193 {
194 dm_log_info("IOTX_CM_EVENT_CLOUD_DISCONNECT");
195
196 dm_msg_cloud_disconnect();
197 }
198
dm_client_event_handle(int fd,iotx_cm_event_msg_t * event,void * context)199 void dm_client_event_handle(int fd, iotx_cm_event_msg_t *event, void *context)
200 {
201 switch (event->type) {
202 case IOTX_CM_EVENT_CLOUD_CONNECTED:
203 {
204 _dm_client_event_cloud_connected_handle();
205 }
206 break;
207 case IOTX_CM_EVENT_CLOUD_CONNECT_FAILED:
208 {
209 }
210 break;
211 case IOTX_CM_EVENT_CLOUD_DISCONNECT:
212 {
213 _dm_client_event_cloud_disconnect_handle();
214 }
215 break;
216 default:
217 break;
218 }
219 }
220
dm_client_thing_event_notify(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)221 void dm_client_thing_event_notify(int fd, const char *topic,
222 const char *payload, unsigned int payload_len,
223 void *context)
224 {
225 int res = 0;
226 dm_msg_source_t source;
227 dm_msg_dest_t dest;
228 dm_msg_request_payload_t request;
229 dm_msg_response_t response;
230
231 memset(&source, 0, sizeof(dm_msg_source_t));
232 memset(&dest, 0, sizeof(dm_msg_dest_t));
233 memset(&request, 0, sizeof(dm_msg_request_payload_t));
234 memset(&response, 0, sizeof(dm_msg_response_t));
235
236 source.uri = topic;
237 source.payload = (unsigned char *)payload;
238 source.payload_len = payload_len;
239 source.context = NULL;
240
241 dest.uri_name = DM_URI_THING_EVENT_NOTIFY_REPLY;
242
243 res = dm_msg_proc_thing_event_notify(&source, &dest, &request, &response);
244 if (res < SUCCESS_RETURN) {
245 return;
246 }
247
248 int event_notify_reply_opt = 0;
249 res =
250 dm_opt_get(DM_OPT_UPSTREAM_EVENT_NOTIFY_REPLY, &event_notify_reply_opt);
251 if (res == SUCCESS_RETURN) {
252 if (event_notify_reply_opt) {
253 dm_msg_response(DM_MSG_DEST_CLOUD, &request, &response, "{}",
254 strlen("{}"), NULL);
255 #ifdef LOG_REPORT_TO_CLOUD
256 if (SUCCESS_RETURN ==
257 check_target_msg(request.id.value, request.id.value_length)) {
258 send_permance_info(request.id.value, request.id.value_length,
259 "2", 1);
260 }
261 #endif
262 }
263 }
264 }
265
dm_client_thing_model_down_raw(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)266 void dm_client_thing_model_down_raw(int fd, const char *topic,
267 const char *payload,
268 unsigned int payload_len, void *context)
269 {
270 dm_msg_source_t source;
271
272 memset(&source, 0, sizeof(dm_msg_source_t));
273
274 source.uri = topic;
275 source.payload = (unsigned char *)payload;
276 source.payload_len = payload_len;
277 source.context = NULL;
278
279 dm_msg_proc_thing_model_down_raw(&source);
280 }
281
dm_client_thing_model_up_raw_reply(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)282 void dm_client_thing_model_up_raw_reply(int fd, const char *topic,
283 const char *payload,
284 unsigned int payload_len, void *context)
285 {
286 dm_msg_source_t source;
287
288 memset(&source, 0, sizeof(dm_msg_source_t));
289
290 source.uri = topic;
291 source.payload = (unsigned char *)payload;
292 source.payload_len = payload_len;
293 source.context = NULL;
294
295 dm_msg_proc_thing_model_up_raw_reply(&source);
296 }
297 #if !defined(DEVICE_MODEL_RAWDATA_SOLO)
dm_client_thing_service_property_set(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)298 void dm_client_thing_service_property_set(int fd, const char *topic,
299 const char *payload,
300 unsigned int payload_len,
301 void *context)
302 {
303 int res = 0;
304 dm_msg_source_t source;
305 dm_msg_dest_t dest;
306 dm_msg_request_payload_t request;
307 dm_msg_response_t response;
308 int prop_set_reply_opt = 0;
309
310 memset(&source, 0, sizeof(dm_msg_source_t));
311 memset(&dest, 0, sizeof(dm_msg_dest_t));
312 memset(&request, 0, sizeof(dm_msg_request_payload_t));
313 memset(&response, 0, sizeof(dm_msg_response_t));
314
315 source.uri = topic;
316 source.payload = (unsigned char *)payload;
317 source.payload_len = payload_len;
318 source.context = NULL;
319
320 dest.uri_name = DM_URI_THING_SERVICE_PROPERTY_SET_REPLY;
321
322 res = dm_msg_proc_thing_service_property_set(&source, &dest, &request,
323 &response);
324 if (res < SUCCESS_RETURN) {
325 return;
326 }
327
328 prop_set_reply_opt = 0;
329 res = dm_opt_get(DM_OPT_UPSTREAM_PROPERTY_SET_REPLY, &prop_set_reply_opt);
330 if (res == SUCCESS_RETURN) {
331 if (prop_set_reply_opt) {
332 dm_msg_response(DM_MSG_DEST_CLOUD, &request, &response, "{}",
333 strlen("{}"), NULL);
334 #ifdef LOG_REPORT_TO_CLOUD
335 if (SUCCESS_RETURN ==
336 check_target_msg(request.id.value, request.id.value_length)) {
337 send_permance_info(request.id.value, request.id.value_length,
338 "2", 1);
339 }
340 #endif
341 }
342 }
343 }
344
345 #ifdef DEVICE_MODEL_SHADOW
dm_client_thing_service_property_get(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)346 void dm_client_thing_service_property_get(int fd, const char *topic,
347 const char *payload,
348 unsigned int payload_len,
349 void *context)
350 {
351 int res = 0;
352 dm_msg_source_t source;
353 dm_msg_dest_t dest;
354 dm_msg_request_payload_t request;
355 dm_msg_response_t response;
356 unsigned char *data = NULL;
357 int data_len = 0;
358
359 memset(&source, 0, sizeof(dm_msg_source_t));
360 memset(&dest, 0, sizeof(dm_msg_dest_t));
361 memset(&request, 0, sizeof(dm_msg_request_payload_t));
362 memset(&response, 0, sizeof(dm_msg_response_t));
363
364 source.uri = topic;
365 source.payload = (unsigned char *)payload;
366 source.payload_len = payload_len;
367 source.context = NULL;
368
369 dest.uri_name = DM_URI_THING_SERVICE_PROPERTY_GET_REPLY;
370
371 res = dm_msg_proc_thing_service_property_get(&source, &dest, &request,
372 &response, &data, &data_len);
373 if (res < SUCCESS_RETURN) {
374 return;
375 }
376 }
377 #endif
378
dm_client_thing_service_request(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)379 void dm_client_thing_service_request(int fd, const char *topic,
380 const char *payload,
381 unsigned int payload_len, void *context)
382 {
383 dm_msg_source_t source;
384
385 memset(&source, 0, sizeof(dm_msg_source_t));
386
387 source.uri = topic;
388 source.payload = (unsigned char *)payload;
389 source.payload_len = payload_len;
390 source.context = NULL;
391
392 dm_msg_proc_thing_service_request(&source);
393 }
394
dm_client_thing_event_post_reply(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)395 void dm_client_thing_event_post_reply(int fd, const char *topic,
396 const char *payload,
397 unsigned int payload_len, void *context)
398 {
399 dm_msg_source_t source;
400
401 memset(&source, 0, sizeof(dm_msg_source_t));
402
403 source.uri = topic;
404 source.payload = (unsigned char *)payload;
405 source.payload_len = payload_len;
406 source.context = NULL;
407
408 dm_msg_proc_thing_event_post_reply(&source);
409 }
410 #ifdef DEVICE_MODEL_SHADOW
dm_client_thing_property_desired_get_reply(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)411 void dm_client_thing_property_desired_get_reply(int fd, const char *topic,
412 const char *payload,
413 unsigned int payload_len,
414 void *context)
415 {
416 dm_msg_source_t source;
417
418 memset(&source, 0, sizeof(dm_msg_source_t));
419
420 source.uri = topic;
421 source.payload = (unsigned char *)payload;
422 source.payload_len = payload_len;
423 source.context = NULL;
424
425 dm_msg_proc_thing_property_desired_get_reply(&source);
426 }
427
dm_client_thing_property_desired_delete_reply(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)428 void dm_client_thing_property_desired_delete_reply(int fd, const char *topic,
429 const char *payload,
430 unsigned int payload_len,
431 void *context)
432 {
433 dm_msg_source_t source;
434
435 memset(&source, 0, sizeof(dm_msg_source_t));
436
437 source.uri = topic;
438 source.payload = (unsigned char *)payload;
439 source.payload_len = payload_len;
440 source.context = NULL;
441
442 dm_msg_proc_thing_property_desired_delete_reply(&source);
443 }
444 #endif
445
dm_client_thing_deviceinfo_update_reply(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)446 void dm_client_thing_deviceinfo_update_reply(int fd, const char *topic,
447 const char *payload,
448 unsigned int payload_len,
449 void *context)
450 {
451 dm_msg_source_t source;
452
453 memset(&source, 0, sizeof(dm_msg_source_t));
454
455 source.uri = topic;
456 source.payload = (unsigned char *)payload;
457 source.payload_len = payload_len;
458 source.context = NULL;
459
460 dm_msg_proc_thing_deviceinfo_update_reply(&source);
461 }
462
dm_client_thing_deviceinfo_delete_reply(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)463 void dm_client_thing_deviceinfo_delete_reply(int fd, const char *topic,
464 const char *payload,
465 unsigned int payload_len,
466 void *context)
467 {
468 dm_msg_source_t source;
469
470 memset(&source, 0, sizeof(dm_msg_source_t));
471
472 source.uri = topic;
473 source.payload = (unsigned char *)payload;
474 source.payload_len = payload_len;
475 source.context = NULL;
476
477 dm_msg_proc_thing_deviceinfo_delete_reply(&source);
478 }
479
dm_client_thing_dynamictsl_get_reply(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)480 void dm_client_thing_dynamictsl_get_reply(int fd, const char *topic,
481 const char *payload,
482 unsigned int payload_len,
483 void *context)
484 {
485 dm_msg_source_t source;
486
487 memset(&source, 0, sizeof(dm_msg_source_t));
488
489 source.uri = topic;
490 source.payload = (unsigned char *)payload;
491 source.payload_len = payload_len;
492 source.context = NULL;
493
494 dm_msg_proc_thing_dynamictsl_get_reply(&source);
495 }
496
dm_client_rrpc_request_wildcard(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)497 void dm_client_rrpc_request_wildcard(int fd, const char *topic,
498 const char *payload,
499 unsigned int payload_len, void *context)
500 {
501 dm_msg_source_t source;
502
503 memset(&source, 0, sizeof(dm_msg_source_t));
504
505 source.uri = topic;
506 source.payload = (unsigned char *)payload;
507 source.payload_len = payload_len;
508 source.context = NULL;
509
510 dm_msg_proc_rrpc_request(&source);
511 }
512
dm_client_ntp_response(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)513 void dm_client_ntp_response(int fd, const char *topic, const char *payload,
514 unsigned int payload_len, void *context)
515 {
516 dm_msg_source_t source;
517
518 memset(&source, 0, sizeof(dm_msg_source_t));
519
520 source.uri = topic;
521 source.payload = (unsigned char *)payload;
522 source.payload_len = payload_len;
523 source.context = NULL;
524
525 dm_disp_ntp_response(&source);
526 }
527
dm_client_ext_error(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)528 void dm_client_ext_error(int fd, const char *topic, const char *payload,
529 unsigned int payload_len, void *context)
530 {
531 dm_msg_source_t source;
532
533 memset(&source, 0, sizeof(dm_msg_source_t));
534
535 source.uri = topic;
536 source.payload = (unsigned char *)payload;
537 source.payload_len = payload_len;
538 source.context = NULL;
539
540 dm_disp_ext_error_response(&source);
541 }
542 #endif
543
544 #ifdef DEVICE_MODEL_GATEWAY
dm_client_subdev_unsubscribe(char product_key[IOTX_PRODUCT_KEY_LEN+1],char device_name[IOTX_DEVICE_NAME_LEN+1])545 int dm_client_subdev_unsubscribe(char product_key[IOTX_PRODUCT_KEY_LEN + 1],
546 char device_name[IOTX_DEVICE_NAME_LEN + 1])
547 {
548 int res = 0, index = 0;
549 int number = sizeof(g_dm_client_uri_map) / sizeof(dm_client_uri_map_t);
550 char *uri = NULL;
551
552 for (index = 0; index < number; index++) {
553 if ((g_dm_client_uri_map[index].dev_type & IOTX_DM_DEVICE_SUBDEV) ==
554 0) {
555 continue;
556 }
557
558 res =
559 dm_utils_service_name((char *)g_dm_client_uri_map[index].uri_prefix,
560 (char *)g_dm_client_uri_map[index].uri_name,
561 product_key, device_name, &uri);
562 if (res < SUCCESS_RETURN) {
563 index--;
564 continue;
565 }
566
567 dm_client_unsubscribe(uri);
568 DM_free(uri);
569 }
570
571 return SUCCESS_RETURN;
572 }
573
dm_client_thing_topo_add_notify(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)574 void dm_client_thing_topo_add_notify(int fd, const char *topic,
575 const char *payload,
576 unsigned int payload_len, void *context)
577 {
578 int res = 0;
579 dm_msg_source_t source;
580 dm_msg_dest_t dest;
581 dm_msg_request_payload_t request;
582 dm_msg_response_t response;
583
584 memset(&source, 0, sizeof(dm_msg_source_t));
585 memset(&dest, 0, sizeof(dm_msg_dest_t));
586 memset(&request, 0, sizeof(dm_msg_request_payload_t));
587 memset(&response, 0, sizeof(dm_msg_response_t));
588
589 source.uri = topic;
590 source.payload = (unsigned char *)payload;
591 source.payload_len = payload_len;
592 source.context = NULL;
593
594 dest.uri_name = DM_URI_THING_TOPO_ADD_NOTIFY_REPLY;
595
596 res =
597 dm_msg_proc_thing_topo_add_notify(&source, &dest, &request, &response);
598 if (res < SUCCESS_RETURN) {
599 return;
600 }
601
602 dm_msg_response(DM_MSG_DEST_CLOUD, &request, &response, "{}", strlen("{}"),
603 NULL);
604 }
605
dm_client_thing_disable(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)606 void dm_client_thing_disable(int fd, const char *topic, const char *payload,
607 unsigned int payload_len, void *context)
608 {
609 int res = 0;
610 dm_msg_source_t source;
611 dm_msg_dest_t dest;
612 dm_msg_request_payload_t request;
613 dm_msg_response_t response;
614
615 memset(&source, 0, sizeof(dm_msg_source_t));
616 memset(&dest, 0, sizeof(dm_msg_dest_t));
617 memset(&request, 0, sizeof(dm_msg_request_payload_t));
618 memset(&response, 0, sizeof(dm_msg_response_t));
619
620 source.uri = topic;
621 source.payload = (unsigned char *)payload;
622 source.payload_len = payload_len;
623 source.context = NULL;
624
625 dest.uri_name = DM_URI_THING_DISABLE_REPLY;
626
627 res = dm_msg_proc_thing_disable(&source, &dest, &request, &response);
628 if (res < SUCCESS_RETURN) {
629 return;
630 }
631
632 dm_msg_response(DM_MSG_DEST_CLOUD, &request, &response, "{}", strlen("{}"),
633 NULL);
634 }
635
dm_client_thing_enable(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)636 void dm_client_thing_enable(int fd, const char *topic, const char *payload,
637 unsigned int payload_len, void *context)
638 {
639 int res = 0;
640 dm_msg_source_t source;
641 dm_msg_dest_t dest;
642 dm_msg_request_payload_t request;
643 dm_msg_response_t response;
644
645 memset(&source, 0, sizeof(dm_msg_source_t));
646 memset(&dest, 0, sizeof(dm_msg_dest_t));
647 memset(&request, 0, sizeof(dm_msg_request_payload_t));
648 memset(&response, 0, sizeof(dm_msg_response_t));
649
650 source.uri = topic;
651 source.payload = (unsigned char *)payload;
652 source.payload_len = payload_len;
653 source.context = NULL;
654
655 dest.uri_name = DM_URI_THING_ENABLE_REPLY;
656
657 res = dm_msg_proc_thing_enable(&source, &dest, &request, &response);
658 if (res < SUCCESS_RETURN) {
659 return;
660 }
661
662 dm_msg_response(DM_MSG_DEST_CLOUD, &request, &response, "{}", strlen("{}"),
663 NULL);
664 }
665
dm_client_thing_delete(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)666 void dm_client_thing_delete(int fd, const char *topic, const char *payload,
667 unsigned int payload_len, void *context)
668 {
669 int res = 0;
670 dm_msg_source_t source;
671 dm_msg_dest_t dest;
672 dm_msg_request_payload_t request;
673 dm_msg_response_t response;
674
675 memset(&source, 0, sizeof(dm_msg_source_t));
676 memset(&dest, 0, sizeof(dm_msg_dest_t));
677 memset(&request, 0, sizeof(dm_msg_request_payload_t));
678 memset(&response, 0, sizeof(dm_msg_response_t));
679
680 source.uri = topic;
681 source.payload = (unsigned char *)payload;
682 source.payload_len = payload_len;
683 source.context = NULL;
684
685 dest.uri_name = DM_URI_THING_DELETE_REPLY;
686
687 res = dm_msg_proc_thing_delete(&source, &dest, &request, &response);
688 if (res < SUCCESS_RETURN) {
689 return;
690 }
691
692 dm_msg_response(DM_MSG_DEST_CLOUD, &request, &response, "{}", strlen("{}"),
693 NULL);
694 }
695
dm_client_thing_gateway_permit(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)696 void dm_client_thing_gateway_permit(int fd, const char *topic,
697 const char *payload,
698 unsigned int payload_len, void *context)
699 {
700 int res = 0;
701 dm_msg_source_t source;
702 dm_msg_dest_t dest;
703 dm_msg_request_payload_t request;
704 dm_msg_response_t response;
705
706 memset(&source, 0, sizeof(dm_msg_source_t));
707 memset(&dest, 0, sizeof(dm_msg_dest_t));
708 memset(&request, 0, sizeof(dm_msg_request_payload_t));
709 memset(&response, 0, sizeof(dm_msg_response_t));
710
711 source.uri = topic;
712 source.payload = (unsigned char *)payload;
713 source.payload_len = payload_len;
714 source.context = NULL;
715
716 dest.uri_name = DM_URI_THING_GATEWAY_PERMIT_REPLY;
717
718 res = dm_msg_proc_thing_gateway_permit(&source, &dest, &request, &response);
719 if (res < SUCCESS_RETURN) {
720 return;
721 }
722
723 dm_msg_response(DM_MSG_DEST_CLOUD, &request, &response, "{}", strlen("{}"),
724 NULL);
725 }
726
dm_client_thing_sub_register_reply(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)727 void dm_client_thing_sub_register_reply(int fd, const char *topic,
728 const char *payload,
729 unsigned int payload_len, void *context)
730 {
731 dm_msg_source_t source;
732
733 memset(&source, 0, sizeof(dm_msg_source_t));
734
735 source.uri = topic;
736 source.payload = (unsigned char *)payload;
737 source.payload_len = payload_len;
738 source.context = NULL;
739
740 dm_msg_proc_thing_sub_register_reply(&source);
741 }
742
dm_client_thing_proxy_product_register_reply(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)743 void dm_client_thing_proxy_product_register_reply(int fd, const char *topic,
744 const char *payload,
745 unsigned int payload_len,
746 void *context)
747 {
748 dm_msg_source_t source;
749
750 memset(&source, 0, sizeof(dm_msg_source_t));
751
752 source.uri = topic;
753 source.payload = (unsigned char *)payload;
754 source.payload_len = payload_len;
755 source.context = NULL;
756
757 dm_msg_proc_thing_proxy_product_register_reply(&source);
758 }
759
dm_client_thing_sub_unregister_reply(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)760 void dm_client_thing_sub_unregister_reply(int fd, const char *topic,
761 const char *payload,
762 unsigned int payload_len,
763 void *context)
764 {
765 dm_msg_source_t source;
766
767 memset(&source, 0, sizeof(dm_msg_source_t));
768
769 source.uri = topic;
770 source.payload = (unsigned char *)payload;
771 source.payload_len = payload_len;
772 source.context = NULL;
773
774 dm_msg_proc_thing_sub_unregister_reply(&source);
775 }
776
dm_client_thing_topo_add_reply(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)777 void dm_client_thing_topo_add_reply(int fd, const char *topic,
778 const char *payload,
779 unsigned int payload_len, void *context)
780 {
781 dm_msg_source_t source;
782
783 memset(&source, 0, sizeof(dm_msg_source_t));
784
785 source.uri = topic;
786 source.payload = (unsigned char *)payload;
787 source.payload_len = payload_len;
788 source.context = NULL;
789
790 dm_msg_proc_thing_topo_add_reply(&source);
791 }
792
dm_client_thing_topo_delete_reply(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)793 void dm_client_thing_topo_delete_reply(int fd, const char *topic,
794 const char *payload,
795 unsigned int payload_len, void *context)
796 {
797 dm_msg_source_t source;
798
799 memset(&source, 0, sizeof(dm_msg_source_t));
800
801 source.uri = topic;
802 source.payload = (unsigned char *)payload;
803 source.payload_len = payload_len;
804 source.context = NULL;
805
806 dm_msg_proc_thing_topo_delete_reply(&source);
807 }
808
dm_client_thing_topo_get_reply(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)809 void dm_client_thing_topo_get_reply(int fd, const char *topic,
810 const char *payload,
811 unsigned int payload_len, void *context)
812 {
813 dm_msg_source_t source;
814
815 memset(&source, 0, sizeof(dm_msg_source_t));
816
817 source.uri = topic;
818 source.payload = (unsigned char *)payload;
819 source.payload_len = payload_len;
820 source.context = NULL;
821
822 dm_msg_proc_thing_topo_get_reply(&source);
823 }
824
dm_client_thing_list_found_reply(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)825 void dm_client_thing_list_found_reply(int fd, const char *topic,
826 const char *payload,
827 unsigned int payload_len, void *context)
828 {
829 dm_msg_source_t source;
830
831 memset(&source, 0, sizeof(dm_msg_source_t));
832
833 source.uri = topic;
834 source.payload = (unsigned char *)payload;
835 source.payload_len = payload_len;
836 source.context = NULL;
837
838 dm_msg_proc_thing_list_found_reply(&source);
839 }
840
dm_client_combine_login_reply(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)841 void dm_client_combine_login_reply(int fd, const char *topic,
842 const char *payload,
843 unsigned int payload_len, void *context)
844 {
845 dm_msg_source_t source;
846
847 memset(&source, 0, sizeof(dm_msg_source_t));
848
849 source.uri = topic;
850 source.payload = (unsigned char *)payload;
851 source.payload_len = payload_len;
852 source.context = NULL;
853
854 dm_msg_proc_combine_login_reply(&source);
855 }
856
dm_client_combine_logout_reply(int fd,const char * topic,const char * payload,unsigned int payload_len,void * context)857 void dm_client_combine_logout_reply(int fd, const char *topic,
858 const char *payload,
859 unsigned int payload_len, void *context)
860 {
861 dm_msg_source_t source;
862
863 memset(&source, 0, sizeof(dm_msg_source_t));
864
865 source.uri = topic;
866 source.payload = (unsigned char *)payload;
867 source.payload_len = payload_len;
868 source.context = NULL;
869
870 dm_msg_proc_combine_logout_reply(&source);
871 }
872 #endif
873