1 /* 2 * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 */ 4 5 #ifndef _DM_MESSAGE_H_ 6 #define _DM_MESSAGE_H_ 7 8 #include "iotx_dm_internal.h" 9 10 #define DM_MSG_KEY_ID "id" 11 #define DM_MSG_KEY_VERSION "version" 12 #define DM_MSG_KEY_METHOD "method" 13 #define DM_MSG_KEY_PARAMS "params" 14 #define DM_MSG_KEY_CODE "code" 15 #define DM_MSG_KEY_DATA "data" 16 #define DM_MSG_KEY_MESSAGE "message" 17 18 #define DM_MSG_VERSION "1.0" 19 20 #define DM_MSG_KEY_FAILURES "failures" 21 #define DM_MSG_KEY_SUCCESSES "successes" 22 #define DM_MSG_KEY_ERRORDETAIL "errorDetail" 23 #define DM_MSG_KEY_CODE "code" 24 #define DM_MSG_KEY_PRODUCT_KEY "productKey" 25 #define DM_MSG_KEY_DEVICE_NAME "deviceName" 26 #define DM_MSG_KEY_DEVICE_SECRET "deviceSecret" 27 #define DM_MSG_KEY_TIME "time" 28 29 #define DM_MSG_SIGN_METHOD_SHA256 "Sha256" 30 #define DM_MSG_SIGN_METHOD_HMACMD5 "hmacMd5" 31 #define DM_MSG_SIGN_METHOD_HMACSHA1 "hmacSha1" 32 #define DM_MSG_SIGN_METHOD_HMACSHA256 "hmacSha256" 33 34 typedef enum { 35 DM_MSG_DEST_CLOUD = 0x01, 36 DM_MSG_DEST_LOCAL = 0x02, 37 DM_MSG_DEST_ALL = 0x03 38 } dm_msg_dest_type_t; 39 40 typedef struct { 41 const char *uri; 42 unsigned char *payload; 43 unsigned int payload_len; 44 void *context; 45 } dm_msg_source_t; 46 47 typedef struct { 48 const char *uri_name; 49 } dm_msg_dest_t; 50 51 typedef struct { 52 lite_cjson_t id; 53 lite_cjson_t version; 54 lite_cjson_t method; 55 lite_cjson_t params; 56 } dm_msg_request_payload_t; 57 58 typedef struct { 59 lite_cjson_t id; 60 lite_cjson_t code; 61 lite_cjson_t data; 62 lite_cjson_t message; 63 } dm_msg_response_payload_t; 64 65 typedef struct { 66 int msgid; 67 int devid; 68 const char *service_prefix; 69 const char *service_name; 70 char product_key[IOTX_PRODUCT_KEY_LEN + 1]; 71 char device_name[IOTX_DEVICE_NAME_LEN + 1]; 72 char *params; 73 int params_len; 74 char *method; 75 iotx_cm_data_handle_cb callback; 76 } dm_msg_request_t; 77 78 typedef struct { 79 const char *service_prefix; 80 const char *service_name; 81 char product_key[IOTX_PRODUCT_KEY_LEN + 1]; 82 char device_name[IOTX_DEVICE_NAME_LEN + 1]; 83 iotx_dm_error_code_t code; 84 } dm_msg_response_t; 85 86 typedef struct { 87 int id; 88 } dm_msg_ctx_t; 89 90 int dm_msg_init(void); 91 int dm_msg_deinit(void); 92 int _dm_msg_send_to_user(iotx_dm_event_types_t type, char *message); 93 int dm_msg_send_msg_timeout_to_user(int msg_id, int devid, 94 iotx_dm_event_types_t type); 95 int dm_msg_uri_parse_pkdn(_IN_ char *uri, _IN_ int uri_len, _IN_ int start_deli, 96 _IN_ int end_deli, 97 _OU_ char product_key[IOTX_PRODUCT_KEY_LEN + 1], 98 _OU_ char device_name[IOTX_DEVICE_NAME_LEN + 1]); 99 int dm_msg_request_parse(_IN_ char *payload, _IN_ int payload_len, 100 _OU_ dm_msg_request_payload_t *request); 101 int dm_msg_response_parse(_IN_ char *payload, _IN_ int payload_len, 102 _OU_ dm_msg_response_payload_t *response); 103 int dm_msg_request(dm_msg_dest_type_t type, _IN_ dm_msg_request_t *request); 104 int dm_msg_response(dm_msg_dest_type_t type, 105 _IN_ dm_msg_request_payload_t *request, 106 _IN_ dm_msg_response_t *response, _IN_ char *data, 107 _IN_ int data_len, _IN_ void *user_data); 108 int dm_msg_thing_model_down_raw(_IN_ char product_key[IOTX_PRODUCT_KEY_LEN + 1], 109 _IN_ char device_name[IOTX_DEVICE_NAME_LEN + 1], 110 _IN_ char *payload, _IN_ int payload_len); 111 int dm_msg_thing_model_up_raw_reply( 112 _IN_ char product_key[IOTX_PRODUCT_KEY_LEN + 1], 113 _IN_ char device_name[IOTX_DEVICE_NAME_LEN + 1], char *payload, 114 int payload_len); 115 #if !defined(DEVICE_MODEL_RAWDATA_SOLO) 116 int dm_msg_property_set(int devid, dm_msg_request_payload_t *request); 117 #ifndef DEPRECATED_LINKKIT 118 int dm_msg_property_get(_IN_ int devid, _IN_ dm_msg_request_payload_t *request, 119 _IN_ void *ctx); 120 #else 121 int dm_msg_property_get(_IN_ int devid, _IN_ dm_msg_request_payload_t *request, 122 _IN_ char **payload, _IN_ int *payload_len); 123 #endif 124 int dm_msg_thing_service_request( 125 _IN_ char product_key[IOTX_PRODUCT_KEY_LEN + 1], 126 _IN_ char device_name[IOTX_DEVICE_NAME_LEN + 1], char *identifier, 127 int identifier_len, dm_msg_request_payload_t *request, _IN_ void *ctx); 128 int dm_msg_rrpc_request(_IN_ char product_key[IOTX_PRODUCT_KEY_LEN + 1], 129 _IN_ char device_name[IOTX_DEVICE_NAME_LEN + 1], 130 char *messageid, int messageid_len, 131 dm_msg_request_payload_t *request); 132 int dm_msg_thing_event_property_post_reply(dm_msg_response_payload_t *response); 133 int dm_msg_thing_event_post_reply(_IN_ char *identifier, 134 _IN_ int identifier_len, 135 _IN_ dm_msg_response_payload_t *response); 136 int dm_msg_thing_deviceinfo_update_reply(dm_msg_response_payload_t *response); 137 int dm_msg_thing_property_desired_get_reply( 138 dm_msg_response_payload_t *response); 139 int dm_msg_thing_property_desired_delete_reply( 140 dm_msg_response_payload_t *response); 141 int dm_msg_thing_deviceinfo_delete_reply(dm_msg_response_payload_t *response); 142 int dm_msg_thing_dsltemplate_get_reply(dm_msg_response_payload_t *response); 143 int dm_msg_thing_dynamictsl_get_reply(dm_msg_response_payload_t *response); 144 int dm_msg_ntp_response(char *payload, int payload_len); 145 int dm_msg_ext_error_response(char *payload, int payload_len); 146 #endif 147 148 #ifdef DEVICE_MODEL_GATEWAY 149 int dm_msg_topo_add_notify(_IN_ char *payload, _IN_ int payload_len); 150 int dm_msg_thing_disable(_IN_ char product_key[IOTX_PRODUCT_KEY_LEN + 1], 151 _IN_ char device_name[IOTX_DEVICE_NAME_LEN + 1]); 152 int dm_msg_thing_enable(_IN_ char product_key[IOTX_PRODUCT_KEY_LEN + 1], 153 _IN_ char device_name[IOTX_DEVICE_NAME_LEN + 1]); 154 int dm_msg_thing_delete(_IN_ char product_key[IOTX_PRODUCT_KEY_LEN + 1], 155 _IN_ char device_name[IOTX_DEVICE_NAME_LEN + 1]); 156 int dm_msg_thing_gateway_permit(_IN_ char *payload, _IN_ int payload_len); 157 int dm_msg_thing_sub_register_reply(dm_msg_response_payload_t *response); 158 int dm_msg_thing_proxy_product_register_reply( 159 dm_msg_response_payload_t *response); 160 int dm_msg_thing_sub_unregister_reply(dm_msg_response_payload_t *response); 161 int dm_msg_thing_topo_add_reply(dm_msg_response_payload_t *response); 162 int dm_msg_thing_topo_delete_reply(dm_msg_response_payload_t *response); 163 int dm_msg_topo_get_reply(dm_msg_response_payload_t *response); 164 int dm_msg_thing_list_found_reply(dm_msg_response_payload_t *response); 165 int dm_msg_combine_login_reply(dm_msg_response_payload_t *response); 166 int dm_msg_combine_logout_reply(dm_msg_response_payload_t *response); 167 #endif 168 #ifdef ALCS_ENABLED 169 int dm_msg_dev_core_service_dev(char **payload, int *payload_len); 170 #endif 171 int dm_msg_cloud_connected(void); 172 int dm_msg_cloud_disconnect(void); 173 int dm_msg_cloud_reconnect(void); 174 int dm_msg_register_result(_IN_ char *uri, _IN_ int result); 175 176 #ifdef DEVICE_MODEL_GATEWAY 177 int dm_msg_thing_sub_register(_IN_ char product_key[IOTX_PRODUCT_KEY_LEN + 1], 178 _IN_ char device_name[IOTX_DEVICE_NAME_LEN + 1], 179 _OU_ dm_msg_request_t *request); 180 int dm_msg_thing_proxy_product_register( 181 _IN_ char product_key[IOTX_PRODUCT_KEY_LEN + 1], 182 _IN_ char product_secret[IOTX_PRODUCT_SECRET_LEN + 1], 183 _IN_ char device_name[IOTX_DEVICE_NAME_LEN + 1], 184 _OU_ dm_msg_request_t *request); 185 int dm_msg_thing_sub_unregister(_IN_ char product_key[IOTX_PRODUCT_KEY_LEN + 1], 186 _IN_ char device_name[IOTX_DEVICE_NAME_LEN + 1], 187 _OU_ dm_msg_request_t *request); 188 int dm_msg_thing_topo_add(_IN_ char product_key[IOTX_PRODUCT_KEY_LEN + 1], 189 _IN_ char device_name[IOTX_DEVICE_NAME_LEN + 1], 190 _IN_ char device_secret[IOTX_DEVICE_SECRET_LEN + 1], 191 _OU_ dm_msg_request_t *request); 192 int dm_msg_thing_topo_delete(_IN_ char product_key[IOTX_PRODUCT_KEY_LEN + 1], 193 _IN_ char device_name[IOTX_DEVICE_NAME_LEN + 1], 194 _OU_ dm_msg_request_t *request); 195 int dm_msg_thing_topo_get(_OU_ dm_msg_request_t *request); 196 int dm_msg_thing_list_found(_IN_ char product_key[IOTX_PRODUCT_KEY_LEN + 1], 197 _IN_ char device_name[IOTX_DEVICE_NAME_LEN + 1], 198 _OU_ dm_msg_request_t *request); 199 int dm_msg_combine_login(_IN_ char product_key[IOTX_PRODUCT_KEY_LEN + 1], 200 _IN_ char device_name[IOTX_DEVICE_NAME_LEN + 1], 201 _IN_ char device_secret[IOTX_DEVICE_SECRET_LEN + 1], 202 _OU_ dm_msg_request_t *request); 203 int dm_msg_combine_logout(_IN_ char product_key[IOTX_PRODUCT_KEY_LEN + 1], 204 _IN_ char device_name[IOTX_DEVICE_NAME_LEN + 1], 205 _OU_ dm_msg_request_t *request); 206 #endif 207 208 int dm_msg_thing_model_user_sub(_IN_ char product_key[IOTX_PRODUCT_KEY_LEN], 209 _IN_ char device_name[IOTX_DEVICE_NAME_LEN], 210 _IN_ char *payload, _IN_ int payload_len); 211 #endif 212