Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
k-sdk
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈伟灿
k-sdk
Commits
c02ee8a2
Commit
c02ee8a2
authored
Aug 20, 2020
by
chen.weican
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改内容】把代码中product key相关统一修改成productType
【提交人】陈伟灿
parent
40e267dd
Changes
24
Hide whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
466 additions
and
339 deletions
+466
-339
application/kcloud/kcloud_data_handle.c
application/kcloud/kcloud_data_handle.c
+9
-9
application/kcloud/kk_topic_mng.c
application/kcloud/kk_topic_mng.c
+67
-43
common/api/com_api.h
common/api/com_api.h
+3
-2
common/hal/HAL_OS_linux.c
common/hal/HAL_OS_linux.c
+1
-1
common/hal/kk_product.h
common/hal/kk_product.h
+2
-2
midware/midware/dm/dm_ota.c
midware/midware/dm/dm_ota.c
+16
-16
midware/midware/dm/dm_ota.h
midware/midware/dm/dm_ota.h
+2
-2
midware/midware/dm/kk_dm_api.c
midware/midware/dm/kk_dm_api.c
+9
-17
midware/midware/dm/kk_dm_mng.c
midware/midware/dm/kk_dm_mng.c
+156
-96
midware/midware/dm/kk_dm_mng.h
midware/midware/dm/kk_dm_mng.h
+16
-9
midware/midware/dm/kk_dm_msg.c
midware/midware/dm/kk_dm_msg.c
+84
-84
midware/midware/dm/kk_linkkit.c
midware/midware/dm/kk_linkkit.c
+4
-4
midware/midware/dm/kk_sub_db.c
midware/midware/dm/kk_sub_db.c
+13
-12
midware/midware/dm/kk_sub_db.h
midware/midware/dm/kk_sub_db.h
+6
-6
midware/midware/dm/kk_wlist_mng.c
midware/midware/dm/kk_wlist_mng.c
+18
-4
midware/midware/dm/kk_wlist_mng.h
midware/midware/dm/kk_wlist_mng.h
+2
-2
midware/midware/midware.c
midware/midware/midware.c
+5
-4
midware/midware/utils/infra_defs.h
midware/midware/utils/infra_defs.h
+2
-2
midware/tsl/tsl_handle/kk_tsl_api.c
midware/tsl/tsl_handle/kk_tsl_api.c
+10
-10
midware/tsl/tsl_handle/kk_tsl_api.h
midware/tsl/tsl_handle/kk_tsl_api.h
+1
-1
midware/tsl/tsl_handle/kk_tsl_common.h
midware/tsl/tsl_handle/kk_tsl_common.h
+5
-3
midware/tsl/tsl_handle/kk_tsl_load.c
midware/tsl/tsl_handle/kk_tsl_load.c
+28
-4
midware/tsl/tsl_handle/kk_tsl_load.h
midware/tsl/tsl_handle/kk_tsl_load.h
+2
-1
midware/tsl/tsl_handle/kk_utils.c
midware/tsl/tsl_handle/kk_utils.c
+5
-5
No files found.
application/kcloud/kcloud_data_handle.c
View file @
c02ee8a2
...
...
@@ -18,7 +18,7 @@
#define KK_FILTER_SET_TOPIC_REPLY "/thing/service/property/set_reply"
#define KK_FILTER_EVENT_POST_TOPIC "/thing/event/property/post"
#define KK_FILTER_EVENT_POST_REPLY "/thing/event/property/post_reply"
const
char
DM_MSG_TO_MIDDWARE
[]
=
"{
\"
msgtype
\"
:
\"
%d
\"
,
\"
product
_type
\"
:
\"
%s
\"
,
\"
device_nam
e
\"
:
\"
%s
\"
}"
;
const
char
DM_MSG_TO_MIDDWARE
[]
=
"{
\"
msgtype
\"
:
\"
%d
\"
,
\"
product
Type
\"
:
\"
%s
\"
,
\"
deviceCod
e
\"
:
\"
%s
\"
}"
;
#define KK_TOPIC_SERVICE_DELIMITER '/'
typedef
struct
{
...
...
@@ -53,7 +53,7 @@ int _kk_sendto_cloud(cJSON *root)
if
(
pData
==
NULL
){
return
-
1
;
}
printf
(
"[%s][%d] payload:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
pData
->
valuestring
);
INFO_PRINT
(
"[%s][%d] payload:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
pData
->
valuestring
);
KK_MQTT_SendMsg
(
topic
,(
const
char
*
)
pData
->
valuestring
);
free
(
topic
);
return
0
;
...
...
@@ -68,7 +68,7 @@ void KK_Data_FromDev(void* str,int len)
}
root
=
cJSON_Parse
((
char
*
)
str
);
if
(
root
==
NULL
){
printf
(
"[%s][%d] root is null
\n
"
,
__FUNCTION__
,
__LINE__
);
ERROR_PRINT
(
"[%s][%d] root is null
\n
"
,
__FUNCTION__
,
__LINE__
);
return
;
}
cmd
=
cJSON_GetObjectItem
(
root
,
"cmd"
);
...
...
@@ -124,11 +124,11 @@ static kk_msg_type_t _kk_parse_type(const char *topic)
}
static
int
_kk_topic_parse_pkdn
(
_IN_
char
*
topic
,
_IN_
int
start_deli
,
_IN_
int
end_deli
,
_OU_
char
product
_key
[
PRODUCT_TYPE_LEN
],
_OU_
char
device_nam
e
[
DEVICE_CODE_LEN
])
_OU_
char
product
Type
[
PRODUCT_TYPE_LEN
],
_OU_
char
deviceCod
e
[
DEVICE_CODE_LEN
])
{
int
res
=
0
,
start
=
0
,
end
=
0
,
slice
=
0
;
if
(
topic
==
NULL
||
product
_key
==
NULL
||
device_nam
e
==
NULL
)
{
if
(
topic
==
NULL
||
product
Type
==
NULL
||
deviceCod
e
==
NULL
)
{
return
-
1
;
}
res
=
kk_utils_memtok
(
topic
,
strlen
(
topic
),
KK_TOPIC_SERVICE_DELIMITER
,
start_deli
,
&
start
);
...
...
@@ -147,8 +147,8 @@ static int _kk_topic_parse_pkdn(_IN_ char *topic, _IN_ int start_deli, _IN_ int
/* dm_log_debug("URI Product Key: %.*s, Device Name: %.*s", slice - start - 1, uri + start + 1, end - slice - 1,
uri + slice + 1); */
memcpy
(
product
_key
,
topic
+
start
+
1
,
slice
-
start
-
1
);
memcpy
(
device
_nam
e
,
topic
+
slice
+
1
,
end
-
slice
-
1
);
memcpy
(
product
Type
,
topic
+
start
+
1
,
slice
-
start
-
1
);
memcpy
(
device
Cod
e
,
topic
+
slice
+
1
,
end
-
slice
-
1
);
return
0
;
}
...
...
@@ -165,7 +165,7 @@ static char * _kk_data_create(const char *topic,const char *data)
kk_msg_type_t
type
;
type
=
_kk_parse_type
(
topic
);
if
(
type
==
MSG_INVALID
){
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
ERROR_PRINT
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
return
NULL
;
}
res
=
_kk_topic_parse_pkdn
((
char
*
)
topic
,
2
,
4
,
product_key
,
device_name
);
...
...
@@ -173,7 +173,7 @@ static char * _kk_data_create(const char *topic,const char *data)
infoStr_len
=
strlen
(
DM_MSG_TO_MIDDWARE
)
+
strlen
(
product_key
)
+
strlen
(
device_name
)
+
10
;
infoStr
=
malloc
(
infoStr_len
);
if
(
infoStr
==
NULL
){
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
ERROR_PRINT
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
return
NULL
;
}
memset
(
infoStr
,
0x0
,
infoStr_len
);
...
...
application/kcloud/kk_topic_mng.c
View file @
c02ee8a2
...
...
@@ -8,8 +8,8 @@
#include "kk_log.h"
const
char
KK_URI_SYS_PREFIX
[]
=
"/sys/%s/%s/#"
;
const
char
KK_URI_SYS_PREFIX_EX
[]
=
"/sys/%s/%s/"
;
const
char
KK_URI_SYS_PREFIX
[]
=
"/sys/
kk/
%s/%s/#"
;
const
char
KK_URI_SYS_PREFIX_EX
[]
=
"/sys/
kk/
%s/%s/"
;
const
char
DM_URI_THING_SUB_REGISTER
[]
=
"thing/sub/register"
;
const
char
DM_URI_THING_SUB_UNREGISTER
[]
=
"thing/sub/unregister"
;
const
char
DM_URI_THING_TOPO_ADD
[]
=
"thing/topo/add"
;
...
...
@@ -22,7 +22,7 @@ const char DM_URI_THING_EVENT_PROPERTY_POST[] = "thing/event/property/post";
const
char
DM_URI_THING_EVENT_POST
[]
=
"thing/event/%.*s/post"
;
const
char
DM_URI_THING_SERVICE_RESPONSE
[]
=
"thing/service/%.*s_reply"
;
const
char
DM_URI_THING_SERVICE_PROPERTY_SET_REPLY
[]
=
"thing/service/property/set_reply"
;
const
char
KK_URI_OTA_PREFIX
[]
=
"/ota/device/upgrade/%s/%s/#"
;
const
char
KK_URI_OTA_PREFIX
[]
=
"/ota/device/upgrade/
kk/
%s/%s/#"
;
const
char
KK_URI_OTA_PROCESS
[]
=
"/ota/device/progress/%s/%s"
;
const
char
KK_URI_OTA_INFORM
[]
=
"/ota/device/inform/%s/%s"
;
...
...
@@ -31,7 +31,7 @@ const char KK_URI_OTA_INFORM[] = "/ota/device/inform/%s/%s";
int
KK_Subdev_Subscribe
(
const
cJSON
*
root
)
{
int
res
=
0
;
cJSON
*
productTyp
e
=
NULL
;
cJSON
*
deviceCod
e
=
NULL
;
cJSON
*
productCode
=
NULL
;
cJSON
*
data
=
NULL
;
cJSON
*
cmd
=
NULL
;
...
...
@@ -41,27 +41,27 @@ int KK_Subdev_Subscribe(const cJSON *root)
if
(
data
==
NULL
){
return
-
1
;
}
productType
=
cJSON_GetObjectItem
(
data
,
"productType"
);
if
(
productTyp
e
==
NULL
){
deviceCode
=
cJSON_GetObjectItem
(
data
,
MSG_DEVICE_CODE_STR
);
if
(
deviceCod
e
==
NULL
){
return
-
1
;
}
productCode
=
cJSON_GetObjectItem
(
data
,
"productCode"
);
productCode
=
cJSON_GetObjectItem
(
data
,
MSG_PRODUCT_CODE_STR
);
if
(
productCode
==
NULL
){
return
-
1
;
}
url_len
=
strlen
(
KK_URI_OTA_PREFIX
)
+
strlen
(
product
Type
->
valuestring
)
+
strlen
(
product
Code
->
valuestring
)
+
1
;
url_len
=
strlen
(
KK_URI_OTA_PREFIX
)
+
strlen
(
product
Code
->
valuestring
)
+
strlen
(
device
Code
->
valuestring
)
+
1
;
char
*
url
=
malloc
(
url_len
);
if
(
url
==
NULL
)
{
return
-
1
;
}
memset
(
url
,
0
,
url_len
);
snprintf
(
url
,
url_len
,
KK_URI_OTA_PREFIX
,
product
Type
->
valuestring
,
product
Code
->
valuestring
);
snprintf
(
url
,
url_len
,
KK_URI_OTA_PREFIX
,
product
Code
->
valuestring
,
device
Code
->
valuestring
);
INFO_PRINT
(
"ota [%s][%d] URL:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
url
);
res
=
KK_MQTT_SubTopic
(
url
);
memset
(
url
,
0
,
url_len
);
snprintf
(
url
,
url_len
,
KK_URI_SYS_PREFIX
,
product
Type
->
valuestring
,
product
Code
->
valuestring
);
snprintf
(
url
,
url_len
,
KK_URI_SYS_PREFIX
,
product
Code
->
valuestring
,
device
Code
->
valuestring
);
INFO_PRINT
(
"sys [%s][%d] URL:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
url
);
res
=
KK_MQTT_SubTopic
(
url
);
free
(
url
);
...
...
@@ -69,25 +69,25 @@ int KK_Subdev_Subscribe(const cJSON *root)
}
static
int
_kk_client_subscribe
(
char
product
Type
[
PRODUCT_TYPE_LEN
],
char
productCode
[
PRODUCT
_CODE_LEN
])
static
int
_kk_client_subscribe
(
char
product
Code
[
PRODUCT_CODE_LEN
],
char
deviceCode
[
DEVICE
_CODE_LEN
])
{
int
res
=
0
,
index
=
0
,
fail_count
=
0
;
int
url_len
=
0
;
url_len
=
strlen
(
KK_URI_OTA_PREFIX
)
+
strlen
(
product
Type
)
+
strlen
(
product
Code
)
+
1
;
url_len
=
strlen
(
KK_URI_OTA_PREFIX
)
+
strlen
(
product
Code
)
+
strlen
(
device
Code
)
+
1
;
char
*
url
=
malloc
(
url_len
);
if
(
url
==
NULL
)
{
return
-
1
;
}
memset
(
url
,
0
,
url_len
);
snprintf
(
url
,
url_len
,
KK_URI_OTA_PREFIX
,
product
Type
,
product
Code
);
snprintf
(
url
,
url_len
,
KK_URI_OTA_PREFIX
,
product
Code
,
device
Code
);
INFO_PRINT
(
"ota [%s][%d] URL:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
url
);
res
=
KK_MQTT_SubTopic
(
url
);
memset
(
url
,
0
,
url_len
);
snprintf
(
url
,
url_len
,
KK_URI_SYS_PREFIX
,
product
Type
,
product
Code
);
snprintf
(
url
,
url_len
,
KK_URI_SYS_PREFIX
,
product
Code
,
device
Code
);
INFO_PRINT
(
"sys [%s][%d] URL:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
url
);
res
=
KK_MQTT_SubTopic
(
url
);
...
...
@@ -98,31 +98,31 @@ static int _kk_client_subscribe(char productType[PRODUCT_TYPE_LEN], char product
int
KK_Client_Gateway_Subscribe
(
void
)
{
char
pr
pductType
[
PRODUCT_TYPE_LEN
]
;
char
prpductCode
[
PRODUCT_CODE_LEN
]
;
char
pr
oductCode
[
PRODUCT_CODE_LEN
]
=
{
0
}
;
char
deviceCode
[
MAC_ADDR_LEN
]
=
{
0
}
;
HAL_GetProduct_
Type
(
prpductTyp
e
);
HAL_Get
Product_Code
(
prpduct
Code
);
return
_kk_client_subscribe
(
pr
pductType
,
prpduct
Code
);
HAL_GetProduct_
Code
(
productCod
e
);
HAL_Get
_mac
(
device
Code
);
return
_kk_client_subscribe
(
pr
oductCode
,
device
Code
);
}
static
int
_kk_utils_topic
(
_IN_
const
char
*
name
,
_IN_
char
*
product_
key
,
_IN_
char
*
device_
nam
e
,
_OU_
char
**
topic
)
static
int
_kk_utils_topic
(
_IN_
const
char
*
name
,
_IN_
char
*
product_
code
,
_IN_
char
*
device_
cod
e
,
_OU_
char
**
topic
)
{
int
service_name_len
=
0
;
if
(
name
==
NULL
||
product_
key
==
NULL
||
device_nam
e
==
NULL
||
if
(
name
==
NULL
||
product_
code
==
NULL
||
device_cod
e
==
NULL
||
topic
==
NULL
||
*
topic
!=
NULL
)
{
return
-
1
;
}
service_name_len
=
strlen
(
KK_URI_SYS_PREFIX_EX
)
+
strlen
(
product_
key
)
+
strlen
(
device_nam
e
)
service_name_len
=
strlen
(
KK_URI_SYS_PREFIX_EX
)
+
strlen
(
product_
code
)
+
strlen
(
device_cod
e
)
+
strlen
(
name
)
+
1
;
*
topic
=
malloc
(
service_name_len
);
if
(
*
topic
==
NULL
)
{
return
-
1
;
}
memset
(
*
topic
,
0
,
service_name_len
);
snprintf
(
*
topic
,
service_name_len
,
KK_URI_SYS_PREFIX_EX
,
product_
key
,
device_nam
e
);
snprintf
(
*
topic
,
service_name_len
,
KK_URI_SYS_PREFIX_EX
,
product_
code
,
device_cod
e
);
if
(
name
!=
NULL
)
{
memcpy
(
*
topic
+
strlen
(
*
topic
),
name
,
strlen
(
name
));
...
...
@@ -130,10 +130,34 @@ static int _kk_utils_topic(_IN_ const char *name, _IN_ char *product_key,
return
0
;
}
static
int
_kk_utils_topic_ota
(
_IN_
int
type
,
_IN_
char
*
product_code
,
_IN_
char
*
device_code
,
_OU_
char
**
topic
)
{
int
service_name_len
=
0
;
int
*
pstr_uri
=
NULL
;
if
(
product_code
==
NULL
||
device_code
==
NULL
||
topic
==
NULL
||
*
topic
!=
NULL
)
{
return
-
1
;
}
if
(
type
=
0
){
pstr_uri
=
KK_URI_OTA_PROCESS
;
}
else
if
(
type
=
1
){
pstr_uri
=
KK_URI_OTA_INFORM
;
}
service_name_len
=
strlen
(
pstr_uri
)
+
strlen
(
product_code
)
+
strlen
(
device_code
)
+
1
;
*
topic
=
malloc
(
service_name_len
);
if
(
*
topic
==
NULL
)
{
return
-
1
;
}
memset
(
*
topic
,
0
,
service_name_len
);
snprintf
(
*
topic
,
service_name_len
,
pstr_uri
,
product_code
,
device_code
);
return
0
;
}
char
*
KK_Make_Topic
(
cJSON
*
info
)
{
cJSON
*
type
,
*
product_
type
,
*
device_nam
e
,
*
root
;
cJSON
*
type
,
*
product_
code
,
*
device_cod
e
,
*
root
;
kk_msg_type_t
msgtype
;
char
*
topic
=
NULL
;
root
=
cJSON_Parse
((
char
*
)
info
->
valuestring
);
...
...
@@ -142,43 +166,43 @@ char* KK_Make_Topic(cJSON *info)
if
(
type
==
NULL
){
goto
errorreturn
;
}
product_
type
=
cJSON_GetObjectItem
(
root
,
MSG_PRODUCT_TYP
E_STR
);
if
(
product_
typ
e
==
NULL
){
product_
code
=
cJSON_GetObjectItem
(
root
,
MSG_PRODUCT_COD
E_STR
);
if
(
product_
cod
e
==
NULL
){
goto
errorreturn
;
}
device_
name
=
cJSON_GetObjectItem
(
root
,
MSG_DEVICE_NAM
E_STR
);
if
(
device_
nam
e
==
NULL
){
device_
code
=
cJSON_GetObjectItem
(
root
,
MSG_DEVICE_COD
E_STR
);
if
(
device_
cod
e
==
NULL
){
goto
errorreturn
;
}
msgtype
=
atoi
(
type
->
valuestring
);
switch
(
msgtype
)
{
case
MSG_REGISTER
:
_kk_utils_topic
(
DM_URI_THING_SUB_REGISTER
,
product_
type
->
valuestring
,
device_nam
e
->
valuestring
,
&
topic
);
_kk_utils_topic
(
DM_URI_THING_SUB_REGISTER
,
product_
code
->
valuestring
,
device_cod
e
->
valuestring
,
&
topic
);
break
;
case
MSG_UNREGISTER
:
_kk_utils_topic
(
DM_URI_THING_SUB_UNREGISTER
,
product_
type
->
valuestring
,
device_nam
e
->
valuestring
,
&
topic
);
_kk_utils_topic
(
DM_URI_THING_SUB_UNREGISTER
,
product_
code
->
valuestring
,
device_cod
e
->
valuestring
,
&
topic
);
break
;
case
MSG_TOPOADD
:
_kk_utils_topic
(
DM_URI_THING_TOPO_ADD
,
product_
type
->
valuestring
,
device_nam
e
->
valuestring
,
&
topic
);
_kk_utils_topic
(
DM_URI_THING_TOPO_ADD
,
product_
code
->
valuestring
,
device_cod
e
->
valuestring
,
&
topic
);
break
;
case
MSG_TOPODELETE
:
_kk_utils_topic
(
DM_URI_THING_TOPO_DELETE
,
product_
type
->
valuestring
,
device_nam
e
->
valuestring
,
&
topic
);
_kk_utils_topic
(
DM_URI_THING_TOPO_DELETE
,
product_
code
->
valuestring
,
device_cod
e
->
valuestring
,
&
topic
);
break
;
case
MSG_TOPOGET
:
_kk_utils_topic
(
DM_URI_THING_TOPO_GET
,
product_
type
->
valuestring
,
device_nam
e
->
valuestring
,
&
topic
);
_kk_utils_topic
(
DM_URI_THING_TOPO_GET
,
product_
code
->
valuestring
,
device_cod
e
->
valuestring
,
&
topic
);
break
;
case
MSG_LISTFOUND
:
_kk_utils_topic
(
DM_URI_THING_LIST_FOUND
,
product_
type
->
valuestring
,
device_nam
e
->
valuestring
,
&
topic
);
_kk_utils_topic
(
DM_URI_THING_LIST_FOUND
,
product_
code
->
valuestring
,
device_cod
e
->
valuestring
,
&
topic
);
break
;
case
MSG_LOGIN
:
_kk_utils_topic
(
DM_URI_COMBINE_LOGIN
,
product_
type
->
valuestring
,
device_nam
e
->
valuestring
,
&
topic
);
_kk_utils_topic
(
DM_URI_COMBINE_LOGIN
,
product_
code
->
valuestring
,
device_cod
e
->
valuestring
,
&
topic
);
break
;
case
MSG_LOGOUT
:
_kk_utils_topic
(
DM_URI_COMBINE_LOGOUT
,
product_
type
->
valuestring
,
device_nam
e
->
valuestring
,
&
topic
);
_kk_utils_topic
(
DM_URI_COMBINE_LOGOUT
,
product_
code
->
valuestring
,
device_cod
e
->
valuestring
,
&
topic
);
break
;
case
MSG_PROPERTYPOST
:
_kk_utils_topic
(
DM_URI_THING_EVENT_PROPERTY_POST
,
product_
type
->
valuestring
,
device_nam
e
->
valuestring
,
&
topic
);
_kk_utils_topic
(
DM_URI_THING_EVENT_PROPERTY_POST
,
product_
code
->
valuestring
,
device_cod
e
->
valuestring
,
&
topic
);
break
;
case
MSG_EVENTPOST
:
{
...
...
@@ -196,7 +220,7 @@ char* KK_Make_Topic(cJSON *info)
}
snprintf
(
service_name
,
service_name_len
,
DM_URI_THING_EVENT_POST
,
identify
->
valuestring
);
_kk_utils_topic
(
service_name
,
product_
type
->
valuestring
,
device_nam
e
->
valuestring
,
&
topic
);
_kk_utils_topic
(
service_name
,
product_
code
->
valuestring
,
device_cod
e
->
valuestring
,
&
topic
);
free
(
service_name
);
}
break
;
...
...
@@ -216,18 +240,18 @@ char* KK_Make_Topic(cJSON *info)
}
snprintf
(
service_name
,
service_name_len
,
DM_URI_THING_SERVICE_RESPONSE
,
identify
->
valuestring
);
_kk_utils_topic
(
service_name
,
product_
type
->
valuestring
,
device_nam
e
->
valuestring
,
&
topic
);
_kk_utils_topic
(
service_name
,
product_
code
->
valuestring
,
device_cod
e
->
valuestring
,
&
topic
);
free
(
service_name
);
}
break
;
case
MSG_SETREPLY
:
_kk_utils_topic
(
DM_URI_THING_SERVICE_PROPERTY_SET_REPLY
,
product_
type
->
valuestring
,
device_nam
e
->
valuestring
,
&
topic
);
_kk_utils_topic
(
DM_URI_THING_SERVICE_PROPERTY_SET_REPLY
,
product_
code
->
valuestring
,
device_cod
e
->
valuestring
,
&
topic
);
break
;
case
MSG_OTA_PROCESS
:
_kk_utils_topic
(
KK_URI_OTA_PROCESS
,
product_type
->
valuestring
,
device_nam
e
->
valuestring
,
&
topic
);
_kk_utils_topic
_ota
(
0
,
product_code
->
valuestring
,
device_cod
e
->
valuestring
,
&
topic
);
break
;
case
MSG_OTA_INFORM
:
_kk_utils_topic
(
KK_URI_OTA_INFORM
,
product_type
->
valuestring
,
device_nam
e
->
valuestring
,
&
topic
);
_kk_utils_topic
_ota
(
1
,
product_code
->
valuestring
,
device_cod
e
->
valuestring
,
&
topic
);
break
;
}
...
...
common/api/com_api.h
View file @
c02ee8a2
...
...
@@ -55,8 +55,9 @@ typedef enum{
}
kk_msg_type_t
;
#define MSG_TYPE_STR "msgtype"
#define MSG_PRODUCT_TYPE_STR "product_type"
#define MSG_DEVICE_NAME_STR "device_name"
#define MSG_PRODUCT_TYPE_STR "productType"
#define MSG_PRODUCT_CODE_STR "productCode"
#define MSG_DEVICE_CODE_STR "deviceCode"
#define MSG_PAYLOAD_STR "payload"
#define MSG_INFO_STR "info"
#define MSG_INDENTIFIER_STR "identifier"
...
...
common/hal/HAL_OS_linux.c
View file @
c02ee8a2
...
...
@@ -520,7 +520,7 @@ int HAL_Get_mac(char* mac)
printf
(
"mac ioctl error
\n
"
);
return
-
1
;
}
sprintf
(
mac_addr
,
"%02x
:%02x:%02x:%02x:%02x:
%02x"
,
sprintf
(
mac_addr
,
"%02x
%02x%02x%02x%02x
%02x"
,
(
unsigned
char
)
tmp
.
ifr_hwaddr
.
sa_data
[
0
],
(
unsigned
char
)
tmp
.
ifr_hwaddr
.
sa_data
[
1
],
(
unsigned
char
)
tmp
.
ifr_hwaddr
.
sa_data
[
2
],
...
...
common/hal/kk_product.h
View file @
c02ee8a2
...
...
@@ -29,8 +29,8 @@
#define SN_ADDR_LEN (32+1)
#define PRODUCT_TPYE "
a1OYuSBt23u
"
#define PRODUCT_CODE "
aIqEbWno8yDdsjCX15iq
"
#define PRODUCT_TPYE "
kk
"
#define PRODUCT_CODE "
15
"
int
HAL_SetProduct_Type
(
_IN_
char
*
product_type
);
int
HAL_SetProduct_Code
(
_IN_
char
*
product_code
);
...
...
midware/midware/dm/dm_ota.c
View file @
c02ee8a2
...
...
@@ -20,8 +20,8 @@ int dm_ota_init(void)
dm_ota_ctx_t
*
ctx
=
_dm_ota_get_ctx
();
memset
(
ctx
,
0
,
sizeof
(
dm_ota_ctx_t
));
HAL_GetProduct_Type
(
ctx
->
product
_key
);
HAL_GetProduct_Code
(
ctx
->
device
_nam
e
);
HAL_GetProduct_Type
(
ctx
->
product
Type
);
HAL_GetProduct_Code
(
ctx
->
device
Cod
e
);
return
SUCCESS_RETURN
;
}
...
...
@@ -32,7 +32,7 @@ int dm_ota_sub(void)
void
*
handle
=
NULL
;
/* Init OTA Handle */
handle
=
IOT_OTA_Init
(
ctx
->
product
_key
,
ctx
->
device_nam
e
,
NULL
);
handle
=
IOT_OTA_Init
(
ctx
->
product
Type
,
ctx
->
deviceCod
e
,
NULL
);
if
(
handle
==
NULL
)
{
return
FAIL_RETURN
;
}
...
...
@@ -43,14 +43,14 @@ int dm_ota_sub(void)
}
int
ota_uri_parse_pkdn
(
_IN_
char
*
uri
,
_IN_
int
uri_len
,
_IN_
int
start_deli
,
_IN_
int
end_deli
,
_OU_
char
product
_key
[
PRODUCT_KEY_MAXLEN
],
_OU_
char
device_name
[
DEVICE_NAM
E_MAXLEN
])
_OU_
char
product
Type
[
PRODUCT_TYPE_MAXLEN
],
_OU_
char
deviceCode
[
DEVICE_COD
E_MAXLEN
])
{
int
res
=
0
,
start
=
0
,
end
=
0
,
slice
=
0
;
int
item_index
=
0
;
int
count
=
0
;
if
(
uri
==
NULL
||
uri_len
<=
0
||
product
_key
==
NULL
||
device_nam
e
==
NULL
||
(
strlen
(
product
_key
)
>=
PRODUCT_KEY_MAXLEN
)
||
(
strlen
(
device_name
)
>=
DEVICE_NAM
E_MAXLEN
))
{
if
(
uri
==
NULL
||
uri_len
<=
0
||
product
Type
==
NULL
||
deviceCod
e
==
NULL
||
(
strlen
(
product
Type
)
>=
PRODUCT_TYPE_MAXLEN
)
||
(
strlen
(
deviceCode
)
>=
DEVICE_COD
E_MAXLEN
))
{
return
INVALID_PARAMETER
;
}
...
...
@@ -75,21 +75,21 @@ int ota_uri_parse_pkdn(_IN_ char *uri, _IN_ int uri_len, _IN_ int start_deli, _I
/* dm_log_debug("URI Product Key: %.*s, Device Name: %.*s", slice - start - 1, uri + start + 1, end - slice - 1,
uri + slice + 1); */
memcpy
(
product
_key
,
uri
+
start
+
1
,
slice
-
start
-
1
);
memcpy
(
device
_nam
e
,
uri
+
slice
+
1
,
end
-
slice
-
1
);
memcpy
(
product
Type
,
uri
+
start
+
1
,
slice
-
start
-
1
);
memcpy
(
device
Cod
e
,
uri
+
slice
+
1
,
end
-
slice
-
1
);
return
SUCCESS_RETURN
;
}
int
dm_ota_setPKN
(
char
product
_key
[
PRODUCT_KEY_MAXLEN
],
char
device_name
[
DEVICE_NAM
E_MAXLEN
])
int
dm_ota_setPKN
(
char
product
Type
[
PRODUCT_TYPE_MAXLEN
],
char
deviceCode
[
DEVICE_COD
E_MAXLEN
])
{
dm_ota_ctx_t
*
ctx
=
_dm_ota_get_ctx
();
int
res
=
0
;
memset
(
ctx
->
product
_key
,
0
,
PRODUCT_KEY
_MAXLEN
);
memset
(
ctx
->
device
_name
,
0
,
DEVICE_NAM
E_MAXLEN
);
memcpy
(
ctx
->
product
_key
,
product_key
,
PRODUCT_KEY
_MAXLEN
);
memcpy
(
ctx
->
device
_name
,
device_name
,
DEVICE_NAM
E_MAXLEN
);
memset
(
ctx
->
product
Type
,
0
,
PRODUCT_TYPE
_MAXLEN
);
memset
(
ctx
->
device
Code
,
0
,
DEVICE_COD
E_MAXLEN
);
memcpy
(
ctx
->
product
Type
,
productType
,
PRODUCT_TYPE
_MAXLEN
);
memcpy
(
ctx
->
device
Code
,
deviceCode
,
DEVICE_COD
E_MAXLEN
);
return
SUCCESS_RETURN
;
}
...
...
@@ -176,7 +176,7 @@ void dm_ota_handle(void *data){
cJSON
*
json
,
*
info_root
,
*
info
;
cJSON
*
topic
,
*
typeJson
;
cJSON
*
payload
;
cJSON
*
product_type
,
*
device_
nam
e
;
cJSON
*
product_type
,
*
device_
cod
e
;
json
=
cJSON_Parse
(
data
);
if
(
json
==
NULL
)
{
printf
(
"Error before: [%s]
\n
"
,
"cJSON_Parse"
);
...
...
@@ -187,7 +187,7 @@ void dm_ota_handle(void *data){
info
=
cJSON_Parse
(
info_root
->
valuestring
);
typeJson
=
cJSON_GetObjectItem
(
info
,
MSG_TYPE_STR
);
product_type
=
cJSON_GetObjectItem
(
info
,
MSG_PRODUCT_TYPE_STR
);
device_
name
=
cJSON_GetObjectItem
(
info
,
MSG_DEVICE_NAM
E_STR
);
device_
code
=
cJSON_GetObjectItem
(
info
,
MSG_DEVICE_COD
E_STR
);
payload
=
cJSON_GetObjectItem
(
json
,
MSG_PAYLOAD_STR
);
printf
(
" payload= %s
\n
"
,
payload
->
valuestring
);
...
...
@@ -195,7 +195,7 @@ void dm_ota_handle(void *data){
char
buf
[
128
]
=
{
0
};
int
len
=
128
;
if
(
dm_ota_check
(
payload
->
valuestring
,
strlen
(
payload
->
valuestring
)
+
1
,
IOTX_OTA_TOPIC_TYPE_DEVICE_UPGRATE
)
==
0
){
dm_ota_setPKN
(
product_type
->
valuestring
,
device_
nam
e
->
valuestring
);
dm_ota_setPKN
(
product_type
->
valuestring
,
device_
cod
e
->
valuestring
);
dm_fota_perform_sync
(
buf
,
len
);
}
else
{
printf
(
"parse params error !!
\n
"
);
...
...
midware/midware/dm/dm_ota.h
View file @
c02ee8a2
...
...
@@ -11,8 +11,8 @@
typedef
struct
{
void
*
ota_handle
;
char
product
_key
[
PRODUCT_KEY
_MAXLEN
];
char
device
_name
[
DEVICE_NAM
E_MAXLEN
];
char
product
Type
[
PRODUCT_TYPE
_MAXLEN
];
char
device
Code
[
DEVICE_COD
E_MAXLEN
];
}
dm_ota_ctx_t
;
int
dm_ota_init
(
void
);
...
...
midware/midware/dm/kk_dm_api.c
View file @
c02ee8a2
...
...
@@ -38,23 +38,18 @@ static void _dm_api_unlock(void)
int
kk_dm_subdev_register
(
_IN_
int
devid
)
{
int
res
=
0
;
dm_mgr_dev_node_t
*
search_node
=
NULL
;
//
dm_mgr_dev_node_t *search_node = NULL;
if
(
devid
<
0
)
{
return
INVALID_PARAMETER
;
}
_dm_api_lock
();
res
=
dm_mgr_search_dev_by_devid
(
devid
,
(
void
**
)
&
search_node
);
if
(
res
!=
SUCCESS_RETURN
)
{
_dm_api_unlock
();
return
FAIL_RETURN
;
}
if
((
strlen
(
search_node
->
device_secret
)
>
0
)
&&
(
strlen
(
search_node
->
device_secret
)
<
DEVICE_SECRET_MAXLEN
))
{
_dm_api_unlock
();
return
SUCCESS_RETURN
;
}
//res = dm_mgr_search_dev_by_devid(devid, (void **)&search_node);
//if (res != SUCCESS_RETURN) {
// _dm_api_unlock();
//return FAIL_RETURN;
//}
res
=
dm_mgr_upstream_thing_sub_register
(
devid
);
...
...
@@ -275,9 +270,6 @@ ERROR:
int
iotx_dm_subscribe
(
_IN_
int
devid
)
{
int
res
=
0
,
dev_type
=
0
;
char
product_key
[
PRODUCT_KEY_MAXLEN
]
=
{
0
};
char
device_name
[
DEVICE_NAME_MAXLEN
]
=
{
0
};
char
device_secret
[
DEVICE_SECRET_MAXLEN
]
=
{
0
};
if
(
devid
<
0
)
{
return
INVALID_PARAMETER
;
...
...
@@ -294,12 +286,12 @@ int iotx_dm_subscribe(_IN_ int devid)
//send app to subscribe mqtt
const
char
subscribe_cmd
[]
=
"{
\"
cmd
\"
:
\"
subscribe
\"
,
\"
data
\"
:{
\"
productType
\"
:
\"
%s
\"
,
\"
productCode
\"
:
\"
%s
\"
}}"
;
int
len
=
strlen
(
subscribe_cmd
)
+
strlen
(
node
->
product
_key
)
+
strlen
(
node
->
device_nam
e
)
+
1
;
"{
\"
cmd
\"
:
\"
subscribe
\"
,
\"
data
\"
:{
\"
productType
\"
:
\"
%s
\"
,
\"
productCode
\"
:
\"
%s
\"
,
\"
deviceCode
\"
:
\"
%s
\"
}}"
;
int
len
=
strlen
(
subscribe_cmd
)
+
strlen
(
node
->
product
Type
)
+
strlen
(
node
->
productCode
)
+
strlen
(
node
->
deviceCod
e
)
+
1
;
void
*
buf
=
malloc
(
len
);
if
(
buf
){
HAL_Snprintf
(
buf
,
len
,
subscribe_cmd
,
node
->
product
_key
,
node
->
device_nam
e
);
HAL_Snprintf
(
buf
,
len
,
subscribe_cmd
,
node
->
product
Type
,
node
->
productCode
,
node
->
deviceCod
e
);
kk_ipc_send
(
IPC_MID2APP
,
buf
,
len
);
free
(
buf
);
}
else
{
...
...
midware/midware/dm/kk_dm_mng.c
View file @
c02ee8a2
...
...
@@ -60,17 +60,17 @@ int dm_mgr_search_dev_by_devid(_IN_ int devid, _OU_ dm_mgr_dev_node_t **node)
ERROR_PRINT
(
"Device Not Found, devid: %d"
,
devid
);
return
FAIL_RETURN
;
}
static
int
_dm_mgr_search_dev_by_pkdn
(
_IN_
char
product
_key
[
PRODUCT_KEY
_MAXLEN
],
_IN_
char
device
_name
[
DEVICE_NAM
E_MAXLEN
],
_OU_
dm_mgr_dev_node_t
**
node
)
static
int
_dm_mgr_search_dev_by_pkdn
(
_IN_
char
product
Type
[
PRODUCT_TYPE
_MAXLEN
],
_IN_
char
device
Code
[
DEVICE_COD
E_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
->
product
_key
)
==
strlen
(
product_key
))
&&
(
memcmp
(
search_node
->
product
_key
,
product_key
,
strlen
(
product_key
))
==
0
)
&&
(
strlen
(
search_node
->
device
_name
)
==
strlen
(
device_nam
e
))
&&
(
memcmp
(
search_node
->
device
_name
,
device_name
,
strlen
(
device_nam
e
))
==
0
))
{
if
((
strlen
(
search_node
->
product
Type
)
==
strlen
(
productType
))
&&
(
memcmp
(
search_node
->
product
Type
,
productType
,
strlen
(
productType
))
==
0
)
&&
(
strlen
(
search_node
->
device
Code
)
==
strlen
(
deviceCod
e
))
&&
(
memcmp
(
search_node
->
device
Code
,
deviceCode
,
strlen
(
deviceCod
e
))
==
0
))
{
/* dm_log_debug("Device Found, Product Key: %s, Device Name: %s", product_key, device_name); */
if
(
node
)
{
*
node
=
search_node
;
...
...
@@ -79,7 +79,7 @@ static int _dm_mgr_search_dev_by_pkdn(_IN_ char product_key[PRODUCT_KEY_MAXLEN],
}
}
ERROR_PRINT
(
"Device Not Found, Product
Key: %s, Device Name: %s"
,
product_key
,
device_nam
e
);
ERROR_PRINT
(
"Device Not Found, Product
Type: %s, Device Code: %s"
,
productType
,
deviceCod
e
);
return
FAIL_RETURN
;
}
static
int
_dm_mgr_next_devid
(
void
)
...
...
@@ -138,29 +138,24 @@ static int _dm_init_tsl_params(int devId)
}
return
res
;
}
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
],
_IN_
char
device_m
ac
[
DEVICE_MAC_MAXLEN
],
_OU_
int
*
devid
)
int
dm_mgr_device_create
(
_IN_
int
dev_type
,
_IN_
char
product
Type
[
PRODUCT_TYPE
_MAXLEN
],
_IN_
char
productCode
[
PRODUCT_CODE_MAXLEN
],
_IN_
char
deviceCode
[
DEVICE_CODE_MAXLEN
],
_IN_
char
fatherM
ac
[
DEVICE_MAC_MAXLEN
],
_OU_
int
*
devid
)
{
int
res
=
0
;
dm_mgr_ctx
*
ctx
=
_dm_mgr_get_ctx
();
dm_mgr_dev_node_t
*
node
=
NULL
;
char
*
tsl_str
=
NULL
;
int
idx
=
0
;
if
(
product_key
==
NULL
||
device_name
==
NULL
||
strlen
(
product_key
)
>=
PRODUCT_KEY_MAXLEN
||
strlen
(
device_name
)
>=
DEVICE_NAME_MAXLEN
)
{
return
INVALID_PARAMETER
;
}
if
(
device_secret
!=
NULL
&&
strlen
(
device_secret
)
>=
DEVICE_SECRET_MAXLEN
)
{
if
(
productType
!=
NULL
&&
strlen
(
productType
)
>=
PRODUCT_TYPE_MAXLEN
)
{
return
INVALID_PARAMETER
;
}
if
(
device
_mac
!=
NULL
&&
strlen
(
device_mac
)
>=
DEVICE_MAC
_MAXLEN
)
{
if
(
device
Code
!=
NULL
&&
strlen
(
deviceCode
)
>=
DEVICE_CODE
_MAXLEN
)
{
return
INVALID_PARAMETER
;
}
res
=
_dm_mgr_search_dev_by_pkdn
(
product
_key
,
device_nam
e
,
&
node
);
res
=
_dm_mgr_search_dev_by_pkdn
(
product
Type
,
deviceCod
e
,
&
node
);
if
(
res
==
SUCCESS_RETURN
)
{
if
(
devid
)
{
*
devid
=
node
->
devid
;
...
...
@@ -174,23 +169,27 @@ int dm_mgr_device_create(_IN_ int dev_type, _IN_ char product_key[PRODUCT_KEY_MA
}
memset
(
node
,
0
,
sizeof
(
dm_mgr_dev_node_t
));
if
(
dev_type
==
KK_DM_DEVICE_
GATEWAY
)
if
(
dev_type
==
KK_DM_DEVICE_
CCU
)
node
->
devid
=
0
;
else
node
->
devid
=
_dm_mgr_next_devid
();
node
->
dev_type
=
dev_type
;
node
->
dev_shadow
=
NULL
;
memcpy
(
node
->
product_key
,
product_key
,
strlen
(
product_key
));
memcpy
(
node
->
device_name
,
device_name
,
strlen
(
device_name
));
if
(
device_secret
!=
NULL
)
{
memcpy
(
node
->
device_secret
,
device_secret
,
strlen
(
device_secret
));
if
(
productType
!=
NULL
)
{
memcpy
(
node
->
productType
,
productType
,
strlen
(
productType
));
}
if
(
productCode
!=
NULL
)
{
memcpy
(
node
->
productCode
,
productCode
,
strlen
(
productCode
));
}
if
(
deviceCode
!=
NULL
)
{
memcpy
(
node
->
deviceCode
,
deviceCode
,
strlen
(
deviceCode
));
}
if
(
dev
ice_m
ac
!=
NULL
)
{
memcpy
(
node
->
device_mac
,
device_mac
,
strlen
(
device_m
ac
));
if
(
dev
_type
!=
KK_DM_DEVICE_CCU
&&
fatherM
ac
!=
NULL
)
{
memcpy
(
node
->
fatherMac
,
fatherMac
,
strlen
(
fatherM
ac
));
}
//node->dev_status = IOTX_DM_DEV_STATUS_AUTHORIZED;
tsl_str
=
kk_load_json
(
product
_key
);
tsl_str
=
kk_load_json
(
product
Code
,
dev_type
);
if
(
tsl_str
!=
NULL
)
{
res
=
kk_tsl_create
(
tsl_str
,
strlen
(
tsl_str
),
&
node
->
dev_shadow
);
...
...
@@ -202,8 +201,8 @@ int dm_mgr_device_create(_IN_ int dev_type, _IN_ char product_key[PRODUCT_KEY_MA
INIT_LIST_HEAD
(
&
node
->
linked_list
);
list_add_tail
(
&
node
->
linked_list
,
&
ctx
->
dev_list
);
if
(
dev_type
==
KK_DM_DEVICE_
GATEWAY
){
_dm_init_tsl_params
(
node
->
devid
);
if
(
dev_type
==
KK_DM_DEVICE_
CCU
){
//
_dm_init_tsl_params(node->devid);
}
if
(
devid
)
{
...
...
@@ -212,17 +211,17 @@ int dm_mgr_device_create(_IN_ int dev_type, _IN_ char product_key[PRODUCT_KEY_MA
return
SUCCESS_RETURN
;
}
int
dm_mgr_search_device_by_pkdn
(
_IN_
char
product
_key
[
PRODUCT_KEY_MAXLEN
],
_IN_
char
device_name
[
DEVICE_NAM
E_MAXLEN
],
int
dm_mgr_search_device_by_pkdn
(
_IN_
char
product
Type
[
PRODUCT_TYPE_MAXLEN
],
_IN_
char
deviceCode
[
DEVICE_COD
E_MAXLEN
],
_OU_
int
*
devid
)
{
int
res
=
0
;
dm_mgr_dev_node_t
*
node
=
NULL
;
if
(
product
_key
==
NULL
||
device_nam
e
==
NULL
)
{
if
(
product
Type
==
NULL
||
deviceCod
e
==
NULL
)
{
return
INVALID_PARAMETER
;
}
res
=
_dm_mgr_search_dev_by_pkdn
(
product
_key
,
device_nam
e
,
&
node
);
res
=
_dm_mgr_search_dev_by_pkdn
(
product
Type
,
deviceCod
e
,
&
node
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
...
...
@@ -239,59 +238,59 @@ int dm_mgr_search_mac_by_topic(_IN_ char* topic, _OU_ char mac[DEVI
int
res
=
0
;
dm_mgr_dev_node_t
*
node
=
NULL
;
char
product
_key
[
PRODUCT_KEY
_MAXLEN
]
=
{
0
};
char
device
_name
[
DEVICE_NAM
E_MAXLEN
]
=
{
0
};
char
product
Type
[
PRODUCT_TYPE
_MAXLEN
]
=
{
0
};
char
device
Code
[
DEVICE_COD
E_MAXLEN
]
=
{
0
};
if
(
topic
==
NULL
)
{
return
INVALID_PARAMETER
;
}
res
=
kk_msg_uri_parse_pkdn
((
char
*
)
topic
,
strlen
(
topic
),
2
+
KK_URI_OFFSET
,
4
+
KK_URI_OFFSET
,
product
_key
,
device
_nam
e
);
res
=
kk_msg_uri_parse_pkdn
((
char
*
)
topic
,
strlen
(
topic
),
2
+
KK_URI_OFFSET
,
4
+
KK_URI_OFFSET
,
product
Type
,
device
Cod
e
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
res
=
_dm_mgr_search_dev_by_pkdn
(
product
_key
,
device_nam
e
,
&
node
);
res
=
_dm_mgr_search_dev_by_pkdn
(
product
Type
,
deviceCod
e
,
&
node
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
memcpy
(
mac
,
node
->
device
_mac
,
DEVICE_MAC_MAXLEN
);
memcpy
(
mac
,
node
->
device
Code
,
DEVICE_MAC_MAXLEN
);
return
SUCCESS_RETURN
;
}
int
dm_mgr_search_mac_by_pkdn
(
_IN_
char
product
_key
[
PRODUCT_KEY_MAXLEN
],
_IN_
char
device_name
[
DEVICE_NAM
E_MAXLEN
],
int
dm_mgr_search_mac_by_pkdn
(
_IN_
char
product
Type
[
PRODUCT_TYPE_MAXLEN
],
_IN_
char
deviceCode
[
DEVICE_COD
E_MAXLEN
],
_OU_
char
mac
[
DEVICE_MAC_MAXLEN
])
{
int
res
=
0
;
dm_mgr_dev_node_t
*
node
=
NULL
;
if
(
product
_key
==
NULL
||
device_nam
e
==
NULL
)
{
if
(
product
Type
==
NULL
||
deviceCod
e
==
NULL
)
{
return
INVALID_PARAMETER
;
}
res
=
_dm_mgr_search_dev_by_pkdn
(
product
_key
,
device_nam
e
,
&
node
);
res
=
_dm_mgr_search_dev_by_pkdn
(
product
Type
,
deviceCod
e
,
&
node
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
memcpy
(
mac
,
node
->
device
_mac
,
DEVICE_MAC_MAXLEN
);
memcpy
(
mac
,
node
->
device
Code
,
DEVICE_MAC_MAXLEN
);
return
SUCCESS_RETURN
;
}
int
dm_mgr_get_device_by_mac
(
_IN_
char
device
_mac
[
DEVICE_MAC_MAXLEN
],
_OU_
dm_mgr_dev_node_t
**
node
)
int
dm_mgr_get_device_by_mac
(
_IN_
char
device
Code
[
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
))
{
if
((
strlen
(
search_node
->
device
Code
)
==
strlen
(
deviceCode
))
&&
(
memcmp
(
search_node
->
device
Code
,
deviceCode
,
strlen
(
deviceCode
))
==
0
))
{
/* dm_log_debug("Device Found, Product Key: %s, Device Name: %s", product_key, device_name); */
if
(
node
)
{
*
node
=
search_node
;
...
...
@@ -300,20 +299,20 @@ int dm_mgr_get_device_by_mac(_IN_ char device_mac[DEVICE_MAC_MAXLEN], _OU_ dm_mg
}
}
ERROR_PRINT
(
"Device Not Found, device
_mac: %s
\n
"
,
device_mac
);
ERROR_PRINT
(
"Device Not Found, device
Code: %s
\n
"
,
deviceCode
);
return
FAIL_RETURN
;
}
int
dm_mgr_get_devId_by_mac
(
_IN_
char
device
_mac
[
DEVICE_MAC_MAXLEN
],
_OU_
int
*
devid
)
int
dm_mgr_get_devId_by_mac
(
_IN_
char
device
Code
[
DEVICE_MAC_MAXLEN
],
_OU_
int
*
devid
)
{
int
res
=
0
;
dm_mgr_dev_node_t
*
node
=
NULL
;
if
(
device
_mac
==
NULL
)
{
if
(
device
Code
==
NULL
)
{
return
INVALID_PARAMETER
;
}
res
=
dm_mgr_get_device_by_mac
(
device
_mac
,
&
node
);
res
=
dm_mgr_get_device_by_mac
(
device
Code
,
&
node
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
...
...
@@ -344,9 +343,9 @@ int dm_mgr_init(void)
{
int
res
=
0
;
dm_mgr_ctx
*
ctx
=
_dm_mgr_get_ctx
();
char
product
_key
[
PRODUCT_KEY
_MAXLEN
]
=
{
0
};
char
device_name
[
DEVICE_NAM
E_MAXLEN
]
=
{
0
};
char
device
_secret
[
DEVICE_SECRET
_MAXLEN
]
=
{
0
};
char
product
Type
[
PRODUCT_TYPE
_MAXLEN
]
=
{
0
};
char
productCode
[
PRODUCT_COD
E_MAXLEN
]
=
{
0
};
char
device
Code
[
DEVICE_CODE
_MAXLEN
]
=
{
0
};
int
devId
=
0
;
memset
(
ctx
,
0
,
sizeof
(
dm_mgr_ctx
));
...
...
@@ -361,18 +360,19 @@ int dm_mgr_init(void)
/* Init Device List */
INIT_LIST_HEAD
(
&
ctx
->
dev_list
);
HAL_GetProduct_Type
(
product_key
);
HAL_GetProduct_Code
(
device_name
);
//memset(product_key,0x0,sizeof(product_key));
//memset(device_name,0x0,sizeof(device_name));
//memcpy(product_key,"a1OYuSBt23u",strlen("a1OYuSBt23u"));
//memcpy(device_name,"aIqEbWno8yDdsjCX15iq",strlen("aIqEbWno8yDdsjCX15iq"));
//_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
,
"aabbccddeeff1120"
,
&
devId
);
//HAL_GetProduct_Type(product_key);
//HAL_GetProduct_Code(device_name);
memset
(
deviceCode
,
0x0
,
sizeof
(
deviceCode
));
HAL_Get_mac
(
deviceCode
);
res
=
dm_mgr_device_create
(
KK_DM_DEVICE_CCU
,
KK_DM_CCU_DEVICE_PRODUCT_TYPE
,
KK_DM_CCU_DEVICE_PRODUCT_CODE
,
deviceCode
,
""
,
&
devId
);
if
(
res
!=
SUCCESS_RETURN
)
{
goto
ERROR
;
}
res
=
dm_mgr_device_create
(
KK_DM_DEVICE_GATEWAY
,
KK_DM_GW_DEVICE_PRODUCT_TYPE
,
KK_DM_GW_DEVICE_PRODUCT_CODE
,
"588E81FFFED3834A"
,
deviceCode
,
&
devId
);
if
(
res
!=
SUCCESS_RETURN
)
{
goto
ERROR
;
}
return
SUCCESS_RETURN
;
ERROR:
...
...
@@ -436,8 +436,9 @@ static int _dm_mgr_upstream_request_assemble(_IN_ int msgid, _IN_ int devid,
{
memcpy
(
request
->
identity
,
identify
,
strlen
(
identify
));
}
memcpy
(
request
->
product_key
,
node
->
product_key
,
strlen
(
node
->
product_key
));
memcpy
(
request
->
device_name
,
node
->
device_name
,
strlen
(
node
->
device_name
));
memcpy
(
request
->
productType
,
node
->
productType
,
strlen
(
node
->
productType
));
memcpy
(
request
->
productCode
,
node
->
productCode
,
strlen
(
node
->
productCode
));
memcpy
(
request
->
deviceCode
,
node
->
deviceCode
,
strlen
(
node
->
deviceCode
));
request
->
params
=
payload_param
;
request
->
params_len
=
paramLen
;
request
->
method
=
method
;
...
...
@@ -522,8 +523,9 @@ static int _kk_mgr_upstream_response_assemble(_IN_ int devid, _IN_ char *msgid,
{
memcpy
(
response
->
identity
,
identfy
,
strlen
(
identfy
));
}
memcpy
(
response
->
product_key
,
node
->
product_key
,
strlen
(
node
->
product_key
));
memcpy
(
response
->
device_name
,
node
->
device_name
,
strlen
(
node
->
device_name
));
memcpy
(
response
->
productType
,
node
->
productType
,
strlen
(
node
->
productType
));
memcpy
(
response
->
productCode
,
node
->
productCode
,
strlen
(
node
->
productCode
));
memcpy
(
response
->
deviceCode
,
node
->
deviceCode
,
strlen
(
node
->
deviceCode
));
response
->
code
=
code
;
return
SUCCESS_RETURN
;
...
...
@@ -573,6 +575,7 @@ int dm_mgr_upstream_thing_sub_register(_IN_ int devid)
{
int
res
=
0
;
dm_mgr_dev_node_t
*
node
=
NULL
;
dm_mgr_dev_node_t
*
gw_node
=
NULL
;
dm_msg_request_t
request
;
if
(
devid
<
0
)
{
...
...
@@ -581,19 +584,23 @@ int dm_mgr_upstream_thing_sub_register(_IN_ int devid)
res
=
dm_mgr_search_dev_by_devid
(
devid
,
&
node
);
if
(
res
!=
SUCCESS_RETURN
)
{
ERROR_PRINT
(
"ERROR [%s][%d] res:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
res
);
return
FAIL_RETURN
;
}
res
=
dm_mgr_get_device_by_mac
(
node
->
fatherMac
,
&
gw_node
);
if
(
res
!=
SUCCESS_RETURN
)
{
ERROR_PRINT
(
"ERROR [%s][%d] res:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
res
);
return
FAIL_RETURN
;
}
memset
(
&
request
,
0
,
sizeof
(
dm_msg_request_t
));
//request.service_prefix = DM_URI_SYS_PREFIX;
//request.service_name = DM_URI_THING_SUB_REGISTER;
request
.
msgtype
=
MSG_REGISTER
;
memcpy
(
request
.
identity
,
""
,
strlen
(
""
));
HAL_GetProduct_Type
(
request
.
product_key
);
HAL_GetProduct_Code
(
request
.
device_name
);
memcpy
(
request
.
productType
,
gw_node
->
productType
,
strlen
(
gw_node
->
productType
)
);
memcpy
(
request
.
productCode
,
gw_node
->
productCode
,
strlen
(
gw_node
->
productCode
));
memcpy
(
request
.
deviceCode
,
gw_node
->
deviceCode
,
strlen
(
gw_node
->
deviceCode
));
/* Get Params And Method */
res
=
dm_msg_thing_sub_register
(
node
->
product
_key
,
node
->
device_nam
e
,
&
request
);
res
=
dm_msg_thing_sub_register
(
node
->
product
Type
,
node
->
productCode
,
node
->
deviceCod
e
,
&
request
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
...
...
@@ -621,6 +628,7 @@ int dm_mgr_upstream_thing_sub_unregister(_IN_ int devid)
{
int
res
=
0
;
dm_mgr_dev_node_t
*
node
=
NULL
;
dm_mgr_dev_node_t
*
gw_node
=
NULL
;
dm_msg_request_t
request
;
if
(
devid
<
0
)
{
...
...
@@ -631,15 +639,22 @@ int dm_mgr_upstream_thing_sub_unregister(_IN_ int devid)
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
res
=
dm_mgr_get_device_by_mac
(
node
->
fatherMac
,
&
gw_node
);
if
(
res
!=
SUCCESS_RETURN
)
{
ERROR_PRINT
(
"ERROR [%s][%d] res:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
res
);
return
FAIL_RETURN
;
}
memset
(
&
request
,
0
,
sizeof
(
dm_msg_request_t
));
request
.
msgtype
=
MSG_UNREGISTER
;
memset
(
request
.
identity
,
""
,
strlen
(
""
));
HAL_GetProduct_Type
(
request
.
product_key
);
HAL_GetProduct_Code
(
request
.
device_name
);
memcpy
(
request
.
productType
,
gw_node
->
productType
,
strlen
(
gw_node
->
productType
));
memcpy
(
request
.
productCode
,
gw_node
->
productCode
,
strlen
(
gw_node
->
productCode
));
memcpy
(
request
.
deviceCode
,
gw_node
->
deviceCode
,
strlen
(
gw_node
->
deviceCode
));
/* Get Params And Method */
res
=
dm_msg_thing_sub_unregister
(
node
->
product
_key
,
node
->
device_nam
e
,
&
request
);
res
=
dm_msg_thing_sub_unregister
(
node
->
product
Type
,
node
->
deviceCod
e
,
&
request
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
...
...
@@ -669,6 +684,7 @@ int dm_mgr_upstream_thing_topo_add(_IN_ int devid)
{
int
res
=
0
;
dm_mgr_dev_node_t
*
node
=
NULL
;
dm_mgr_dev_node_t
*
gw_node
=
NULL
;
dm_msg_request_t
request
;
if
(
devid
<
0
)
{
...
...
@@ -679,15 +695,22 @@ int dm_mgr_upstream_thing_topo_add(_IN_ int devid)
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
res
=
dm_mgr_get_device_by_mac
(
node
->
fatherMac
,
&
gw_node
);
if
(
res
!=
SUCCESS_RETURN
)
{
ERROR_PRINT
(
"ERROR [%s][%d] res:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
res
);
return
FAIL_RETURN
;
}
memset
(
&
request
,
0
,
sizeof
(
dm_msg_request_t
));
request
.
msgtype
=
MSG_TOPOADD
;
memcpy
(
request
.
identity
,
""
,
strlen
(
""
));
HAL_GetProduct_Type
(
request
.
product_key
);
HAL_GetProduct_Code
(
request
.
device_name
);
memcpy
(
request
.
productType
,
gw_node
->
productType
,
strlen
(
gw_node
->
productType
));
memcpy
(
request
.
productCode
,
gw_node
->
productCode
,
strlen
(
gw_node
->
productCode
));
memcpy
(
request
.
deviceCode
,
gw_node
->
deviceCode
,
strlen
(
gw_node
->
deviceCode
));
/* Get Params And Method */
res
=
dm_msg_thing_topo_add
(
node
->
product
_key
,
node
->
device_name
,
node
->
device_secret
,
&
request
);
res
=
dm_msg_thing_topo_add
(
node
->
product
Type
,
node
->
productCode
,
node
->
deviceCode
,
&
request
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
...
...
@@ -717,6 +740,7 @@ int dm_mgr_upstream_thing_topo_delete(_IN_ int devid)
{
int
res
=
0
;
dm_mgr_dev_node_t
*
node
=
NULL
;
dm_mgr_dev_node_t
*
gw_node
=
NULL
;
dm_msg_request_t
request
;
if
(
devid
<
0
)
{
...
...
@@ -727,15 +751,24 @@ int dm_mgr_upstream_thing_topo_delete(_IN_ int devid)
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
res
=
dm_mgr_get_device_by_mac
(
node
->
fatherMac
,
&
gw_node
);
if
(
res
!=
SUCCESS_RETURN
)
{
ERROR_PRINT
(
"ERROR [%s][%d] res:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
res
);
return
FAIL_RETURN
;
}
memset
(
&
request
,
0
,
sizeof
(
dm_msg_request_t
));
request
.
msgtype
=
MSG_TOPODELETE
;
memcpy
(
request
.
identity
,
""
,
strlen
(
""
));
HAL_GetProduct_Type
(
request
.
product_key
);
HAL_GetProduct_Code
(
request
.
device_name
);
memcpy
(
request
.
productType
,
gw_node
->
productType
,
strlen
(
gw_node
->
productType
));
memcpy
(
request
.
productCode
,
gw_node
->
productCode
,
strlen
(
gw_node
->
productCode
));
memcpy
(
request
.
deviceCode
,
gw_node
->
deviceCode
,
strlen
(
gw_node
->
deviceCode
));
/* Get Params And Method */
res
=
dm_msg_thing_topo_delete
(
node
->
product
_key
,
node
->
device_nam
e
,
&
request
);
res
=
dm_msg_thing_topo_delete
(
node
->
product
Type
,
node
->
deviceCod
e
,
&
request
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
...
...
@@ -765,15 +798,17 @@ int dm_mgr_upstream_thing_topo_get(void)
{
int
res
=
0
;
dm_mgr_dev_node_t
*
node
=
NULL
;
dm_msg_request_t
request
;
memset
(
&
request
,
0
,
sizeof
(
dm_msg_request_t
));
request
.
msgtype
=
MSG_TOPOGET
;
memcpy
(
request
.
identity
,
""
,
strlen
(
""
));
HAL_GetProduct_Type
(
request
.
product_key
);
HAL_GetProduct_Code
(
request
.
device_name
);
HAL_GetProduct_Type
(
request
.
productType
);
HAL_GetProduct_Code
(
request
.
deviceCode
);
res
=
_dm_mgr_search_dev_by_pkdn
(
request
.
product
_key
,
request
.
device_nam
e
,
&
node
);
res
=
_dm_mgr_search_dev_by_pkdn
(
request
.
product
Type
,
request
.
deviceCod
e
,
&
node
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
...
...
@@ -807,6 +842,7 @@ int dm_mgr_upstream_thing_list_found(_IN_ int devid)
{
int
res
=
0
;
dm_mgr_dev_node_t
*
node
=
NULL
;
dm_mgr_dev_node_t
*
gw_node
=
NULL
;
dm_msg_request_t
request
;
if
(
devid
<
0
)
{
...
...
@@ -817,15 +853,22 @@ int dm_mgr_upstream_thing_list_found(_IN_ int devid)
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
res
=
dm_mgr_get_device_by_mac
(
node
->
fatherMac
,
&
gw_node
);
if
(
res
!=
SUCCESS_RETURN
)
{
ERROR_PRINT
(
"ERROR [%s][%d] res:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
res
);
return
FAIL_RETURN
;
}
memset
(
&
request
,
0
,
sizeof
(
dm_msg_request_t
));
request
.
msgtype
=
MSG_LISTFOUND
;
memcpy
(
request
.
identity
,
""
,
strlen
(
""
));
HAL_GetProduct_Type
(
request
.
product_key
);
HAL_GetProduct_Code
(
request
.
device_name
);
memcpy
(
request
.
productType
,
gw_node
->
productType
,
strlen
(
gw_node
->
productType
));
memcpy
(
request
.
productCode
,
gw_node
->
productCode
,
strlen
(
gw_node
->
productCode
));
memcpy
(
request
.
deviceCode
,
gw_node
->
deviceCode
,
strlen
(
gw_node
->
deviceCode
));
/* Get Params And Method */
res
=
dm_msg_thing_list_found
(
node
->
product
_key
,
node
->
device_nam
e
,
&
request
);
res
=
dm_msg_thing_list_found
(
node
->
product
Type
,
node
->
deviceCod
e
,
&
request
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
...
...
@@ -854,6 +897,7 @@ int dm_mgr_upstream_combine_login(_IN_ int devid)
{
int
res
=
0
;
dm_mgr_dev_node_t
*
node
=
NULL
;
dm_mgr_dev_node_t
*
gw_node
=
NULL
;
dm_msg_request_t
request
;
if
(
devid
<
0
)
{
...
...
@@ -864,15 +908,22 @@ int dm_mgr_upstream_combine_login(_IN_ int devid)
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
res
=
dm_mgr_get_device_by_mac
(
node
->
fatherMac
,
&
gw_node
);
if
(
res
!=
SUCCESS_RETURN
)
{
ERROR_PRINT
(
"ERROR [%s][%d] res:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
res
);
return
FAIL_RETURN
;
}
memset
(
&
request
,
0
,
sizeof
(
dm_msg_request_t
));
request
.
msgtype
=
MSG_LOGIN
;
memcpy
(
request
.
identity
,
""
,
strlen
(
""
));
HAL_GetProduct_Type
(
request
.
product_key
);
HAL_GetProduct_Code
(
request
.
device_name
);
memcpy
(
request
.
productType
,
gw_node
->
productType
,
strlen
(
gw_node
->
productType
));
memcpy
(
request
.
productCode
,
gw_node
->
productCode
,
strlen
(
gw_node
->
productCode
));
memcpy
(
request
.
deviceCode
,
gw_node
->
deviceCode
,
strlen
(
gw_node
->
deviceCode
));
/* Get Params And Method */
res
=
dm_msg_combine_login
(
node
->
product
_key
,
node
->
device_name
,
node
->
device_secret
,
&
request
);
res
=
dm_msg_combine_login
(
node
->
product
Type
,
node
->
productCode
,
node
->
deviceCode
,
&
request
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
...
...
@@ -902,6 +953,7 @@ int dm_mgr_upstream_combine_logout(_IN_ int devid)
{
int
res
=
0
;
dm_mgr_dev_node_t
*
node
=
NULL
;
dm_mgr_dev_node_t
*
gw_node
=
NULL
;
dm_msg_request_t
request
;
if
(
devid
<
0
)
{
...
...
@@ -912,15 +964,22 @@ int dm_mgr_upstream_combine_logout(_IN_ int devid)
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
res
=
dm_mgr_get_device_by_mac
(
node
->
fatherMac
,
&
gw_node
);
if
(
res
!=
SUCCESS_RETURN
)
{
ERROR_PRINT
(
"ERROR [%s][%d] res:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
res
);
return
FAIL_RETURN
;
}
memset
(
&
request
,
0
,
sizeof
(
dm_msg_request_t
));
request
.
msgtype
=
MSG_LOGOUT
;
memcpy
(
request
.
identity
,
""
,
strlen
(
""
));
HAL_GetProduct_Type
(
request
.
product_key
);
HAL_GetProduct_Code
(
request
.
device_name
);
memcpy
(
request
.
productType
,
gw_node
->
productType
,
strlen
(
gw_node
->
productType
));
memcpy
(
request
.
productCode
,
gw_node
->
productCode
,
strlen
(
gw_node
->
productCode
));
memcpy
(
request
.
deviceCode
,
gw_node
->
deviceCode
,
strlen
(
gw_node
->
deviceCode
));
/* Get Params And Method */
res
=
dm_msg_combine_logout
(
node
->
product
_key
,
node
->
device_nam
e
,
&
request
);
res
=
dm_msg_combine_logout
(
node
->
product
Type
,
node
->
deviceCod
e
,
&
request
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
...
...
@@ -965,8 +1024,9 @@ int dm_mgr_ota_report_version(_IN_ int devid, char *version)
memset
(
&
request
,
0
,
sizeof
(
dm_msg_request_t
));
request
.
msgtype
=
MSG_OTA_INFORM
;
memcpy
(
request
.
identity
,
""
,
strlen
(
""
));
memcpy
(
request
.
product_key
,
node
->
product_key
,
PRODUCT_KEY_MAXLEN
);
memcpy
(
request
.
device_name
,
node
->
device_name
,
DEVICE_NAME_MAXLEN
);
memcpy
(
request
.
productType
,
node
->
productType
,
PRODUCT_TYPE_MAXLEN
);
memcpy
(
request
.
productCode
,
node
->
productCode
,
PRODUCT_CODE_MAXLEN
);
memcpy
(
request
.
deviceCode
,
node
->
deviceCode
,
DEVICE_CODE_MAXLEN
);
/* Get Params And Method */
res
=
dm_msg_ota_report_version
(
version
,
&
request
);
...
...
@@ -998,11 +1058,11 @@ int dm_mgr_ota_report_version(_IN_ int devid, char *version)
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
],
_IN_
char
device_m
ac
[
DEVICE_MAC_MAXLEN
],
_OU_
int
*
devid
){
int
dm_mgr_subdev_create
(
_IN_
char
product
Type
[
PRODUCT_TYPE
_MAXLEN
],
_IN_
char
productCode
[
PRODUCT_CODE_MAXLEN
],
_IN_
char
deviceCode
[
DEVICE_CODE_MAXLEN
],
_IN_
char
fatherM
ac
[
DEVICE_MAC_MAXLEN
],
_OU_
int
*
devid
){
int
res
=
0
;
res
=
dm_mgr_device_create
(
KK_DM_DEVICE_SUBDEV
,
product
_key
,
device_name
,
device_secret
,
device_m
ac
,
devid
);
res
=
dm_mgr_device_create
(
KK_DM_DEVICE_SUBDEV
,
product
Type
,
productCode
,
deviceCode
,
fatherM
ac
,
devid
);
if
(
TSL_ALREADY_EXIST
==
res
)
{
ERROR_PRINT
(
"SUBDEV ALREADY EXIST!!!
\n
"
);
...
...
midware/midware/dm/kk_dm_mng.h
View file @
c02ee8a2
...
...
@@ -6,20 +6,24 @@
#include "iotx_dm.h"
#define KK_DM_DEVICE_
SINGLE
(0x01)
#define KK_DM_DEVICE_
CCU
(0x01)
#define KK_DM_DEVICE_SUBDEV (0x02)
#define KK_DM_DEVICE_GATEWAY (0x04)
#define KK_MID_SYNC_DEFAULT_TIMEOUT_MS (200)
#define IDENTIFY_MAXLEN (64 + 1)
#define KK_DM_CCU_DEVICE_PRODUCT_TYPE "ccu"
#define KK_DM_CCU_DEVICE_PRODUCT_CODE "15"
#define KK_DM_GW_DEVICE_PRODUCT_TYPE "gw"
#define KK_DM_GW_DEVICE_PRODUCT_CODE "2"
typedef
struct
{
int
devid
;
int
dev_type
;
kk_tsl_t
*
dev_shadow
;
char
product
_key
[
PRODUCT_KEY
_MAXLEN
];
char
device_name
[
DEVICE_NAM
E_MAXLEN
];
char
device
_secret
[
DEVICE_SECRET
_MAXLEN
];
char
device_m
ac
[
DEVICE_MAC_MAXLEN
];
char
product
Type
[
PRODUCT_TYPE
_MAXLEN
];
char
productCode
[
PRODUCT_COD
E_MAXLEN
];
char
device
Code
[
DEVICE_CODE
_MAXLEN
];
char
fatherM
ac
[
DEVICE_MAC_MAXLEN
];
struct
list_head
linked_list
;
}
dm_mgr_dev_node_t
;
...
...
@@ -36,8 +40,9 @@ typedef struct {
//const char *service_name;
kk_msg_type_t
msgtype
;
char
identity
[
IDENTIFY_MAXLEN
];
char
product_key
[
PRODUCT_KEY_MAXLEN
];
char
device_name
[
DEVICE_NAME_MAXLEN
];
char
productType
[
PRODUCT_TYPE_MAXLEN
];
char
productCode
[
PRODUCT_CODE_MAXLEN
];
char
deviceCode
[
DEVICE_CODE_MAXLEN
];
char
*
params
;
int
params_len
;
char
*
method
;
...
...
@@ -46,8 +51,10 @@ typedef struct {
typedef
struct
{
kk_msg_type_t
msgtype
;
char
identity
[
IDENTIFY_MAXLEN
];
char
product_key
[
PRODUCT_KEY_MAXLEN
];
char
device_name
[
DEVICE_NAME_MAXLEN
];
char
productType
[
PRODUCT_TYPE_MAXLEN
];
char
productCode
[
PRODUCT_CODE_MAXLEN
];
char
deviceCode
[
DEVICE_CODE_MAXLEN
];
iotx_dm_error_code_t
code
;
}
kk_msg_response_t
;
...
...
midware/midware/dm/kk_dm_msg.c
View file @
c02ee8a2
...
...
@@ -9,7 +9,7 @@
const
char
DM_MSG_REQUEST
[]
DM_READ_ONLY
=
"{
\"
msgId
\"
:
\"
%d
\"
,
\"
version
\"
:
\"
%s
\"
,
\"
params
\"
:%.*s,
\"
method
\"
:
\"
%s
\"
}"
;
const
char
DM_MSG_INFO
[]
DM_READ_ONLY
=
"{
\"
msgtype
\"
:
\"
%d
\"
,
\"
product
_type
\"
:
\"
%s
\"
,
\"
device_nam
e
\"
:
\"
%s
\"
,
\"
identifier
\"
:
\"
%s
\"
}"
;
const
char
DM_MSG_INFO
[]
DM_READ_ONLY
=
"{
\"
msgtype
\"
:
\"
%d
\"
,
\"
product
Type
\"
:
\"
%s
\"
,
\"
productCode
\"
:
\"
%s
\"
,
\"
deviceCod
e
\"
:
\"
%s
\"
,
\"
identifier
\"
:
\"
%s
\"
}"
;
void
kk_sendData2app
(
void
*
info
,
void
*
payload
){
cJSON
*
root
=
cJSON_CreateObject
();
...
...
@@ -23,31 +23,31 @@ void kk_sendData2app(void *info, void *payload){
}
const
char
DM_MSG_THING_SUB_REGISTER_METHOD
[]
=
"thing.sub.register"
;
const
char
DM_MSG_THING_SUB_REGISTER_PARAMS
[]
=
"[{
\"
product
Key
\"
:
\"
%s
\"
,
\"
deviceNam
e
\"
:
\"
%s
\"
}]"
;
const
char
DM_MSG_THING_SUB_REGISTER_PARAMS
[]
=
"[{
\"
product
Type
\"
:
\"
%s
\"
,
\"
productCode
\"
:
\"
%s
\"
,
\"
deviceCod
e
\"
:
\"
%s
\"
}]"
;
int
dm_msg_thing_sub_register
(
_IN_
char
product
_key
[
PRODUCT_KEY
_MAXLEN
],
_IN_
char
device_name
[
DEVICE_NAM
E_MAXLEN
],
int
dm_msg_thing_sub_register
(
_IN_
char
product
Type
[
PRODUCT_TYPE
_MAXLEN
],
_IN_
char
productCode
[
DEVICE_CODE_MAXLEN
],
_IN_
char
deviceCode
[
DEVICE_COD
E_MAXLEN
],
_OU_
dm_msg_request_t
*
request
)
{
int
params_len
=
0
;
char
*
params
=
NULL
;
if
(
request
==
NULL
||
product
_key
==
NULL
||
device_nam
e
==
NULL
||
(
strlen
(
product
_key
)
>=
PRODUCT_KEY
_MAXLEN
)
||
(
strlen
(
device
_name
)
>=
DEVICE_NAM
E_MAXLEN
)
||
(
strlen
(
request
->
product
_key
)
>=
PRODUCT_KEY
_MAXLEN
)
||
(
strlen
(
request
->
device
_name
)
>=
DEVICE_NAM
E_MAXLEN
))
{
if
(
request
==
NULL
||
product
Type
==
NULL
||
deviceCod
e
==
NULL
||
(
strlen
(
product
Type
)
>=
PRODUCT_TYPE
_MAXLEN
)
||
(
strlen
(
device
Code
)
>=
DEVICE_COD
E_MAXLEN
)
||
(
strlen
(
request
->
product
Type
)
>=
PRODUCT_TYPE
_MAXLEN
)
||
(
strlen
(
request
->
device
Code
)
>=
DEVICE_COD
E_MAXLEN
))
{
return
INVALID_PARAMETER
;
}
params_len
=
strlen
(
DM_MSG_THING_SUB_REGISTER_PARAMS
)
+
strlen
(
product
_key
)
+
strlen
(
device_nam
e
)
+
1
;
params_len
=
strlen
(
DM_MSG_THING_SUB_REGISTER_PARAMS
)
+
strlen
(
product
Type
)
+
strlen
(
productCode
)
+
strlen
(
deviceCod
e
)
+
1
;
params
=
malloc
(
params_len
);
if
(
params
==
NULL
)
{
return
MEMORY_NOT_ENOUGH
;
}
memset
(
params
,
0
,
params_len
);
snprintf
(
params
,
params_len
,
DM_MSG_THING_SUB_REGISTER_PARAMS
,
product
_key
,
device_nam
e
);
snprintf
(
params
,
params_len
,
DM_MSG_THING_SUB_REGISTER_PARAMS
,
product
Type
,
productCode
,
deviceCod
e
);
/* Get Params */
request
->
params
=
params
;
...
...
@@ -61,28 +61,28 @@ int dm_msg_thing_sub_register(_IN_ char product_key[PRODUCT_KEY_MAXLEN],
const
char
DM_MSG_THING_SUB_UNREGISTER_METHOD
[]
DM_READ_ONLY
=
"thing.sub.unregister"
;
const
char
DM_MSG_THING_SUB_UNREGISTER_PARAMS
[]
DM_READ_ONLY
=
"[{
\"
productKey
\"
:
\"
%s
\"
,
\"
deviceName
\"
:
\"
%s
\"
}]"
;
int
dm_msg_thing_sub_unregister
(
_IN_
char
product
_key
[
PRODUCT_KEY
_MAXLEN
],
_IN_
char
device
_name
[
DEVICE_NAM
E_MAXLEN
],
int
dm_msg_thing_sub_unregister
(
_IN_
char
product
Type
[
PRODUCT_TYPE
_MAXLEN
],
_IN_
char
device
Code
[
DEVICE_COD
E_MAXLEN
],
_OU_
dm_msg_request_t
*
request
)
{
int
params_len
=
0
;
char
*
params
=
NULL
;
if
(
request
==
NULL
||
product
_key
==
NULL
||
device_nam
e
==
NULL
||
(
strlen
(
product
_key
)
>=
PRODUCT_KEY
_MAXLEN
)
||
(
strlen
(
device
_name
)
>=
DEVICE_NAM
E_MAXLEN
)
||
(
strlen
(
request
->
product
_key
)
>=
PRODUCT_KEY
_MAXLEN
)
||
(
strlen
(
request
->
device
_name
)
>=
DEVICE_NAM
E_MAXLEN
))
{
if
(
request
==
NULL
||
product
Type
==
NULL
||
deviceCod
e
==
NULL
||
(
strlen
(
product
Type
)
>=
PRODUCT_TYPE
_MAXLEN
)
||
(
strlen
(
device
Code
)
>=
DEVICE_COD
E_MAXLEN
)
||
(
strlen
(
request
->
product
Type
)
>=
PRODUCT_TYPE
_MAXLEN
)
||
(
strlen
(
request
->
device
Code
)
>=
DEVICE_COD
E_MAXLEN
))
{
return
INVALID_PARAMETER
;
}
params_len
=
strlen
(
DM_MSG_THING_SUB_UNREGISTER_PARAMS
)
+
strlen
(
product
_key
)
+
strlen
(
device_nam
e
)
+
1
;
params_len
=
strlen
(
DM_MSG_THING_SUB_UNREGISTER_PARAMS
)
+
strlen
(
product
Type
)
+
strlen
(
deviceCod
e
)
+
1
;
params
=
malloc
(
params_len
);
if
(
params
==
NULL
)
{
return
MEMORY_NOT_ENOUGH
;
}
memset
(
params
,
0
,
params_len
);
snprintf
(
params
,
params_len
,
DM_MSG_THING_SUB_UNREGISTER_PARAMS
,
product
_key
,
device_nam
e
);
snprintf
(
params
,
params_len
,
DM_MSG_THING_SUB_UNREGISTER_PARAMS
,
product
Type
,
deviceCod
e
);
/* Get Params */
request
->
params
=
params
;
...
...
@@ -98,27 +98,27 @@ const char DM_MSG_THING_TOPO_ADD_SIGN_SOURCE[] DM_READ_ONLY = "clientId%sdeviceN
const
char
DM_MSG_THING_TOPO_ADD_METHOD
[]
DM_READ_ONLY
=
"thing.topo.add"
;
const
char
DM_MSG_THING_TOPO_ADD_PARAMS
[]
DM_READ_ONLY
=
"[{
\"
productKey
\"
:
\"
%s
\"
,
\"
deviceName
\"
:
\"
%s
\"
,
\"
signmethod
\"
:
\"
%s
\"
,
\"
sign
\"
:
\"
%s
\"
,
\"
timestamp
\"
:
\"
%s
\"
,
\"
clientId
\"
:
\"
%s
\"
}]"
;
int
dm_msg_thing_topo_add
(
_IN_
char
product
_key
[
PRODUCT_KEY
_MAXLEN
],
_IN_
char
device_name
[
DEVICE_NAM
E_MAXLEN
],
_IN_
char
device
_secret
[
DEVICE_SECRET
_MAXLEN
],
_OU_
dm_msg_request_t
*
request
)
int
dm_msg_thing_topo_add
(
_IN_
char
product
Type
[
PRODUCT_TYPE
_MAXLEN
],
_IN_
char
productCode
[
PRODUCT_COD
E_MAXLEN
],
_IN_
char
device
Code
[
DEVICE_CODE
_MAXLEN
],
_OU_
dm_msg_request_t
*
request
)
{
char
*
params
=
NULL
;
int
params_len
=
0
;
char
timestamp
[
DM_UTILS_UINT64_STRLEN
]
=
{
0
};
char
client_id
[
PRODUCT_
KEY_MAXLEN
+
DEVICE_NAM
E_MAXLEN
+
1
]
=
{
0
};
char
client_id
[
PRODUCT_
TYPE_MAXLEN
+
DEVICE_COD
E_MAXLEN
+
1
]
=
{
0
};
char
*
sign_source
=
NULL
;
int
sign_source_len
=
0
;
char
*
sign_method
=
DM_MSG_SIGN_METHOD_HMACSHA1
;
char
sign
[
65
]
=
{
0
};
if
(
request
==
NULL
||
product
_key
==
NULL
||
device_name
==
NULL
||
device_secret
==
NULL
||
(
strlen
(
product
_key
)
>=
PRODUCT_KEY
_MAXLEN
)
||
(
strlen
(
device_name
)
>=
DEVICE_NAM
E_MAXLEN
)
||
(
strlen
(
device
_secret
)
>=
DEVICE_SECRET
_MAXLEN
)
||
(
strlen
(
request
->
product
_key
)
>=
PRODUCT_KEY
_MAXLEN
)
||
(
strlen
(
request
->
device
_name
)
>=
DEVICE_NAM
E_MAXLEN
))
{
if
(
request
==
NULL
||
product
Type
==
NULL
||
productCode
==
NULL
||
deviceCode
==
NULL
||
(
strlen
(
product
Type
)
>=
PRODUCT_TYPE
_MAXLEN
)
||
(
strlen
(
productCode
)
>=
PRODUCT_COD
E_MAXLEN
)
||
(
strlen
(
device
Code
)
>=
DEVICE_CODE
_MAXLEN
)
||
(
strlen
(
request
->
product
Type
)
>=
PRODUCT_TYPE
_MAXLEN
)
||
(
strlen
(
request
->
device
Code
)
>=
DEVICE_COD
E_MAXLEN
))
{
return
INVALID_PARAMETER
;
}
...
...
@@ -127,18 +127,18 @@ int dm_msg_thing_topo_add(_IN_ char product_key[PRODUCT_KEY_MAXLEN],
/* dm_log_debug("Time Stamp: %s", timestamp); */
/* Client ID */
HAL_Snprintf
(
client_id
,
PRODUCT_
KEY_MAXLEN
+
DEVICE_NAME_MAXLEN
+
1
,
"%s.%s"
,
product_key
,
device_nam
e
);
HAL_Snprintf
(
client_id
,
PRODUCT_
TYPE_MAXLEN
+
DEVICE_CODE_MAXLEN
+
1
,
"%s.%s"
,
productType
,
deviceCod
e
);
/* Sign */
sign_source_len
=
strlen
(
DM_MSG_THING_TOPO_ADD_SIGN_SOURCE
)
+
strlen
(
client_id
)
+
strlen
(
device
_name
)
+
strlen
(
product_key
)
+
strlen
(
timestamp
)
+
1
;
strlen
(
device
Code
)
+
strlen
(
productType
)
+
strlen
(
timestamp
)
+
1
;
sign_source
=
malloc
(
sign_source_len
);
if
(
sign_source
==
NULL
)
{
return
MEMORY_NOT_ENOUGH
;
}
memset
(
sign_source
,
0
,
sign_source_len
);
HAL_Snprintf
(
sign_source
,
sign_source_len
,
DM_MSG_THING_TOPO_ADD_SIGN_SOURCE
,
client_id
,
device
_name
,
product_key
,
timestamp
);
device
Code
,
productType
,
timestamp
);
/* dm_log_debug("Sign Srouce: %s", sign_source); */
#if 0
...
...
@@ -160,7 +160,7 @@ int dm_msg_thing_topo_add(_IN_ char product_key[PRODUCT_KEY_MAXLEN],
/* Params */
request
->
method
=
(
char
*
)
DM_MSG_THING_TOPO_ADD_METHOD
;
params_len
=
strlen
(
DM_MSG_THING_TOPO_ADD_PARAMS
)
+
strlen
(
product
_key
)
+
strlen
(
device_nam
e
)
+
params_len
=
strlen
(
DM_MSG_THING_TOPO_ADD_PARAMS
)
+
strlen
(
product
Type
)
+
strlen
(
deviceCod
e
)
+
strlen
(
sign_method
)
+
strlen
(
sign
)
+
strlen
(
timestamp
)
+
strlen
(
client_id
)
+
1
;
params
=
malloc
(
params_len
);
...
...
@@ -168,7 +168,7 @@ int dm_msg_thing_topo_add(_IN_ char product_key[PRODUCT_KEY_MAXLEN],
return
MEMORY_NOT_ENOUGH
;
}
memset
(
params
,
0
,
params_len
);
HAL_Snprintf
(
params
,
params_len
,
DM_MSG_THING_TOPO_ADD_PARAMS
,
product
_key
,
device_nam
e
,
HAL_Snprintf
(
params
,
params_len
,
DM_MSG_THING_TOPO_ADD_PARAMS
,
product
Type
,
deviceCod
e
,
sign_method
,
sign
,
timestamp
,
client_id
);
request
->
params
=
params
;
...
...
@@ -179,31 +179,31 @@ int dm_msg_thing_topo_add(_IN_ char product_key[PRODUCT_KEY_MAXLEN],
const
char
DM_MSG_THING_TOPO_DELETE_METHOD
[]
DM_READ_ONLY
=
"thing.topo.delete"
;
const
char
DM_MSG_THING_TOPO_DELETE_PARAMS
[]
DM_READ_ONLY
=
"[{
\"
productKey
\"
:
\"
%s
\"
,
\"
deviceName
\"
:
\"
%s
\"
}]"
;
int
dm_msg_thing_topo_delete
(
_IN_
char
product
_key
[
PRODUCT_KEY
_MAXLEN
],
_IN_
char
device
_name
[
DEVICE_NAM
E_MAXLEN
],
int
dm_msg_thing_topo_delete
(
_IN_
char
product
Type
[
PRODUCT_CODE
_MAXLEN
],
_IN_
char
device
Code
[
DEVICE_COD
E_MAXLEN
],
_OU_
dm_msg_request_t
*
request
)
{
char
*
params
=
NULL
;
int
params_len
=
0
;
if
(
request
==
NULL
||
product
_key
==
NULL
||
device
_nam
e
==
NULL
||
(
strlen
(
product
_key
)
>=
PRODUCT_KEY
_MAXLEN
)
||
(
strlen
(
device
_name
)
>=
DEVICE_NAM
E_MAXLEN
)
||
(
strlen
(
request
->
product
_key
)
>=
PRODUCT_KEY
_MAXLEN
)
||
(
strlen
(
request
->
device
_name
)
>=
DEVICE_NAM
E_MAXLEN
))
{
if
(
request
==
NULL
||
product
Type
==
NULL
||
device
Cod
e
==
NULL
||
(
strlen
(
product
Type
)
>=
PRODUCT_CODE
_MAXLEN
)
||
(
strlen
(
device
Code
)
>=
DEVICE_COD
E_MAXLEN
)
||
(
strlen
(
request
->
product
Type
)
>=
PRODUCT_CODE
_MAXLEN
)
||
(
strlen
(
request
->
device
Code
)
>=
DEVICE_COD
E_MAXLEN
))
{
return
INVALID_PARAMETER
;
}
/* Params */
request
->
method
=
(
char
*
)
DM_MSG_THING_TOPO_DELETE_METHOD
;
params_len
=
strlen
(
DM_MSG_THING_TOPO_DELETE_PARAMS
)
+
strlen
(
product
_key
)
+
strlen
(
device_nam
e
)
+
1
;
params_len
=
strlen
(
DM_MSG_THING_TOPO_DELETE_PARAMS
)
+
strlen
(
product
Type
)
+
strlen
(
deviceCod
e
)
+
1
;
params
=
malloc
(
params_len
);
if
(
params
==
NULL
)
{
return
MEMORY_NOT_ENOUGH
;
}
memset
(
params
,
0
,
params_len
);
HAL_Snprintf
(
params
,
params_len
,
DM_MSG_THING_TOPO_DELETE_PARAMS
,
product_key
,
device_nam
e
);
HAL_Snprintf
(
params
,
params_len
,
DM_MSG_THING_TOPO_DELETE_PARAMS
,
deviceCode
,
deviceCod
e
);
request
->
params
=
params
;
request
->
params_len
=
strlen
(
request
->
params
);
...
...
@@ -236,29 +236,29 @@ int dm_msg_thing_topo_delete(_IN_ char product_key[PRODUCT_KEY_MAXLEN],
const
char
DM_MSG_THING_LIST_FOUND_METHOD
[]
DM_READ_ONLY
=
"thing.list.found"
;
const
char
DM_MSG_THING_LIST_FOUND_PARAMS
[]
DM_READ_ONLY
=
"[{
\"
productKey
\"
:
\"
%s
\"
,
\"
deviceName
\"
:
\"
%s
\"
}]"
;
int
dm_msg_thing_list_found
(
_IN_
char
product
_key
[
PRODUCT_KEY
_MAXLEN
],
_IN_
char
device
_name
[
DEVICE_NAM
E_MAXLEN
],
int
dm_msg_thing_list_found
(
_IN_
char
product
Type
[
PRODUCT_TYPE
_MAXLEN
],
_IN_
char
device
Code
[
DEVICE_COD
E_MAXLEN
],
_OU_
dm_msg_request_t
*
request
)
{
char
*
params
=
NULL
;
int
params_len
=
0
;
if
(
product
_key
==
NULL
||
device_nam
e
==
NULL
||
(
strlen
(
product
_key
)
>=
PRODUCT_KEY
_MAXLEN
)
||
(
strlen
(
device
_name
)
>=
DEVICE_NAM
E_MAXLEN
)
||
if
(
product
Type
==
NULL
||
deviceCod
e
==
NULL
||
(
strlen
(
product
Type
)
>=
PRODUCT_TYPE
_MAXLEN
)
||
(
strlen
(
device
Code
)
>=
DEVICE_COD
E_MAXLEN
)
||
request
==
NULL
)
{
return
INVALID_PARAMETER
;
}
/* Params */
request
->
method
=
(
char
*
)
DM_MSG_THING_LIST_FOUND_METHOD
;
params_len
=
strlen
(
DM_MSG_THING_LIST_FOUND_PARAMS
)
+
strlen
(
product
_key
)
+
strlen
(
device_nam
e
)
+
1
;
params_len
=
strlen
(
DM_MSG_THING_LIST_FOUND_PARAMS
)
+
strlen
(
product
Type
)
+
strlen
(
deviceCod
e
)
+
1
;
params
=
malloc
(
params_len
);
if
(
params
==
NULL
)
{
return
MEMORY_NOT_ENOUGH
;
}
memset
(
params
,
0
,
params_len
);
HAL_Snprintf
(
params
,
params_len
,
DM_MSG_THING_LIST_FOUND_PARAMS
,
product
_key
,
device_nam
e
);
HAL_Snprintf
(
params
,
params_len
,
DM_MSG_THING_LIST_FOUND_PARAMS
,
product
Type
,
deviceCod
e
);
request
->
params
=
params
;
request
->
params_len
=
strlen
(
request
->
params
);
...
...
@@ -271,27 +271,27 @@ const char DM_MSG_COMBINE_LOGIN_SIGN_SOURCE[] DM_READ_ONLY = "clientId%sdeviceNa
const
char
DM_MSG_COMBINE_LOGIN_METHOD
[]
DM_READ_ONLY
=
"combine.login"
;
const
char
DM_MSG_COMBINE_LOGIN_PARAMS
[]
DM_READ_ONLY
=
"{
\"
productKey
\"
:
\"
%s
\"
,
\"
deviceName
\"
:
\"
%s
\"
,
\"
clientId
\"
:
\"
%s
\"
,
\"
timestamp
\"
:
\"
%s
\"
,
\"
signMethod
\"
:
\"
%s
\"
,
\"
sign
\"
:
\"
%s
\"
,
\"
cleanSession
\"
:
\"
%s
\"
}"
;
int
dm_msg_combine_login
(
_IN_
char
product
_key
[
PRODUCT_KEY
_MAXLEN
],
_IN_
char
device_name
[
DEVICE_NAM
E_MAXLEN
],
_IN_
char
device
_secret
[
DEVICE_SECRET
_MAXLEN
],
_OU_
dm_msg_request_t
*
request
)
int
dm_msg_combine_login
(
_IN_
char
product
Type
[
PRODUCT_TYPE
_MAXLEN
],
_IN_
char
productCode
[
PRODUCT_COD
E_MAXLEN
],
_IN_
char
device
Code
[
DEVICE_CODE
_MAXLEN
],
_OU_
dm_msg_request_t
*
request
)
{
char
*
params
=
NULL
;
int
params_len
=
0
;
char
timestamp
[
DM_UTILS_UINT64_STRLEN
]
=
{
0
};
char
client_id
[
PRODUCT_
KEY_MAXLEN
+
DEVICE_NAM
E_MAXLEN
+
20
]
=
{
0
};
char
client_id
[
PRODUCT_
TYPE_MAXLEN
+
DEVICE_COD
E_MAXLEN
+
20
]
=
{
0
};
char
*
sign_source
=
NULL
;
int
sign_source_len
=
0
;
char
*
sign_method
=
DM_MSG_SIGN_METHOD_HMACSHA1
;
char
sign
[
64
]
=
{
0
};
if
(
request
==
NULL
||
product
_key
==
NULL
||
device
_name
==
NULL
||
device_secret
==
NULL
||
(
strlen
(
product
_key
)
>=
PRODUCT_KEY
_MAXLEN
)
||
(
strlen
(
device
_name
)
>=
DEVICE_NAM
E_MAXLEN
)
||
(
strlen
(
device_secret
)
>=
DEVICE_SECRET
_MAXLEN
)
||
(
strlen
(
request
->
product
_key
)
>=
PRODUCT_KEY
_MAXLEN
)
||
(
strlen
(
request
->
device
_name
)
>=
DEVICE_NAM
E_MAXLEN
))
{
if
(
request
==
NULL
||
product
Type
==
NULL
||
device
Code
==
NULL
||
productCode
==
NULL
||
(
strlen
(
product
Type
)
>=
PRODUCT_TYPE
_MAXLEN
)
||
(
strlen
(
device
Code
)
>=
DEVICE_COD
E_MAXLEN
)
||
(
strlen
(
productCode
)
>=
PRODUCT_CODE
_MAXLEN
)
||
(
strlen
(
request
->
product
Type
)
>=
PRODUCT_TYPE
_MAXLEN
)
||
(
strlen
(
request
->
device
Code
)
>=
DEVICE_COD
E_MAXLEN
))
{
return
INVALID_PARAMETER
;
}
...
...
@@ -300,18 +300,18 @@ int dm_msg_combine_login(_IN_ char product_key[PRODUCT_KEY_MAXLEN],
/* dm_log_debug("Time Stamp: %s", timestamp); */
/* Client ID */
HAL_Snprintf
(
client_id
,
PRODUCT_
KEY_MAXLEN
+
DEVICE_NAME_MAXLEN
+
20
,
"%s.%s|_v=sdk-c-3.0.1|"
,
product_key
,
device_nam
e
);
HAL_Snprintf
(
client_id
,
PRODUCT_
TYPE_MAXLEN
+
DEVICE_CODE_MAXLEN
+
20
,
"%s.%s|_v=sdk-c-3.0.1|"
,
productType
,
deviceCod
e
);
/* Sign */
sign_source_len
=
strlen
(
DM_MSG_COMBINE_LOGIN_SIGN_SOURCE
)
+
strlen
(
client_id
)
+
strlen
(
device
_name
)
+
strlen
(
product_key
)
+
strlen
(
timestamp
)
+
1
;
strlen
(
device
Code
)
+
strlen
(
productType
)
+
strlen
(
timestamp
)
+
1
;
sign_source
=
malloc
(
sign_source_len
);
if
(
sign_source
==
NULL
)
{
return
DM_MEMORY_NOT_ENOUGH
;
}
memset
(
sign_source
,
0
,
sign_source_len
);
HAL_Snprintf
(
sign_source
,
sign_source_len
,
DM_MSG_COMBINE_LOGIN_SIGN_SOURCE
,
client_id
,
device
_name
,
product_key
,
timestamp
);
device
Code
,
productType
,
timestamp
);
/* dm_log_debug("Sign Srouce: %s", sign_source); */
#if 0
...
...
@@ -333,7 +333,7 @@ int dm_msg_combine_login(_IN_ char product_key[PRODUCT_KEY_MAXLEN],
/* Params */
request
->
method
=
(
char
*
)
DM_MSG_COMBINE_LOGIN_METHOD
;
params_len
=
strlen
(
DM_MSG_COMBINE_LOGIN_PARAMS
)
+
strlen
(
product
_key
)
+
strlen
(
device_nam
e
)
+
params_len
=
strlen
(
DM_MSG_COMBINE_LOGIN_PARAMS
)
+
strlen
(
product
Type
)
+
strlen
(
deviceCod
e
)
+
strlen
(
sign_method
)
+
strlen
(
sign
)
+
strlen
(
timestamp
)
+
strlen
(
client_id
)
+
1
;
params
=
malloc
(
params_len
);
...
...
@@ -341,7 +341,7 @@ int dm_msg_combine_login(_IN_ char product_key[PRODUCT_KEY_MAXLEN],
return
DM_MEMORY_NOT_ENOUGH
;
}
memset
(
params
,
0
,
params_len
);
HAL_Snprintf
(
params
,
params_len
,
DM_MSG_COMBINE_LOGIN_PARAMS
,
product
_key
,
device_nam
e
,
HAL_Snprintf
(
params
,
params_len
,
DM_MSG_COMBINE_LOGIN_PARAMS
,
product
Type
,
deviceCod
e
,
client_id
,
timestamp
,
sign_method
,
sign
,
"true"
);
request
->
params
=
params
;
...
...
@@ -353,31 +353,31 @@ int dm_msg_combine_login(_IN_ char product_key[PRODUCT_KEY_MAXLEN],
const
char
DM_MSG_COMBINE_LOGOUT_METHOD
[]
DM_READ_ONLY
=
"combine.logout"
;
const
char
DM_MSG_COMBINE_LOGOUT_PARAMS
[]
DM_READ_ONLY
=
"{
\"
productKey
\"
:
\"
%s
\"
,
\"
deviceName
\"
:
\"
%s
\"
}"
;
int
dm_msg_combine_logout
(
_IN_
char
product
_key
[
PRODUCT_KEY
_MAXLEN
],
_IN_
char
device
_name
[
DEVICE_NAM
E_MAXLEN
],
int
dm_msg_combine_logout
(
_IN_
char
product
Type
[
PRODUCT_TYPE
_MAXLEN
],
_IN_
char
device
Code
[
DEVICE_COD
E_MAXLEN
],
_OU_
dm_msg_request_t
*
request
)
{
char
*
params
=
NULL
;
int
params_len
=
0
;
if
(
product
_key
==
NULL
||
device_nam
e
==
NULL
||
(
strlen
(
product
_key
)
>=
PRODUCT_KEY
_MAXLEN
||
(
strlen
(
device
_name
)
>=
DEVICE_NAM
E_MAXLEN
)
||
if
(
product
Type
==
NULL
||
deviceCod
e
==
NULL
||
(
strlen
(
product
Type
)
>=
PRODUCT_TYPE
_MAXLEN
||
(
strlen
(
device
Code
)
>=
DEVICE_COD
E_MAXLEN
)
||
request
==
NULL
)
){
return
INVALID_PARAMETER
;
}
/* Params */
request
->
method
=
(
char
*
)
DM_MSG_COMBINE_LOGOUT_METHOD
;
params_len
=
strlen
(
DM_MSG_COMBINE_LOGOUT_PARAMS
)
+
strlen
(
product
_key
)
+
strlen
(
device_nam
e
)
+
1
;
params_len
=
strlen
(
DM_MSG_COMBINE_LOGOUT_PARAMS
)
+
strlen
(
product
Type
)
+
strlen
(
deviceCod
e
)
+
1
;
params
=
malloc
(
params_len
);
if
(
params
==
NULL
)
{
return
MEMORY_NOT_ENOUGH
;
}
memset
(
params
,
0
,
params_len
);
HAL_Snprintf
(
params
,
params_len
,
DM_MSG_COMBINE_LOGOUT_PARAMS
,
product
_key
,
device_nam
e
);
HAL_Snprintf
(
params
,
params_len
,
DM_MSG_COMBINE_LOGOUT_PARAMS
,
product
Type
,
deviceCod
e
);
request
->
params
=
params
;
request
->
params_len
=
strlen
(
request
->
params
);
...
...
@@ -438,7 +438,7 @@ int dm_msg_request (_IN_ dm_msg_request_t *request)
snprintf
(
payload
,
payload_len
,
DM_MSG_REQUEST
,
request
->
msgid
,
DM_MSG_VERSION
,
request
->
params_len
,
request
->
params
,
request
->
method
);
req_info_len
=
strlen
(
DM_MSG_INFO
)
+
10
+
strlen
(
request
->
product
_key
)
+
strlen
(
request
->
device_nam
e
)
+
strlen
(
request
->
identity
)
+
1
;
req_info_len
=
strlen
(
DM_MSG_INFO
)
+
10
+
strlen
(
request
->
product
Type
)
+
strlen
(
request
->
productCode
)
+
strlen
(
request
->
deviceCod
e
)
+
strlen
(
request
->
identity
)
+
1
;
req_info
=
malloc
(
req_info_len
);
if
(
req_info
==
NULL
)
{
free
(
payload
);
...
...
@@ -446,7 +446,7 @@ int dm_msg_request (_IN_ dm_msg_request_t *request)
}
memset
(
req_info
,
0
,
req_info_len
);
snprintf
(
req_info
,
req_info_len
,
DM_MSG_INFO
,
request
->
msgtype
,
request
->
product
_key
,
request
->
device_nam
e
,
request
->
identity
);
request
->
product
Type
,
request
->
productCode
,
request
->
deviceCod
e
,
request
->
identity
);
memset
(
&
lite
,
0
,
sizeof
(
lite_cjson_t
));
res
=
lite_cjson_parse
(
payload
,
payload_len
,
&
lite
);
...
...
@@ -500,7 +500,7 @@ int dm_msg_response(_IN_ kk_msg_request_payload_t *request, _IN_ kk_msg_response
snprintf
(
payload
,
payload_len
,
DM_MSG_RESPONSE_WITH_DATA
,
request
->
id
.
value_length
,
request
->
id
.
value
,
response
->
code
,
data_len
,
data
);
res_info_len
=
strlen
(
DM_MSG_INFO
)
+
10
+
strlen
(
response
->
product
_key
)
+
strlen
(
response
->
device_nam
e
)
+
strlen
(
response
->
identity
)
+
1
;
res_info_len
=
strlen
(
DM_MSG_INFO
)
+
10
+
strlen
(
response
->
product
Type
)
+
strlen
(
response
->
deviceCod
e
)
+
strlen
(
response
->
identity
)
+
1
;
res_info
=
malloc
(
res_info_len
);
if
(
res_info
==
NULL
)
{
free
(
payload
);
...
...
@@ -509,7 +509,7 @@ int dm_msg_response(_IN_ kk_msg_request_payload_t *request, _IN_ kk_msg_response
memset
(
res_info
,
0
,
res_info_len
);
snprintf
(
res_info
,
res_info_len
,
DM_MSG_INFO
,
response
->
msgtype
,
response
->
product
_key
,
response
->
device_nam
e
,
response
->
identity
);
response
->
product
Type
,
response
->
deviceCod
e
,
response
->
identity
);
memset
(
&
lite
,
0
,
sizeof
(
lite_cjson_t
));
...
...
@@ -598,7 +598,7 @@ static int dm_msg_request_parse(_IN_ char *payload, _IN_ int payload_len, _OU_ k
}
int
dm_msg_thing_property_set_reply
(
char
product
_type
[
PRODUCT_KEY_MAXLEN
],
char
device_name
[
DEVICE_NAM
E_MAXLEN
],
char
*
payload
,
unsigned
int
payload_len
,
int
dm_msg_thing_property_set_reply
(
char
product
Type
[
PRODUCT_TYPE_MAXLEN
],
char
deviceCode
[
DEVICE_COD
E_MAXLEN
],
char
*
payload
,
unsigned
int
payload_len
,
void
*
context
){
kk_msg_request_payload_t
request
;
...
...
@@ -609,7 +609,7 @@ int dm_msg_thing_property_set_reply(char product_type[PRODUCT_KEY_MAXLEN], char
memset
(
&
request
,
0
,
sizeof
(
kk_msg_request_payload_t
));
memset
(
&
response
,
0
,
sizeof
(
kk_msg_response_t
));
res
=
dm_mgr_search_device_by_pkdn
(
product
_type
,
device_nam
e
,
&
devid
);
res
=
dm_mgr_search_device_by_pkdn
(
product
Type
,
deviceCod
e
,
&
devid
);
if
(
res
<
SUCCESS_RETURN
)
{
ERROR_PRINT
(
"dm_mgr_search_device_by_pkdn failed"
);
return
res
;
...
...
@@ -623,8 +623,8 @@ int dm_msg_thing_property_set_reply(char product_type[PRODUCT_KEY_MAXLEN], char
/* Response */
response
.
msgtype
=
MSG_SETREPLY
;
memset
(
response
.
identity
,
""
,
strlen
(
""
));
memcpy
(
response
.
product
_key
,
product_type
,
strlen
(
product_t
ype
));
memcpy
(
response
.
device
_name
,
device_name
,
strlen
(
device_nam
e
));
memcpy
(
response
.
product
Type
,
productType
,
strlen
(
productT
ype
));
memcpy
(
response
.
device
Code
,
deviceCode
,
strlen
(
deviceCod
e
));
response
.
code
=
(
res
==
SUCCESS_RETURN
)
?
(
IOTX_DM_ERR_CODE_SUCCESS
)
:
(
IOTX_DM_ERR_CODE_REQUEST_ERROR
);
dm_msg_response
(
&
request
,
&
response
,
"{}"
,
strlen
(
"{}"
),
NULL
);
}
...
...
midware/midware/dm/kk_linkkit.c
View file @
c02ee8a2
...
...
@@ -287,7 +287,7 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
}
else
if
(
msgType
==
MSG_PROPERTYSET
){
INFO_PRINT
(
"property set reply
\n
"
);
cJSON
*
product_type
=
cJSON_GetObjectItem
(
info
,
MSG_PRODUCT_TYPE_STR
);
cJSON
*
device_name
=
cJSON_GetObjectItem
(
info
,
MSG_DEVICE_
NAM
E_STR
);
cJSON
*
device_name
=
cJSON_GetObjectItem
(
info
,
MSG_DEVICE_
COD
E_STR
);
dm_msg_thing_property_set_reply
(
product_type
->
valuestring
,
device_name
->
valuestring
,
payload
->
valuestring
,
strlen
(
payload
->
valuestring
),
NULL
);
//kk_tsl_service_property_set(topic->valuestring, payload->valuestring, strlen(payload->valuestring), NULL);
}
else
if
(
msgType
==
MSG_OTA_UPGRADE
){
...
...
@@ -1654,18 +1654,18 @@ int iot_linkkit_subdev_query_id(char product_key[IOTX_PRODUCT_KEY_LEN + 1], char
#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
],
char
device_m
ac
[
DEVICE_MAC_MAXLEN
]){
int
kk_mid_subdev_add
(
char
product
Type
[
PRODUCT_TYPE_MAXLEN
],
char
productCode
[
PRODUCT_CODE_MAXLEN
],
char
deviceCode
[
DEVICE_CODE_MAXLEN
],
char
fatherM
ac
[
DEVICE_MAC_MAXLEN
]){
int
res
=
0
;
int
devid
=
0
;
res
=
dm_mgr_subdev_create
(
product
_key
,
device_name
,
device_secret
,
device_m
ac
,
&
devid
);
res
=
dm_mgr_subdev_create
(
product
Type
,
productCode
,
deviceCode
,
fatherM
ac
,
&
devid
);
if
(
res
!=
SUCCESS_RETURN
)
{
ERROR_PRINT
(
"subdev create Failed
\n
"
);
return
FAIL_RETURN
;
}
INFO_PRINT
(
"subdev open susseed, devid = %d
\n
"
,
devid
);
res
=
kk_subDev_insert_db
(
0
,
product
_key
,
device_name
,
device_secret
,
device_mac
);
res
=
kk_subDev_insert_db
(
0
,
product
Type
,
productCode
,
deviceCode
,
fatherMac
,
"1.1.0"
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
...
...
midware/midware/dm/kk_sub_db.c
View file @
c02ee8a2
...
...
@@ -49,7 +49,7 @@ static int kk_subDev_db_Init(void)
}
INFO_PRINT
(
"sub db Database opened
\n
"
);
{
const
char
*
pSubDevTable
=
"CREATE TABLE IF NOT EXISTS SubDeviceInfo(idx INTEGER,isOnline INTEGER,product
_type varchar(33), device_name varchar(33), device_secret varchar(33),device_mac varchar(17
))"
;
const
char
*
pSubDevTable
=
"CREATE TABLE IF NOT EXISTS SubDeviceInfo(idx INTEGER,isOnline INTEGER,product
Type varchar(33),productCode varchar(33),deviceCode varchar(33),fatherMac varchar(17),version varchar(33
))"
;
char
*
pcErr
;
...
...
@@ -91,9 +91,10 @@ static int _kk_load_subDevice(void)
else
{
ctx
->
subDevNum
++
;
}
iotx_dm_subscribe
(
devId
);
kk_dm_ota_report_version
(
devId
,
"1.0.0"
);
//todo
usleep
(
100000
);
iotx_dm_subscribe
(
devId
);
kk_dm_ota_report_version
(
devId
,
sqlite3_column_text
(
stmt
,
6
));
//version
//usleep(100000);
}
sqlite3_finalize
(
stmt
);
_kk_subDb_unlock
();
...
...
@@ -130,7 +131,7 @@ static int _kk_check_subDev_exist(const char* device_mac)
sqlite3_prepare_v2
(
ctx
->
pDb
,
searchCmd
,
strlen
(
searchCmd
),
&
stmt
,
NULL
);
INFO_PRINT
(
"total_column = %d
\n
"
,
sqlite3_column_count
(
stmt
));
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
pmac
=
sqlite3_column_text
(
stmt
,
5
);
pmac
=
sqlite3_column_text
(
stmt
,
4
);
if
(
!
strcmp
(
device_mac
,
pmac
))
{
isExist
=
1
;
...
...
@@ -146,23 +147,23 @@ static int _kk_check_subDev_exist(const char* device_mac)
}
int
kk_subDev_insert_db
(
int
isOnline
,
char
product
_type
[
PRODUCT_KEY_MAXLEN
],
char
device_name
[
DEVICE_NAM
E_MAXLEN
],
\
char
device
_secret
[
DEVICE_SECRET_MAXLEN
],
char
device_mac
[
DEVICE_MAC
_MAXLEN
])
int
kk_subDev_insert_db
(
int
isOnline
,
char
product
Type
[
PRODUCT_TYPE_MAXLEN
],
char
productCode
[
PRODUCT_COD
E_MAXLEN
],
\
char
device
Code
[
DEVICE_CODE_MAXLEN
],
char
fatherMac
[
DEVICE_MAC_MAXLEN
],
char
version
[
DEVICE_VERSION
_MAXLEN
])
{
const
char
*
insertCmd
=
"insert into SubDeviceInfo (idx,isOnline, product
_type, device_name,device_secret,device_mac) values ('%d','%d', '%s',
'%s','%s','%s');"
;
const
char
*
insertCmd
=
"insert into SubDeviceInfo (idx,isOnline, product
Type,productCode,deviceCode,fatherMac,version) values ('%d','%d', '%s', '%s',
'%s','%s','%s');"
;
char
*
sqlCmd
=
NULL
;
int
rc
=
0
;
char
*
zErrMsg
=
0
;
kk_subDb_ctx_t
*
ctx
=
_kk_subDb_get_ctx
();
if
(
_kk_check_subDev_exist
((
const
char
*
)
device
_mac
)
==
1
)
if
(
_kk_check_subDev_exist
((
const
char
*
)
device
Code
)
==
1
)
{
WARNING_PRINT
(
"[%s][%d] DATA ALREADY EXIST!!!
\n
"
,
__FUNCTION__
,
__LINE__
);
return
SUCCESS_RETURN
;
}
_kk_subDb_lock
();
sqlCmd
=
sqlite3_mprintf
(
insertCmd
,
ctx
->
subDevNum
,
isOnline
,
product
_type
,
device_name
,
device_secret
,
device_mac
);
sqlCmd
=
sqlite3_mprintf
(
insertCmd
,
ctx
->
subDevNum
,
isOnline
,
product
Type
,
productCode
,
deviceCode
,
fatherMac
,
version
);
rc
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
rc
!=
SQLITE_OK
){
...
...
@@ -176,16 +177,16 @@ int kk_subDev_insert_db(int isOnline,char product_type[PRODUCT_KEY_MAXLEN],char
_kk_subDb_unlock
();
return
SUCCESS_RETURN
;
}
int
kk_subDev_delete_byMac
(
char
device
_mac
[
DEVICE_MAC
_MAXLEN
])
int
kk_subDev_delete_byMac
(
char
device
Code
[
DEVICE_CODE
_MAXLEN
])
{
const
char
*
deleteCmd
=
"delete from SubDeviceInfo where device
Mac
= %s;"
;
const
char
*
deleteCmd
=
"delete from SubDeviceInfo where device
Code
= %s;"
;
char
*
sqlCmd
=
NULL
;
int
rc
=
0
;
char
*
zErrMsg
=
0
;
kk_subDb_ctx_t
*
ctx
=
_kk_subDb_get_ctx
();
_kk_subDb_lock
();
sqlCmd
=
sqlite3_mprintf
(
deleteCmd
,
device
_mac
);
sqlCmd
=
sqlite3_mprintf
(
deleteCmd
,
device
Code
);
INFO_PRINT
(
"Table delete data sqlCmd:%s
\n
"
,
sqlCmd
);
rc
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
...
...
midware/midware/dm/kk_sub_db.h
View file @
c02ee8a2
...
...
@@ -4,15 +4,15 @@
typedef
struct
{
int
isOnline
;
int
index
;
char
device_mac
[
DEVICE_MAC
_MAXLEN
];
char
product
_id
[
PRODUCT_KEY
_MAXLEN
];
char
device
_sn
[
DEVICE_SN
_MAXLEN
];
char
device_id
[
DEVICE_NAME
_MAXLEN
];
char
productType
[
PRODUCT_TYPE
_MAXLEN
];
char
product
Code
[
PRODUCT_CODE
_MAXLEN
];
char
device
Code
[
DEVICE_CODE
_MAXLEN
];
char
fatherMac
[
DEVICE_MAC
_MAXLEN
];
}
kk_dm_subdev_t
;
int
kk_subDb_init
(
void
);
int
kk_subDev_insert_db
(
int
isOnline
,
char
device_mac
[
DEVICE_MAC_MAXLEN
],
char
product_Id
[
PRODUCT_KEY
_MAXLEN
],
\
char
device_SN
[
DEVICE_SN_MAXLEN
],
char
device_Id
[
DEVICE_NAME
_MAXLEN
]);
int
kk_subDev_insert_db
(
int
isOnline
,
char
productType
[
PRODUCT_TYPE_MAXLEN
],
char
productCode
[
PRODUCT_CODE
_MAXLEN
],
\
char
deviceCode
[
DEVICE_CODE_MAXLEN
],
char
fatherMac
[
DEVICE_MAC_MAXLEN
],
char
version
[
DEVICE_VERSION
_MAXLEN
]);
int
kk_subDev_delete_byMac
(
char
device_mac
[
DEVICE_MAC_MAXLEN
]);
int
kk_subDev_update_online
(
int
isOnline
,
const
char
*
device_mac
);
...
...
midware/midware/dm/kk_wlist_mng.c
View file @
c02ee8a2
...
...
@@ -17,6 +17,7 @@
typedef
struct
{
void
*
mutex
;
int
isOpened
;
int
isInited
;
int
wlistNum
;
sqlite3
*
pDb
;
}
kk_wlist_ctx_t
;
...
...
@@ -102,8 +103,8 @@ static int _kk_check_exist(const char* device_mac)
}
static
int
kk_wlist_insert_db
(
int
index
,
char
device_mac
[
DEVICE_MAC_MAXLEN
],
char
product_Id
[
PRODUCT_
KEY
_MAXLEN
],
\
char
device_SN
[
DEVICE_SN_MAXLEN
],
char
device_Id
[
DEVICE_
NAM
E_MAXLEN
])
static
int
kk_wlist_insert_db
(
int
index
,
char
device_mac
[
DEVICE_MAC_MAXLEN
],
char
product_Id
[
PRODUCT_
CODE
_MAXLEN
],
\
char
device_SN
[
DEVICE_SN_MAXLEN
],
char
device_Id
[
DEVICE_
COD
E_MAXLEN
])
{
const
char
*
insertCmd
=
"insert into WhiteList (idx, deviceMac, productId,deviceSN,deviceId) values ('%d', '%s', '%s','%s','%s');"
;
char
*
sqlCmd
=
NULL
;
...
...
@@ -155,12 +156,20 @@ int kk_wlist_status_open(int isOpen)
{
int
res
=
0
;
kk_wlist_ctx_t
*
ctx
=
_kk_wlist_get_ctx
();
if
(
ctx
->
isOpened
)
{
printf
(
"[%s][%d] ALREADY OPENED
\n
"
,
__FUNCTION__
,
__LINE__
,
res
);
return
SUCCESS_RETURN
;
}
res
=
kk_tsl_set_value
(
kk_tsl_set_property_value
,
0
,
KK_TSL_GATAWAY_WHITELIST_IDENTIFIER
,
&
isOpen
,
NULL
);
if
(
res
!=
SUCCESS_RETURN
){
ERROR_PRINT
(
"[%s][%d] res:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
res
);
return
FAIL_RETURN
;
}
ctx
->
isOpened
=
1
;
ctx
->
isOpened
=
isOpen
;
if
(
ctx
->
isOpened
){
kk_wlist_init
();
}
return
SUCCESS_RETURN
;
}
int
kk_load_wlist
(
void
)
...
...
@@ -194,7 +203,11 @@ int kk_wlist_init(void)
{
int
res
=
0
;
kk_wlist_ctx_t
*
ctx
=
_kk_wlist_get_ctx
();
if
(
ctx
->
isInited
)
{
return
SUCCESS_RETURN
;
}
/* Create Mutex */
ctx
->
mutex
=
HAL_MutexCreate
();
if
(
ctx
->
mutex
==
NULL
)
{
...
...
@@ -207,6 +220,7 @@ int kk_wlist_init(void)
}
kk_load_wlist
();
ctx
->
isInited
=
1
;
return
SUCCESS_RETURN
;
}
int
kk_set_wlist_byIdx
(
int
idx
,
kk_wlist_dev_t
*
wlist_dev
)
...
...
midware/midware/dm/kk_wlist_mng.h
View file @
c02ee8a2
...
...
@@ -4,9 +4,9 @@
typedef
struct
{
char
device_mac
[
DEVICE_MAC_MAXLEN
];
char
product_id
[
PRODUCT_
KEY
_MAXLEN
];
char
product_id
[
PRODUCT_
TYPE
_MAXLEN
];
char
device_sn
[
DEVICE_SN_MAXLEN
];
char
device_id
[
DEVICE_
NAM
E_MAXLEN
];
char
device_id
[
DEVICE_
COD
E_MAXLEN
];
int
index
;
}
kk_wlist_dev_t
;
int
kk_wlist_init
(
void
);
...
...
midware/midware/midware.c
View file @
c02ee8a2
...
...
@@ -45,7 +45,7 @@ void mid_cb(void* data, int len){
info_root
=
cJSON_GetObjectItem
(
json
,
MSG_INFO_STR
);
info
=
cJSON_Parse
(
info_root
->
valuestring
);
product_type
=
cJSON_GetObjectItem
(
info
,
MSG_PRODUCT_TYPE_STR
);
device_name
=
cJSON_GetObjectItem
(
info
,
MSG_DEVICE_
NAM
E_STR
);
device_name
=
cJSON_GetObjectItem
(
info
,
MSG_DEVICE_
COD
E_STR
);
type
=
cJSON_GetObjectItem
(
info
,
MSG_TYPE_STR
);
switch
(
atoi
(
type
->
valuestring
))
{
...
...
@@ -109,6 +109,7 @@ void kk_platMsg_handle(void* data){
cJSON
*
jsonPay
;
cJSON
*
proType
;
cJSON
*
proCode
;
cJSON
*
devCode
;
cJSON
*
mac
;
json
=
cJSON_Parse
(
data
);
...
...
@@ -123,9 +124,9 @@ void kk_platMsg_handle(void* data){
jsonPay
=
cJSON_GetObjectItem
(
json
,
"params"
);
proType
=
cJSON_GetObjectItem
(
jsonPay
,
"productType"
);
proCode
=
cJSON_GetObjectItem
(
jsonPay
,
"productCode"
);
devCode
=
cJSON_GetObjectItem
(
jsonPay
,
"deviceCode"
);
INFO_PRINT
(
"productType productCode mac: [%s][%s] [%s]
\n
"
,
proType
->
valuestring
,
proCode
->
valuestring
,
mac
->
valuestring
);
kk_mid_subdev_add
(
proType
->
valuestring
,
proCode
->
valuestring
,
""
,
mac
->
valuestring
);
kk_mid_subdev_add
(
proType
->
valuestring
,
proCode
->
valuestring
,
devCode
->
valuestring
,
mac
->
valuestring
);
}
else
if
(
method
!=
NULL
&&
mac
!=
NULL
){
INFO_PRINT
(
"save property and send to cloud
\n
"
);
...
...
@@ -276,7 +277,7 @@ int main(const int argc, const char **argv)
kk_platMsg_dispatch
();
/*if (ct == 0){
ct =1;
void* buf = "{ \"msgId\": \"7\", \"version\": \"1.0\", \"mac\": \"588E81FFFED3834A\", \"method\": \"thing.topo.add\", \"params\": { \"AppVersion\": \"10\", \"device
Type\": \"1\", \"deviceCode\": \"2\", \"productType\": \"3\", \"productCode\": \"
4\" }}";
void* buf = "{ \"msgId\": \"7\", \"version\": \"1.0\", \"mac\": \"588E81FFFED3834A\", \"method\": \"thing.topo.add\", \"params\": { \"AppVersion\": \"10\", \"device
Code\": \"1212121212121212\", \"productType\": \"curtain\", \"productCode\": \"2
4\" }}";
kk_platMsg_handle(buf);
//kk_set_tsl_by_productKey("a1OYuSallan","model.json");
//kk_mid_subdev_add("a1OYuSallan","allanWno8yDdsjCX15iq","","aabbccddeeff1122");
...
...
midware/midware/utils/infra_defs.h
View file @
c02ee8a2
...
...
@@ -298,14 +298,14 @@ typedef enum IOT_RETURN_CODES {
}
iotx_err_t
;
#endif
#if 0
typedef struct _iotx_dev_meta_info {
char product_key[IOTX_PRODUCT_KEY_LEN + 1];
char product_secret[IOTX_PRODUCT_SECRET_LEN + 1];
char device_name[IOTX_DEVICE_NAME_LEN + 1];
char device_secret[IOTX_DEVICE_SECRET_LEN + 1];
} iotx_dev_meta_info_t;
#endif
typedef
struct
{
const
char
*
region
;
uint16_t
port
;
...
...
midware/tsl/tsl_handle/kk_tsl_api.c
View file @
c02ee8a2
...
...
@@ -1207,12 +1207,12 @@ int kk_tsl_set_value(kk_tsl_set_t set, int devId, const char *identifier,
return
SUCCESS_RETURN
;
}
int
kk_msg_uri_parse_pkdn
(
_IN_
char
*
uri
,
_IN_
int
uri_len
,
_IN_
int
start_deli
,
_IN_
int
end_deli
,
_OU_
char
product
_key
[
PRODUCT_KEY_MAXLEN
],
_OU_
char
device_name
[
DEVICE_NAM
E_MAXLEN
])
_OU_
char
product
Type
[
PRODUCT_TYPE_MAXLEN
],
_OU_
char
deviceCode
[
DEVICE_COD
E_MAXLEN
])
{
int
res
=
0
,
start
=
0
,
end
=
0
,
slice
=
0
;
if
(
uri
==
NULL
||
uri_len
<=
0
||
product
_key
==
NULL
||
device_nam
e
==
NULL
||
(
strlen
(
product
_key
)
>=
PRODUCT_KEY_MAXLEN
)
||
(
strlen
(
device_name
)
>=
DEVICE_NAM
E_MAXLEN
))
{
if
(
uri
==
NULL
||
uri_len
<=
0
||
product
Type
==
NULL
||
deviceCod
e
==
NULL
||
(
strlen
(
product
Type
)
>=
PRODUCT_TYPE_MAXLEN
)
||
(
strlen
(
deviceCode
)
>=
DEVICE_COD
E_MAXLEN
))
{
return
INVALID_PARAMETER
;
}
...
...
@@ -1234,8 +1234,8 @@ int kk_msg_uri_parse_pkdn(_IN_ char *uri, _IN_ int uri_len, _IN_ int start_deli,
/* dm_log_debug("URI Product Key: %.*s, Device Name: %.*s", slice - start - 1, uri + start + 1, end - slice - 1,
uri + slice + 1); */
memcpy
(
product
_key
,
uri
+
start
+
1
,
slice
-
start
-
1
);
memcpy
(
device
_nam
e
,
uri
+
slice
+
1
,
end
-
slice
-
1
);
memcpy
(
product
Type
,
uri
+
start
+
1
,
slice
-
start
-
1
);
memcpy
(
device
Cod
e
,
uri
+
slice
+
1
,
end
-
slice
-
1
);
return
SUCCESS_RETURN
;
}
...
...
@@ -1287,8 +1287,8 @@ int kk_tsl_service_property_set(const char *topic, const char *payload, unsigned
int
res
=
0
,
devid
=
0
;
char
product
_key
[
PRODUCT_KEY
_MAXLEN
]
=
{
0
};
char
device
_name
[
DEVICE_NAM
E_MAXLEN
]
=
{
0
};
char
product
Type
[
PRODUCT_TYPE
_MAXLEN
]
=
{
0
};
char
device
Code
[
DEVICE_COD
E_MAXLEN
]
=
{
0
};
memset
(
&
request
,
0
,
sizeof
(
kk_msg_request_payload_t
));
...
...
@@ -1300,11 +1300,11 @@ int kk_tsl_service_property_set(const char *topic, const char *payload, unsigned
/* Request */
/* Request */
res
=
kk_msg_uri_parse_pkdn
((
char
*
)
topic
,
strlen
(
topic
),
2
+
KK_URI_OFFSET
,
4
+
KK_URI_OFFSET
,
product
_key
,
device
_nam
e
);
res
=
kk_msg_uri_parse_pkdn
((
char
*
)
topic
,
strlen
(
topic
),
2
+
KK_URI_OFFSET
,
4
+
KK_URI_OFFSET
,
product
Type
,
device
Cod
e
);
res
=
dm_mgr_search_device_by_pkdn
(
product
_key
,
device_nam
e
,
&
devid
);
res
=
dm_mgr_search_device_by_pkdn
(
product
Type
,
deviceCod
e
,
&
devid
);
if
(
res
<
SUCCESS_RETURN
)
{
return
res
;
}
...
...
midware/tsl/tsl_handle/kk_tsl_api.h
View file @
c02ee8a2
...
...
@@ -78,7 +78,7 @@ extern int kk_tsl_get_value(kk_tsl_get_t method_get, int devId, const char *iden
char
**
value_str
);
extern
int
kk_msg_uri_parse_pkdn
(
_IN_
char
*
uri
,
_IN_
int
uri_len
,
_IN_
int
start_deli
,
_IN_
int
end_deli
,
\
_OU_
char
product
_key
[
PRODUCT_KEY_MAXLEN
],
_OU_
char
device_name
[
DEVICE_NAM
E_MAXLEN
]);
_OU_
char
product
Type
[
PRODUCT_TYPE_MAXLEN
],
_OU_
char
deviceCode
[
DEVICE_COD
E_MAXLEN
]);
extern
int
kk_tsl_service_property_set
(
const
char
*
topic
,
const
char
*
payload
,
unsigned
int
payload_len
,
void
*
context
);
extern
int
kk_tsl_post_property
(
int
devId
,
const
char
*
property_identifier
);
...
...
midware/tsl/tsl_handle/kk_tsl_common.h
View file @
c02ee8a2
...
...
@@ -12,11 +12,13 @@
#define _OU_
#endif
#define PRODUCT_KEY_MAXLEN (32 + 1)
#define DEVICE_NAME_MAXLEN (32 + 1)
#define DEVICE_SECRET_MAXLEN (64 + 1)
#define PRODUCT_TYPE_MAXLEN (32 + 1)
#define PRODUCT_CODE_MAXLEN (32 + 1)
#define DEVICE_CODE_MAXLEN (32 + 1)
#define DEVICE_MAC_MAXLEN (16 + 1)
#define DEVICE_SN_MAXLEN (32 + 1)
#define DEVICE_VERSION_MAXLEN (32 + 1)
#define DM_UTILS_UINT16_STRLEN (5)
#define DM_UTILS_UINT32_STRLEN (10)
...
...
midware/tsl/tsl_handle/kk_tsl_load.c
View file @
c02ee8a2
...
...
@@ -2,11 +2,15 @@
#include <string.h>
#include <stdio.h>
#include "kk_tsl_common.h"
#include "kk_dm_mng.h"
#include "kk_log.h"
#define TSL_PATH_FILE "/home/tsl/%s.json"
char
*
kk_load_json
(
const
char
*
product_type
)
#define TSL_SUBDEVICE_PATH_FILE "/home/tsl/product_%s.json"
#define TSL_GATEWAY_PATH_FILE "/home/tsl/gateway-%s.json"
#define TSL_CCU_PATH_FILE "/home/tsl/ccu-%s.json"
char
*
kk_load_json
(
const
char
*
productCode
,
int
type
)
{
FILE
*
fp
;
char
*
buf
=
NULL
;
...
...
@@ -14,13 +18,33 @@ char* kk_load_json(const char *product_type)
int
path_len
=
0
;
unsigned
int
filesize
;
path_len
=
strlen
(
TSL_PATH_FILE
)
+
strlen
(
product_type
)
+
1
;
if
(
type
==
KK_DM_DEVICE_CCU
){
path_len
=
strlen
(
TSL_CCU_PATH_FILE
)
+
strlen
(
productCode
)
+
1
;
}
else
if
(
type
==
KK_DM_DEVICE_GATEWAY
){
path_len
=
strlen
(
TSL_GATEWAY_PATH_FILE
)
+
strlen
(
productCode
)
+
1
;
}
else
{
path_len
=
strlen
(
TSL_SUBDEVICE_PATH_FILE
)
+
strlen
(
productCode
)
+
1
;
}
tslPath
=
malloc
(
path_len
);
if
(
tslPath
==
NULL
){
return
NULL
;
}
memset
(
tslPath
,
0x0
,
path_len
);
snprintf
(
tslPath
,
path_len
,
TSL_PATH_FILE
,
product_type
);
if
(
type
==
KK_DM_DEVICE_CCU
){
snprintf
(
tslPath
,
path_len
,
TSL_CCU_PATH_FILE
,
productCode
);
}
else
if
(
type
==
KK_DM_DEVICE_GATEWAY
){
snprintf
(
tslPath
,
path_len
,
TSL_GATEWAY_PATH_FILE
,
productCode
);
}
else
{
snprintf
(
tslPath
,
path_len
,
TSL_SUBDEVICE_PATH_FILE
,
productCode
);
}
INFO_PRINT
(
"
\n
[%s][%d]tslPath:%s!!!
\n
"
,
__FUNCTION__
,
__LINE__
,
tslPath
);
if
(
!
(
fp
=
fopen
(
tslPath
,
"a+"
)))
{
...
...
midware/tsl/tsl_handle/kk_tsl_load.h
View file @
c02ee8a2
#ifndef __TSL_DATA_LOAD__
#define __TSL_DATA_LOAD__
char
*
kk_load_json
(
const
char
*
product_type
);
char
*
kk_load_json
(
const
char
*
productCode
,
int
type
);
#endif
midware/tsl/tsl_handle/kk_utils.c
View file @
c02ee8a2
...
...
@@ -188,18 +188,18 @@ void kk_MutexDestroy(void *mutex)
free
(
mutex
);
}
int
kk_utils_service_name
(
_IN_
const
char
*
prefix
,
_IN_
const
char
*
name
,
_IN_
char
product
_key
[
PRODUCT_KEY
_MAXLEN
],
_IN_
char
device
_name
[
DEVICE_NAM
E_MAXLEN
],
_OU_
char
**
service_name
)
int
kk_utils_service_name
(
_IN_
const
char
*
prefix
,
_IN_
const
char
*
name
,
_IN_
char
product
Type
[
PRODUCT_TYPE
_MAXLEN
],
_IN_
char
device
Code
[
DEVICE_COD
E_MAXLEN
],
_OU_
char
**
service_name
)
{
int
prefix_len
=
(
prefix
==
NULL
)
?
(
0
)
:
(
strlen
(
prefix
));
int
name_len
=
(
name
==
NULL
)
?
(
0
)
:
(
strlen
(
name
));
int
service_name_len
=
0
;
if
((
prefix
==
NULL
&&
name
==
NULL
)
||
product
_key
==
NULL
||
device_nam
e
==
NULL
||
if
((
prefix
==
NULL
&&
name
==
NULL
)
||
product
Type
==
NULL
||
deviceCod
e
==
NULL
||
service_name
==
NULL
||
*
service_name
!=
NULL
)
{
return
INVALID_PARAMETER
;
}
service_name_len
=
prefix_len
+
name_len
+
strlen
(
product
_key
)
+
strlen
(
device_nam
e
)
+
1
;
service_name_len
=
prefix_len
+
name_len
+
strlen
(
product
Type
)
+
strlen
(
deviceCod
e
)
+
1
;
*
service_name
=
malloc
(
service_name_len
);
if
(
*
service_name
==
NULL
)
{
return
MEMORY_NOT_ENOUGH
;
...
...
@@ -207,7 +207,7 @@ int kk_utils_service_name(_IN_ const char *prefix, _IN_ const char *name, _IN_ c
memset
(
*
service_name
,
0
,
service_name_len
);
if
(
prefix
!=
NULL
)
{
snprintf
(
*
service_name
,
service_name_len
,
prefix
,
product
_key
,
device_nam
e
);
snprintf
(
*
service_name
,
service_name_len
,
prefix
,
product
Type
,
deviceCod
e
);
}
if
(
name
!=
NULL
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment