Commit 0ae047b0 authored by whmaizmy's avatar whmaizmy

【修改内容】增加通过mac获取设备信息

【提交人】陈伟灿
parent 60bc7224
...@@ -137,19 +137,6 @@ typedef struct { ...@@ -137,19 +137,6 @@ typedef struct {
iotx_dm_event_callback event_callback; iotx_dm_event_callback event_callback;
} iotx_dm_init_params_t; } iotx_dm_init_params_t;
typedef enum {
IOTX_DM_DEV_AVAIL_ENABLE,
IOTX_DM_DEV_AVAIL_DISABLE
} iotx_dm_dev_avail_t;
typedef enum {
IOTX_DM_DEV_STATUS_UNAUTHORIZED, /* Subdev Created */
IOTX_DM_DEV_STATUS_AUTHORIZED, /* Receive Topo Add Notify */
IOTX_DM_DEV_STATUS_REGISTERED, /* Receive Subdev Registered */
IOTX_DM_DEV_STATUS_ATTACHED, /* Receive Subdev Topo Add Reply */
IOTX_DM_DEV_STATUS_LOGINED, /* Receive Subdev Login Reply */
IOTX_DM_DEV_STATUS_ONLINE /* After All Topic Subscribed */
} iotx_dm_dev_status_t;
typedef enum { typedef enum {
DM_TSL_SERVICE_GET_FAILED = -13, DM_TSL_SERVICE_GET_FAILED = -13,
......
...@@ -32,35 +32,6 @@ static void _dm_api_unlock(void) ...@@ -32,35 +32,6 @@ static void _dm_api_unlock(void)
} }
} }
int iotx_dm_subdev_create(_IN_ char product_key[PRODUCT_KEY_MAXLEN],
_IN_ char device_name[DEVICE_NAME_MAXLEN],
_IN_ char device_secret[DEVICE_SECRET_MAXLEN], _OU_ int *devid)
{
int res = 0;
if (product_key == NULL || device_name == NULL ||
(strlen(product_key) >= PRODUCT_KEY_MAXLEN) ||
(strlen(device_name) >= DEVICE_NAME_MAXLEN) ||
devid == NULL) {
return INVALID_PARAMETER;
}
if (device_secret != NULL && strlen(device_secret) >= DEVICE_SECRET_MAXLEN) {
return INVALID_PARAMETER;
}
_dm_api_lock();
res = dm_mgr_device_create(IOTX_DM_DEVICE_SUBDEV, product_key, device_name, device_secret, devid);
if (res != SUCCESS_RETURN) {
_dm_api_unlock();
return FAIL_RETURN;
}
_dm_api_unlock();
return SUCCESS_RETURN;
}
int kk_dm_subdev_register(_IN_ int devid) int kk_dm_subdev_register(_IN_ int devid)
{ {
int res = 0; int res = 0;
......
...@@ -167,7 +167,7 @@ static int _dm_init_tsl_params(int devId) ...@@ -167,7 +167,7 @@ static int _dm_init_tsl_params(int devId)
return res; return res;
} }
int dm_mgr_device_create(_IN_ int dev_type, _IN_ char product_key[PRODUCT_KEY_MAXLEN], int dm_mgr_device_create(_IN_ int dev_type, _IN_ char product_key[PRODUCT_KEY_MAXLEN],
_IN_ char device_name[DEVICE_NAME_MAXLEN], _IN_ char device_secret[DEVICE_SECRET_MAXLEN], _OU_ int *devid) _IN_ char device_name[DEVICE_NAME_MAXLEN], _IN_ char device_secret[DEVICE_SECRET_MAXLEN],_IN_ char device_mac[DEVICE_MAC_MAXLEN], _OU_ int *devid)
{ {
int res = 0; int res = 0;
dm_mgr_ctx *ctx = _dm_mgr_get_ctx(); dm_mgr_ctx *ctx = _dm_mgr_get_ctx();
...@@ -184,6 +184,9 @@ int dm_mgr_device_create(_IN_ int dev_type, _IN_ char product_key[PRODUCT_KEY_MA ...@@ -184,6 +184,9 @@ int dm_mgr_device_create(_IN_ int dev_type, _IN_ char product_key[PRODUCT_KEY_MA
if (device_secret != NULL && strlen(device_secret) >= DEVICE_SECRET_MAXLEN) { if (device_secret != NULL && strlen(device_secret) >= DEVICE_SECRET_MAXLEN) {
return INVALID_PARAMETER; return INVALID_PARAMETER;
} }
if (device_mac != NULL && strlen(device_mac) >= DEVICE_MAC_MAXLEN) {
return INVALID_PARAMETER;
}
res = _dm_mgr_search_dev_by_pkdn(product_key, device_name, &node); res = _dm_mgr_search_dev_by_pkdn(product_key, device_name, &node);
if (res == SUCCESS_RETURN) { if (res == SUCCESS_RETURN) {
...@@ -210,6 +213,10 @@ int dm_mgr_device_create(_IN_ int dev_type, _IN_ char product_key[PRODUCT_KEY_MA ...@@ -210,6 +213,10 @@ int dm_mgr_device_create(_IN_ int dev_type, _IN_ char product_key[PRODUCT_KEY_MA
if (device_secret != NULL) { if (device_secret != NULL) {
memcpy(node->device_secret, device_secret, strlen(device_secret)); memcpy(node->device_secret, device_secret, strlen(device_secret));
} }
if (device_mac != NULL) {
memcpy(node->device_mac, device_mac, strlen(device_mac));
}
//node->dev_status = IOTX_DM_DEV_STATUS_AUTHORIZED; //node->dev_status = IOTX_DM_DEV_STATUS_AUTHORIZED;
memset(name,0x0,sizeof(name)); memset(name,0x0,sizeof(name));
kk_get_tsl_by_productKey(product_key,name); kk_get_tsl_by_productKey(product_key,name);
...@@ -255,6 +262,46 @@ int dm_mgr_search_device_by_pkdn(_IN_ char product_key[PRODUCT_KEY_MAXLEN], _IN_ ...@@ -255,6 +262,46 @@ int dm_mgr_search_device_by_pkdn(_IN_ char product_key[PRODUCT_KEY_MAXLEN], _IN_
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
int dm_mgr_get_device_by_mac(_IN_ char device_mac[DEVICE_MAC_MAXLEN], _OU_ dm_mgr_dev_node_t **node)
{
dm_mgr_ctx *ctx = _dm_mgr_get_ctx();
dm_mgr_dev_node_t *search_node = NULL;
list_for_each_entry(search_node, &ctx->dev_list, linked_list, dm_mgr_dev_node_t) {
if ((strlen(search_node->device_mac) == strlen(device_mac)) &&
(memcmp(search_node->device_mac, device_mac, strlen(device_mac)) == 0)) {
/* dm_log_debug("Device Found, Product Key: %s, Device Name: %s", product_key, device_name); */
if (node) {
*node = search_node;
}
return SUCCESS_RETURN;
}
}
printf("Device Not Found, device_mac: %s\n", device_mac);
return FAIL_RETURN;
}
int dm_mgr_get_devId_by_mac(_IN_ char device_mac[DEVICE_MAC_MAXLEN],_OU_ int *devid)
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
if (device_mac == NULL) {
return INVALID_PARAMETER;
}
res = dm_mgr_get_device_by_mac(device_mac, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
if (devid) {
*devid = node->devid;
}
return SUCCESS_RETURN;
}
int dm_mgr_init(void) int dm_mgr_init(void)
{ {
int res = 0; int res = 0;
...@@ -284,7 +331,7 @@ int dm_mgr_init(void) ...@@ -284,7 +331,7 @@ int dm_mgr_init(void)
//memcpy(device_name,"aIqEbWno8yDdsjCX15iq",strlen("aIqEbWno8yDdsjCX15iq")); //memcpy(device_name,"aIqEbWno8yDdsjCX15iq",strlen("aIqEbWno8yDdsjCX15iq"));
//_dm_mgr_legacy_thing_created(IOTX_DM_LOCAL_NODE_DEVID); //_dm_mgr_legacy_thing_created(IOTX_DM_LOCAL_NODE_DEVID);
res = dm_mgr_device_create(KK_DM_DEVICE_GATEWAY,product_key,device_name,device_secret,&devId); res = dm_mgr_device_create(KK_DM_DEVICE_GATEWAY,product_key,device_name,device_secret,NULL,&devId);
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
goto ERROR; goto ERROR;
} }
...@@ -685,10 +732,6 @@ int dm_mgr_upstream_combine_logout(_IN_ int devid) ...@@ -685,10 +732,6 @@ int dm_mgr_upstream_combine_logout(_IN_ int devid)
return FAIL_RETURN; return FAIL_RETURN;
} }
if (node->dev_status < IOTX_DM_DEV_STATUS_LOGINED) {
return FAIL_RETURN;
}
memset(&request, 0, sizeof(dm_msg_request_t)); memset(&request, 0, sizeof(dm_msg_request_t));
request.service_prefix = DM_URI_EXT_SESSION_PREFIX; request.service_prefix = DM_URI_EXT_SESSION_PREFIX;
request.service_name = DM_URI_COMBINE_LOGOUT; request.service_name = DM_URI_COMBINE_LOGOUT;
...@@ -773,10 +816,10 @@ int dm_mgr_upstream_thing_topo_delete(_IN_ int devid) ...@@ -773,10 +816,10 @@ int dm_mgr_upstream_thing_topo_delete(_IN_ int devid)
int dm_mgr_subdev_create(_IN_ char product_key[PRODUCT_KEY_MAXLEN], int dm_mgr_subdev_create(_IN_ char product_key[PRODUCT_KEY_MAXLEN],
_IN_ char device_name[DEVICE_NAME_MAXLEN], _IN_ char device_secret[DEVICE_SECRET_MAXLEN], _OU_ int *devid){ _IN_ char device_name[DEVICE_NAME_MAXLEN], _IN_ char device_secret[DEVICE_SECRET_MAXLEN],_IN_ char device_mac[DEVICE_MAC_MAXLEN], _OU_ int *devid){
int res = 0; int res = 0;
res = dm_mgr_device_create(KK_DM_DEVICE_SUBDEV,product_key,device_name,device_secret, devid); res = dm_mgr_device_create(KK_DM_DEVICE_SUBDEV,product_key,device_name,device_secret,device_mac, devid);
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
printf("subdev open Failed\n"); printf("subdev open Failed\n");
return FAIL_RETURN; return FAIL_RETURN;
......
...@@ -17,8 +17,7 @@ typedef struct { ...@@ -17,8 +17,7 @@ typedef struct {
char product_key[PRODUCT_KEY_MAXLEN]; char product_key[PRODUCT_KEY_MAXLEN];
char device_name[DEVICE_NAME_MAXLEN]; char device_name[DEVICE_NAME_MAXLEN];
char device_secret[DEVICE_SECRET_MAXLEN]; char device_secret[DEVICE_SECRET_MAXLEN];
iotx_dm_dev_avail_t status; char device_mac[DEVICE_MAC_MAXLEN];
iotx_dm_dev_status_t dev_status;
struct list_head linked_list; struct list_head linked_list;
} dm_mgr_dev_node_t; } dm_mgr_dev_node_t;
......
...@@ -241,7 +241,7 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data) ...@@ -241,7 +241,7 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
printf("_iotx_linkkit_event_callback topic: [%s] ,payload= %s \n",topic->valuestring,payload->valuestring ); printf("_iotx_linkkit_event_callback topic: [%s] ,payload= %s \n",topic->valuestring,payload->valuestring );
if (strcmp(payload->valuestring, "addsub")==0){ if (strcmp(payload->valuestring, "addsub")==0){
kk_mid_subdev_add("a1OYuSallan","allanWno8yDdsjCX15iq",""); kk_mid_subdev_add("a1OYuSallan","allanWno8yDdsjCX15iq","","");
}else{ }else{
printf("rrr topic: [%s] ,payload= %s \n",topic->valuestring,payload->valuestring ); printf("rrr topic: [%s] ,payload= %s \n",topic->valuestring,payload->valuestring );
...@@ -1745,10 +1745,10 @@ int iot_linkkit_subdev_query_id(char product_key[IOTX_PRODUCT_KEY_LEN + 1], char ...@@ -1745,10 +1745,10 @@ int iot_linkkit_subdev_query_id(char product_key[IOTX_PRODUCT_KEY_LEN + 1], char
#endif /* #ifdef DEVICE_MODEL_GATEWAY */ #endif /* #ifdef DEVICE_MODEL_GATEWAY */
int kk_mid_subdev_add(char product_key[PRODUCT_KEY_MAXLEN], char device_name[DEVICE_NAME_MAXLEN], char device_secret[DEVICE_SECRET_MAXLEN]){ int kk_mid_subdev_add(char product_key[PRODUCT_KEY_MAXLEN], char device_name[DEVICE_NAME_MAXLEN], char device_secret[DEVICE_SECRET_MAXLEN],char device_mac[DEVICE_MAC_MAXLEN]){
int res = 0; int res = 0;
int devid = 0; int devid = 0;
res = dm_mgr_subdev_create(product_key,device_name,device_secret,&devid); res = dm_mgr_subdev_create(product_key,device_name,device_secret,device_mac,&devid);
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
printf("subdev create Failed\n"); printf("subdev create Failed\n");
return FAIL_RETURN; return FAIL_RETURN;
......
...@@ -32,7 +32,7 @@ void mid_cb(void* data, int len){ ...@@ -32,7 +32,7 @@ void mid_cb(void* data, int len){
payload = cJSON_GetObjectItem(json, "payload"); payload = cJSON_GetObjectItem(json, "payload");
printf("mid_cb topic: [%s] ,payload= %s \n",topic->valuestring,payload->valuestring ); printf("mid_cb topic: [%s] ,payload= %s \n",topic->valuestring,payload->valuestring );
if (strcmp(payload->valuestring, "addsub")==0){ if (strcmp(payload->valuestring, "addsub")==0){
kk_mid_subdev_add("a1OYuSallan","allanWno8yDdsjCX15iq",""); kk_mid_subdev_add("a1OYuSallan","allanWno8yDdsjCX15iq","","");
}else{ }else{
void* buf = malloc(len); void* buf = malloc(len);
memcpy(buf, data, len); memcpy(buf, data, len);
...@@ -191,7 +191,7 @@ int main(const int argc, const char **argv) ...@@ -191,7 +191,7 @@ int main(const int argc, const char **argv)
ct =1; ct =1;
kk_set_tsl_by_productKey("a1OYuSallan","model.json"); kk_set_tsl_by_productKey("a1OYuSallan","model.json");
kk_mid_subdev_add("a1OYuSallan","allanWno8yDdsjCX15iq",""); kk_mid_subdev_add("a1OYuSallan","allanWno8yDdsjCX15iq","","");
} }
/*memset(buf, 0, 100); /*memset(buf, 0, 100);
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#define PRODUCT_KEY_MAXLEN (32 + 1) #define PRODUCT_KEY_MAXLEN (32 + 1)
#define DEVICE_NAME_MAXLEN (32 + 1) #define DEVICE_NAME_MAXLEN (32 + 1)
#define DEVICE_SECRET_MAXLEN (64 + 1) #define DEVICE_SECRET_MAXLEN (64 + 1)
#define DEVICE_MAC_MAXLEN (16 + 1)
#define TSL_PATH_MAXLEN (64 + 1) #define TSL_PATH_MAXLEN (64 + 1)
#define DM_UTILS_UINT16_STRLEN (5) #define DM_UTILS_UINT16_STRLEN (5)
...@@ -66,6 +68,7 @@ ...@@ -66,6 +68,7 @@
#define KK_TSL_GATAWAY_MAC_IDENTIFIER "MACAddress" #define KK_TSL_GATAWAY_MAC_IDENTIFIER "MACAddress"
#define KK_TSL_GATAWAY_PORT_IDENTIFIER "Port" #define KK_TSL_GATAWAY_PORT_IDENTIFIER "Port"
#define KK_TSL_GATAWAY_SN_IDENTIFIER "SN" #define KK_TSL_GATAWAY_SN_IDENTIFIER "SN"
#define KK_TSL_GATAWAY_WHITELIST_IDENTIFIER "WhiteListState"
typedef enum { typedef enum {
KK_TSL_DATA_TARGET_SERVICE_INPUT_DATA, KK_TSL_DATA_TARGET_SERVICE_INPUT_DATA,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment