已开启
feat:添加专用热点网关模块,支持专用热点设备配网 #214
feat:添加专用热点网关模块,支持专用热点设备配网 #214
已开启
移动-吴昊创建于 13 天前
14 个文件变更+834-2
Mcore/bridge/bridge_init.c+1-1
@@ -1,4 +1,4 @@
1-/*1+/*
2 * Copyright (c) 2024-2026 CMCC Cmhi Co., Ltd.2 * Copyright (c) 2024-2026 CMCC Cmhi Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.4 * you may not use this file except in compliance with the License.
Mcore/infrastructure/define/comm_def.h+2-1
@@ -1,4 +1,4 @@
1-/*1+/*
2 * Copyright (c) 2024-2024 Huawei Device Co., Ltd.2 * Copyright (c) 2024-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.4 * you may not use this file except in compliance with the License.
@@ -237,6 +237,7 @@ typedef struct {
237#define STR_JSON_SEQ "seq"237#define STR_JSON_SEQ "seq"
238#define STR_JSON_MSG_ID "msgId"238#define STR_JSON_MSG_ID "msgId"
239#define STR_JSON_DEVICE_INFO "deviceInfo"239#define STR_JSON_DEVICE_INFO "deviceInfo"
240+#define STR_JSON_CONN_REQUEST "connRequest"
240#define STR_JSON_MAC "mac"241#define STR_JSON_MAC "mac"
241#define STR_JSON_BLE_MAC "bleMac"242#define STR_JSON_BLE_MAC "bleMac"
242#define STR_JSON_SLE_MAC "sleMac"243#define STR_JSON_SLE_MAC "sleMac"
Acore/wifi/application/dedap/include/dedap_coap_apiserver.h+90-0
@@ -0,0 +1,90 @@
1+/*
2+ * Copyright (c) 2024-2026 China Mobile (Hangzhou) Information Technology Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+#ifndef DEDAP_COAP_API_SERVER_H
17+#define DEDAP_COAP_API_SERVER_H
18+ 
19+#include <stdint.h>
20+#include "iotc_json.h"
21+#include "iotc_event_params.h"
22+#include "trans_socket.h"
23+ 
24+#ifdef __cplusplus
25+extern "C" {
26+#endif
27+ 
28+/* 专用热点设备监听的 CoAP 服务端口 */
29+#define DEDAP_DEVICE_COAP_SERVER_PORT 5683
30+ 
31+/**
32+ * @brief 解析 confignet/request 请求参数
33+ * @details 解析 JSON 中的 mac、connRequest、rssi,填充 IotcSubDevDiscoveredParam。
34+ * 供 DedapCoapDispatchHandler 和 dedap_coap_server.c 共用。
35+ * @param inData JSON 字符串
36+ * @param inLen JSON 长度
37+ * @param outParam 输出参数(调用方提供缓冲区)
38+ * @return 0 成功,非 0 失败
39+ */
40+int32_t DedapParseConfignetParam(const char *inData, uint32_t inLen,
41+ IotcSubDevDiscoveredParam *outParam);
42+ 
43+/**
44+ * @brief 处理 confignet/request 核心逻辑(解析 + 会话更新 + 上报)
45+ * @details 解析 JSON payload 中的设备信息,更新设备会话,发布 REPORT_SUBDEV 事件到 bridge。
46+ * @param inData 输入 JSON 字符串
47+ * @param inLen 输入数据长度
48+ * @param addr 设备地址(必填)
49+ * @return 0 成功,非0 失败
50+ */
51+int32_t DedapHandleConfignetRequest(const char *inData, uint32_t inLen,
52+ const SocketAddr *addr);
53+ 
54+/**
55+ * @brief dedap 模块 CoAP 请求分发处理
56+ * @details 根据 URI 路径分发到对应处理逻辑,返回 JSON 对象。
57+ * 调用方决定如何使用返回值(序列化或 CoAP 发送)。
58+ * 内部使用,供 DedapApiCoapRecvHandler 调用。
59+ *
60+ * 支持的 URI 路径:
61+ * - STR_URI_PATH_DEDAP_CONFIGNET_REQUEST : 设备配网请求,解析 connRequest 并发布到 bridge
62+ *
63+ * @param uriPath 请求 URI 路径(不含前导 '/'
64+ * @param srcIp 请求来源 IP 地址字符串(当前仅用于日志)
65+ * @param inData 输入数据(JSON 字符串)
66+ * @param inLen 输入数据长度
67+ * @return JSON 响应对象(调用方负责 IotcJsonDelete);未知 URI 或失败返回 NULL
68+ */
69+IotcJson* DedapCoapDispatchHandler(const char *uriPath, const char *srcIp,
70+ const char *inData, uint32_t inLen);
71+ 
72+/**
73+ * @brief 外部 API 入口:接收并处理 dedap 模块 CoAP 请求,返回 JSON 字符串
74+ * @details 封装 DedapCoapDispatchHandler,将返回的 JSON 对象序列化为字符串。
75+ * 返回的字符串由 cJSON 分配,调用方须用 IotcJsonFreePrint 释放。
76+ *
77+ * @param uriPath 请求 URI 路径(不含前导 '/'
78+ * @param srcIp 请求来源 IP 地址字符串(当前仅用于日志)
79+ * @param inData 输入数据(JSON 字符串)
80+ * @param inLen 输入数据长度
81+ * @return JSON 响应字符串,调用方用 IotcJsonFreePrint 释放;失败返回 NULL
82+ */
83+char* DedapApiCoapRecvHandler(const char *uriPath, const char *srcIp,
84+ const char *inData, uint32_t inLen);
85+ 
86+#ifdef __cplusplus
87+}
88+#endif
89+ 
90+#endif /* DEDAP_COAP_API_SERVER_H */
Acore/wifi/application/dedap/include/dedap_coap_client.h+75-0
@@ -0,0 +1,75 @@
1+/*
2+ * Copyright (c) 2024-2026 China Mobile (Hangzhou) Information Technology Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+#ifndef DEDAP_COAP_CLIENT_H
17+#define DEDAP_COAP_CLIENT_H
18+ 
19+#include <stdint.h>
20+#include <stdbool.h>
21+#include "coap_endpoint.h"
22+#include "coap_endpoint_client.h"
23+#include "coap_net_stack.h"
24+#include "iotc_json.h"
25+#include "dedap_ctx.h"
26+ 
27+#ifdef __cplusplus
28+extern "C" {
29+#endif
30+ 
31+/**
32+ * @brief DeDAP CoAP请求描述。
33+ */
34+typedef struct {
35+ const char *uri;
36+ CoapMethodType code;
37+ const uint8_t *payload;
38+ uint32_t payloadLen;
39+ CoapClientRespHandler respHandler;
40+ DedapRequestType request;
41+} DedapCoapRequest;
42+ 
43+/**
44+ * @brief 发送CoAP请求。
45+ * @param request 请求描述。
46+ * @param sess 目标设备会话。
47+ * @return 0成功,非0表示参数非法、pending请求启动失败或CoAP发送失败。
48+ */
49+int32_t DedapCoapClientSendReq(const DedapCoapRequest *request, DedapDeviceSession *sess);
50+ 
51+/**
52+ * @brief 校验CoAP响应并解析JSON载荷。
53+ * @param resp CoAP响应报文。
54+ * @param respJson 输出的JSON对象,成功后由调用方释放。
55+ * @return 0成功,非0失败。
56+ */
57+int32_t DedapCoapClientParseRespJson(const CoapPacket *resp, IotcJson **respJson);
58+ 
59+/**
60+ * @brief 获取CoAP端点指针。
61+ * @return CoAP端点指针。
62+ */
63+CoapEndpoint *DedapCoapClientGetEndpoint(void);
64+ 
65+/**
66+ * @brief 检查CoAP客户端是否已初始化。
67+ * @return true已初始化,false未初始化。
68+ */
69+bool DedapCoapClientIsInitialized(void);
70+ 
71+#ifdef __cplusplus
72+}
73+#endif
74+ 
75+#endif /* DEDAP_COAP_CLIENT_H */
Acore/wifi/application/dedap/include/dedap_coap_enc.h+52-0
@@ -0,0 +1,52 @@
1+/*
2+ * Copyright (c) 2024-2026 China Mobile (Hangzhou) Information Technology Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+#ifndef DEDAP_COAP_ENC_H
17+#define DEDAP_COAP_ENC_H
18+ 
19+#include <stdint.h>
20+#include "trans_sess.h"
21+ 
22+#ifdef __cplusplus
23+extern "C" {
24+#endif
25+ 
26+/**
27+ * @brief 发送侧 CoAP payload 加密 handler。
28+ * @details 作为 send tail handler 注册到 CoAP session,自动加密业务报文。
29+ * SPEKE 协商报文自动跳过(speke session 为 NULL)。
30+ * @param msg 待发送的CoAP消息。
31+ * @param buf 消息编码缓冲区。
32+ * @param info 包含目标设备地址的附加信息。
33+ * @return SESS_CODE_CONTINUE表示继续发送,SESS_CODE_ERR表示处理失败。
34+ */
35+SessCode DedapCoapMsgSendEncryptProcess(SessMsg *msg, UtilsBuffer *buf, SessAddtlInfo *info);
36+ 
37+/**
38+ * @brief 接收侧 CoAP payload 解密 handler。
39+ * @details 作为 recv tail handler 注册到 CoAP session,自动解密业务报文。
40+ * SPEKE 协商报文自动跳过(speke session 为 NULL)。
41+ * @param msg 收到的CoAP消息。
42+ * @param buf 消息解码缓冲区。
43+ * @param info 包含来源设备地址的附加信息。
44+ * @return SESS_CODE_CONTINUE表示继续处理,SESS_CODE_ERR表示处理失败。
45+ */
46+SessCode DedapCoapMsgRecvDecryptProcess(SessMsg *msg, UtilsBuffer *buf, SessAddtlInfo *info);
47+ 
48+#ifdef __cplusplus
49+}
50+#endif
51+ 
52+#endif /* DEDAP_COAP_ENC_H */
Acore/wifi/application/dedap/include/dedap_coap_server.h+47-0
@@ -0,0 +1,47 @@
1+/*
2+ * Copyright (c) 2024-2026 China Mobile (Hangzhou) Information Technology Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+#ifndef DEDAP_COAP_SERVER_H
17+#define DEDAP_COAP_SERVER_H
18+ 
19+#include <stdint.h>
20+#include "comm_def.h"
21+ 
22+#ifdef __cplusplus
23+extern "C" {
24+#endif
25+ 
26+// 专用热点网关监听的默认端口
27+#define DEDAP_DEFAULT_PORT 5687
28+ 
29+/**
30+ * @brief 初始化CoAP接收处理器
31+ * @details 注册CoAP资源Handler到dedap的CoAP端点
32+ * @return 0成功,非0失败
33+ */
34+int32_t DedapCoapHandlerRegister(void);
35+ 
36+/**
37+ * @brief 反初始化CoAP接收处理器
38+ * @details 注销所有CoAP资源Handler
39+ * @return 无返回值;端点未初始化时跳过资源注销。
40+ */
41+void DedapCoapHandlerUnregister(void);
42+ 
43+#ifdef __cplusplus
44+}
45+#endif
46+ 
47+#endif /* DEDAP_COAP_SERVER_H */
Acore/wifi/application/dedap/include/dedap_connrequest.h+81-0
@@ -0,0 +1,81 @@
1+/*
2+ * Copyright (c) 2024-2026 China Mobile (Hangzhou) Information Technology Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+#ifndef DEDAP_CONNREQUEST_H
17+#define DEDAP_CONNREQUEST_H
18+ 
19+#include <stdint.h>
20+#include "iotc_event_params.h"
21+ 
22+#ifdef __cplusplus
23+extern "C" {
24+#endif
25+ 
26+/* ===== connRequest 格式:Oc-{deviceName}-{protoVer+PID+SN+cfgCap+p} ===== */
27+/* 前缀与分隔符 */
28+#define DEDAP_CONNREQUEST_PREFIX "Oc-"
29+#define DEDAP_CONNREQUEST_PREFIX_LEN 3
30+#define DEDAP_CONNREQUEST_SEPARATOR '-'
31+ 
32+/* 设备名称 */
33+#define DEDAP_CONNREQUEST_DEVICE_NAME_MIN_LEN 1
34+#define DEDAP_CONNREQUEST_DEVICE_NAME_MAX_LEN 10
35+ 
36+/* 数据部分字段布局(位于第二个'-'之后,共14字节) */
37+#define DEDAP_CONNREQ_DATA_MIN_LEN 14 /* protoVer(1)+PID(5)+SN(4)+hex(4) */
38+#define DEDAP_CONNREQ_PROTOVER_OFFSET 0
39+#define DEDAP_CONNREQ_PROTOVER_LEN 1
40+#define DEDAP_CONNREQ_PID_OFFSET 1
41+#define DEDAP_CONNREQ_PID_LEN 5
42+#define DEDAP_CONNREQ_SN_OFFSET 6
43+#define DEDAP_CONNREQ_SN_LEN 4
44+#define DEDAP_CONNREQ_HEX_OFFSET 10
45+#define DEDAP_CONNREQ_HEX_LEN 2
46+ 
47+/* 整体长度限制 */
48+#define DEDAP_CFGNET_REQUEST_MIN_LEN \
49+ (DEDAP_CONNREQUEST_PREFIX_LEN + DEDAP_CONNREQUEST_DEVICE_NAME_MIN_LEN + 1 + DEDAP_CONNREQ_DATA_MIN_LEN)
50+ 
51+/**
52+ * @brief 将单个hex字符转换为数值
53+ * @param c hex字符('0'-'9','A'-'F','a'-'f')
54+ * @return 转换后的4位值,非法字符返回0
55+ */
56+uint8_t DedapHexCharToUint4(char c);
57+ 
58+/**
59+ * @brief 将2个hex字符转换为uint8_t
60+ * @param hex 2个hex字符(不含\0
61+ * @return 转换后的值
62+ */
63+uint8_t DedapHexByteToUint8(const char hex[2]);
64+ 
65+/**
66+ * @brief 解析connRequest字段到IotcSubDevDiscoveredParam
67+ * @details 格式:"Oc-" + 设备名(<=10字节) + "-" + protoVer(1字符) + PID(5字符) + SN后缀(4字符) + 配网能力(hex 2字符) + p(hex 2字符)
68+ * 示例:"Oc-cmcc-21234500017000" → deviceName="cmcc", protoVer='2', prodId="12345", snSuffix="0001",
69+ * cfgCapability=0x70, p=0x00
70+ * @param connRequest connRequest字符串
71+ * @param connReqLen connRequest长度
72+ * @param result 输出:解析结果
73+ * @return 0成功,非0失败
74+ */
75+int32_t DedapParseConnRequest(const char *connRequest, uint32_t connReqLen, IotcSubDevDiscoveredParam *result);
76+ 
77+#ifdef __cplusplus
78+}
79+#endif
80+ 
81+#endif /* DEDAP_CONNREQUEST_H */
Acore/wifi/application/dedap/include/dedap_ctx.h+139-0
@@ -0,0 +1,139 @@
1+/*
2+ * Copyright (c) 2024-2026 China Mobile (Hangzhou) Information Technology Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+#ifndef DEDAP_CTX_H
17+#define DEDAP_CTX_H
18+ 
19+#include <stdint.h>
20+#include <stdbool.h>
21+#include "iotc_event_params.h"
22+#include "security_speke.h"
23+#include "iotc_socket.h" /* for SocketAddr */
24+#include "coap_net_stack.h"
25+#include "coap_endpoint_client.h"
26+#include "sched_event_loop.h"
27+#include "utils_list.h"
28+#ifdef __cplusplus
29+extern "C" {
30+#endif
31+ 
32+/* 替代框架接口中的 void *userData,业务层不得解引用该不透明类型。 */
33+typedef struct DedapUserData DedapUserData;
34+ 
35+/**
36+ * @brief 单个DEDAP请求的业务超时时间(毫秒)。
37+ */
38+#define DEDAP_PENDING_REQUEST_TIMEOUT_MS (10 * 1000)
39+ 
40+/**
41+ * @brief DEDAP请求类型,用于将响应和超时关联到具体设备会话。
42+ */
43+typedef enum {
44+ DEDAP_REQUEST_NONE = 0,
45+ DEDAP_REQUEST_SPEKE,
46+ DEDAP_REQUEST_GET_PROVISION,
47+ DEDAP_REQUEST_DEVICE_INFO,
48+ DEDAP_REQUEST_PROVISION_PSK,
49+ DEDAP_REQUEST_HUB_CFG,
50+} DedapRequestType;
51+ 
52+/**
53+ * @brief 单个设备的会话上下文。
54+ */
55+typedef struct {
56+ ListEntry node; /* 链表节点 */
57+ char mac[IOTC_MAC_STR_MAX_LEN]; /* 设备MAC地址 */
58+ char prodId[IOTC_DEV_PROID_LEN + 1]; /* 产品ID */
59+ char snSuffix[IOTC_DEV_SN_SUFFIX_LEN + 1]; /* 序列号后缀 */
60+ char pin[IOTC_DEV_PINCODE_LEN + 1]; /* 配网用PIN码 */
61+ char devId[IOTC_DEV_DEVICEID_MAX_LEN + 1]; /* 设备ID(配网后分配) */
62+ char domainId[IOTC_DEV_DOMAINID_MAX_LEN + 1]; /* 管理域ID(配网后分配) */
63+ char deviceName[IOTC_DEV_NAME_MAX_LEN + 1]; /* 设备名(从connRequest解析,<=10字节+'\0') */
64+ uint8_t protoVer; /* 协议版本(从connRequest解析) */
65+ uint8_t cfgCapability; /* 配网能力(从connRequest解析) */
66+ uint8_t p; /* p字段(从connRequest解析) */
67+ uint64_t createTime; /* 会话创建时间戳(毫秒) */
68+ uint64_t lastActiveTime; /* 最后活跃时间戳(毫秒) */
69+ SpekeSession *speke; /* SPEKE协商会话 */
70+ bool spekeReady; /* SPEKE协商是否已完成(密钥可用) */
71+ SocketAddr deviceAddr; /* WiFi设备地址 */
72+ DedapRequestType pendingRequest; /* 当前等待响应的请求类型 */
73+ int32_t pendingTimerId; /* 当前请求的业务超时定时器ID */
74+ char wifiSetupSsid[IOTC_SSID_MAX_LEN + 1]; /* 目标WiFi SSID */
75+ char wifiSetupPassword[IOTC_WIFI_PWD_MAX_LEN + 1]; /* 目标WiFi密码 */
76+ char wifiSetupBssid[IOTC_MAC_STR_MAX_LEN]; /* 目标WiFi BSSID */
77+ uint8_t wifiSetupChannel; /* 目标WiFi信道 */
78+ IotcPskInfo pskInfo; /* PSK认证信息 */
79+ void *provisionResponseJson; /* /getProvisionRequest 响应的 provision 部分(IotcJson*) */
80+ void *deviceInfoJson; /* /DeviceInfo 响应的 devInfo 对象(IotcJson*) */
81+} DedapDeviceSession;
82+ 
83+/**
84+ * @brief dedap统一上下文。
85+ * @details 将初始化状态、热点运行状态、设备会话链表、CoAP网络栈集中在一个结构中,
86+ * 通过GetDedapCtx()获取单例,减少分散的全局变量。
87+ */
88+typedef struct {
89+ ListEntry sessionList; /* 设备会话链表头 */
90+ CoapNetStack coapStack; /* CoAP客户端网络栈 */
91+ EventSource *coapSource; /* CoAP事件源 */
92+ bool initialized; /* 上下文是否已初始化 */
93+ bool hotspotRunning; /* 热点是否正在运行 */
94+ bool coapStarted; /* CoAP网络栈是否已启动 */
95+} DedapCtx;
96+ 
97+/**
98+ * @brief 获取dedap全局上下文。
99+ * @return dedap上下文指针。
100+ */
101+DedapCtx *GetDedapCtx(void);
102+ 
103+/**
104+ * @brief 初始化dedap上下文和设备会话链表。
105+ * @return 0表示成功,非0表示初始化失败。
106+ */
107+int32_t DedapCtxInit(void);
108+ 
109+/**
110+ * @brief 释放dedap上下文持有的传输层和设备会话资源。
111+ * @return 无返回值;上下文未初始化时直接返回。
112+ */
113+void DedapCtxDeinit(void);
114+ 
115+/**
116+ * @brief 初始化指定端口的dedap UDP传输层。
117+ * @param port UDP监听端口,0表示自动分配。
118+ * @return 0表示成功,非0表示服务器、处理器注册或网络栈启动失败。
119+ */
120+int32_t DedapTransportUdpInit(uint16_t port);
121+ 
122+/**
123+ * @brief 注销处理器并释放dedap UDP传输层。
124+ * @return 无返回值。
125+ */
126+void DedapTransportUdpDeinit(void);
127+ 
128+/**
129+ * @brief 将CoAP响应码映射为dedap业务错误码。
130+ * @param coapCode CoAP响应码。
131+ * @return 0表示成功响应,否则返回对应的dedap业务错误码。
132+ */
133+int32_t DedapMapCoapCodeToBusinessError(uint8_t coapCode);
134+ 
135+#ifdef __cplusplus
136+}
137+#endif
138+ 
139+#endif /* DEDAP_CTX_H */
Acore/wifi/application/dedap/include/dedap_device_session.h+143-0
@@ -0,0 +1,143 @@
1+/*
2+ * Copyright (c) 2024-2026 China Mobile (Hangzhou) Information Technology Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+#ifndef DEDAP_DEVICE_SESSION_H
17+#define DEDAP_DEVICE_SESSION_H
18+ 
19+#include <stdint.h>
20+#include "iotc_event_params.h"
21+#include "security_speke.h"
22+#include "dedap_ctx.h"
23+ 
24+#ifdef __cplusplus
25+extern "C" {
26+#endif
27+ 
28+/**
29+ * @brief 分配一个空闲的设备会话槽位。
30+ * @return 会话指针,无空闲槽位时返回NULL
31+ */
32+DedapDeviceSession *DedapAllocSession(void);
33+ 
34+/**
35+ * @brief 按MAC地址查找设备会话。
36+ * @param mac 设备MAC地址字符串。
37+ * @return 匹配的会话指针,未找到时返回NULL
38+ */
39+DedapDeviceSession *DedapFindSessionByMac(const char *mac);
40+ 
41+/**
42+ * @brief 按设备地址查找设备会话。
43+ * @param addr 设备地址指针。
44+ * @return 匹配的会话指针,未找到时返回NULL
45+ */
46+DedapDeviceSession *DedapFindSessionByAddr(const SocketAddr *addr);
47+ 
48+/**
49+ * @brief 为设备会话启动一个pending请求及独立业务超时定时器。
50+ * @param sess 设备会话指针。
51+ * @param request 请求类型。
52+ * @return 0表示成功,非0表示参数非法、已有pending请求或定时器创建失败。
53+ */
54+int32_t DedapStartPendingRequest(DedapDeviceSession *sess, DedapRequestType request);
55+ 
56+/**
57+ * @brief 按来源地址和请求类型完成pending请求并取消其业务定时器。
58+ * @param addr 响应来源地址。
59+ * @param request 预期请求类型。
60+ * @return 匹配且等待该响应的会话指针;参数非法、未找到或类型不匹配时返回NULL
61+ */
62+DedapDeviceSession *DedapCompletePendingRequest(const SocketAddr *addr, DedapRequestType request);
63+ 
64+/**
65+ * @brief 取消设备会话当前的pending请求及业务超时定时器。
66+ * @param sess 设备会话指针。
67+ * @return 无返回值;sess为NULL或没有pending请求时直接返回。
68+ */
69+void DedapCancelPendingRequest(DedapDeviceSession *sess);
70+ 
71+/**
72+ * @brief 释放设备会话。
73+ * @details 清理会话资源,包括SPEKE会话、状态重置等。
74+ * @param sess 设备会话指针。
75+ * @return 无返回值;sess为NULL时直接返回。
76+ */
77+void DedapFreeSession(DedapDeviceSession *sess);
78+ 
79+/**
80+ * @brief 上报失败并释放设备会话。
81+ * @param sess 设备会话指针;为NULL时不执行操作。
82+ * @param status 失败原因码。
83+ * @return 无返回值。
84+ */
85+void DedapAbortSession(DedapDeviceSession *sess, int32_t status);
86+ 
87+/**
88+ * @brief 启动指定WiFi设备的配网流程。
89+ * @details 发起与指定MAC地址设备的SPEKE协商和设备信息交换。
90+ * @param mac 设备MAC地址字符串。
91+ * @param prodId 设备产品ID。
92+ * @param pin 配网用PIN码,用于SPEKE密钥协商。
93+ * @return 0成功,非0失败。
94+ */
95+int32_t DedapDeviceProvisionStart(const char *mac, const char *prodId, const char *pin);
96+ 
97+/**
98+ * @brief 向设备下发管理域和配网信息。
99+ * @details 向设备发送hubCfg和provisionPSK消息,完成配网流程。
100+ * @param param 包含WiFi凭证和认证信息的配网参数。
101+ * @return 0成功,非0失败。
102+ */
103+int32_t DedapDeviceHubSetup(const IotcHubSetupParam *param);
104+ 
105+/**
106+ * @brief 向bridge发布设备认证事件。
107+ * @details SPEKE协商成功并获取设备信息后调用,将devInfo和provision信息上报给bridge。
108+ * @param sess 设备会话上下文。
109+ * @return 无返回值;认证数据未就绪或参数复制失败时中止会话。
110+ */
111+void DedapPublishAuthEvent(DedapDeviceSession *sess);
112+ 
113+/**
114+ * @brief 通知bridge添加子设备失败。
115+ * @param mac 设备MAC地址。
116+ * @param prodId 产品ID。
117+ * @param sn 序列号后缀。
118+ * @param status 失败原因码。
119+ * @return 无返回值;MAC为空或事件参数复制失败时不发布事件。
120+ */
121+void DedapPublishAddFail(const char *mac, const char *prodId, const char *sn, int32_t status);
122+ 
123+/**
124+ * @brief 通知bridge设备已在线。
125+ * @param mac 设备MAC地址。
126+ * @param devId 设备ID。
127+ * @return 无返回值;事件参数复制失败时不发布事件。
128+ */
129+void DedapPublishOnlineNotify(const char *mac, const char *devId);
130+ 
131+/**
132+ * @brief 通过EventBus向bridge上报发现的设备。
133+ * @param param 设备发现事件参数。
134+ * @param isRegistered 是否已注册。
135+ * @return 无返回值;参数复制失败时不发布事件。
136+ */
137+void DedapPublishReportSubDev(const IotcSubDevDiscoveredParam *param, bool isRegistered);
138+ 
139+#ifdef __cplusplus
140+}
141+#endif
142+ 
143+#endif /* DEDAP_DEVICE_SESSION_H */
Acore/wifi/application/dedap/include/dedap_event_handler.h+41-0
@@ -0,0 +1,41 @@
1+/*
2+ * Copyright (c) 2024-2026 China Mobile (Hangzhou) Information Technology Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+#ifndef DEDAP_EVENT_HANDLER_H
17+#define DEDAP_EVENT_HANDLER_H
18+ 
19+#include <stdint.h>
20+ 
21+#ifdef __cplusplus
22+extern "C" {
23+#endif
24+ 
25+/**
26+ * @brief 注册dedap事件订阅到bridge的EventBus。
27+ * @return 0成功,非0失败。
28+ */
29+int32_t DedapEventHandlerInit(void);
30+ 
31+/**
32+ * @brief 退订dedap事件订阅。
33+ * @return 无返回值。
34+ */
35+void DedapEventHandlerDeinit(void);
36+ 
37+#ifdef __cplusplus
38+}
39+#endif
40+ 
41+#endif /* DEDAP_EVENT_HANDLER_H */
Acore/wifi/application/dedap/include/dedap_hotspot.h+53-0
@@ -0,0 +1,53 @@
1+/*
2+ * Copyright (c) 2024-2026 China Mobile (Hangzhou) Information Technology Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+#ifndef DEDAP_HOTSPOT_H
17+#define DEDAP_HOTSPOT_H
18+ 
19+#include <stdint.h>
20+#include <stdbool.h>
21+ 
22+/** @brief CoAP 服务端端口号(WiFi设备端监听端口) */
23+#define DEDAP_COAP_SERVER_PORT 5683
24+ 
25+#ifdef __cplusplus
26+extern "C" {
27+#endif
28+ 
29+/**
30+ * @brief 启动专用热点(SoftAP),用于WiFi设备代理配网。
31+ * @details 创建带有生成SSID的SoftAP,使WiFi设备能够发现并连接以进行代理配网。
32+ * @return 0成功,非0失败。
33+ */
34+int32_t DedapHotspotStart(void);
35+ 
36+/**
37+ * @brief 停止专用热点。
38+ * @details 关闭SoftAP并清理相关资源。
39+ * @return 0成功,非0失败。
40+ */
41+int32_t DedapHotspotStop(void);
42+ 
43+/**
44+ * @brief 检查热点是否正在运行。
45+ * @return true表示热点处于活动状态,false表示未运行。
46+ */
47+bool DedapHotspotIsRunning(void);
48+ 
49+#ifdef __cplusplus
50+}
51+#endif
52+ 
53+#endif /* DEDAP_HOTSPOT_H */
Acore/wifi/application/dedap/include/dedap_provision.h+61-0
@@ -0,0 +1,61 @@
1+/*
2+ * Copyright (c) 2024-2026 China Mobile (Hangzhou) Information Technology Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+#ifndef DEDAP_PROVISION_H
17+#define DEDAP_PROVISION_H
18+ 
19+#include <stdint.h>
20+#include "comm_def.h"
21+#include "dedap_ctx.h"
22+ 
23+#ifdef __cplusplus
24+extern "C" {
25+#endif
26+ 
27+/* 专用热点网关->Wi-Fi设备之间的coap资源路径 */
28+// 网关下发网络配置信息
29+#define DEDAP_URI_PATH_HUB_CFG STR_URI_PATH_HUB_SETUP
30+// 网关下发管理凭证
31+#define DEDAP_URI_PATH_PROVISION_PSK STR_URI_PROVISION_PSK
32+// 网关发送speke协商请求
33+#define DEDAP_URI_PATH_SPEKE STR_URI_SPEKE // STR_URI_SPEKE_V2
34+// 网关获取设备身份信息
35+#define DEDAP_URI_PATH_GET_PROVISION_REQUEST STR_URI_PATH_GET_PROVISION_REQUEST
36+// 网关获取设备详情
37+#define DEDAP_URI_PATH_GET_DEVICE_INFO STR_URI_PATH_GET_DEVICE_INFO
38+ 
39+/**
40+ * @brief 下发hubCfg(WiFi网络凭证)到设备。
41+ * @details 构造JSON包含domainId、devId、ssid、password、channel、bssid,
42+ * 通过CoAP POST /hubCfg发送到WiFi设备,等待设备确认。
43+ * @param sess 设备会话上下文。
44+ * @return 0成功,非0失败。
45+ */
46+int32_t DedapProvisionSendHubCfg(DedapDeviceSession *sess);
47+ 
48+/**
49+ * @brief 下发provisionPSK(认证凭证)到设备。
50+ * @details 构造JSON包含domainId、pskId、psk、valid,
51+ * 通过CoAP POST /provisionPSK发送到WiFi设备,等待设备确认。
52+ * @param sess 设备会话上下文。
53+ * @return 0成功,非0失败。
54+ */
55+int32_t DedapProvisionSendPsk(DedapDeviceSession *sess);
56+ 
57+#ifdef __cplusplus
58+}
59+#endif
60+ 
61+#endif /* DEDAP_PROVISION_H */
Acore/wifi/application/dedap/include/dedap_service.h+43-0
@@ -0,0 +1,43 @@
1+/*
2+ * Copyright (c) 2024-2026 China Mobile (Hangzhou) Information Technology Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+#ifndef DEDAP_SERVICE_H
17+#define DEDAP_SERVICE_H
18+ 
19+#include <stdint.h>
20+ 
21+#ifdef __cplusplus
22+extern "C" {
23+#endif
24+ 
25+/**
26+ * @brief 初始化专用热点(dedap)服务模块。
27+ * @details 注册bridge事件订阅并初始化内部状态。
28+ * @return 0成功,非0失败。
29+ */
30+int32_t DedapServiceInit(void);
31+ 
32+/**
33+ * @brief 反初始化dedap服务。
34+ * @details 退订所有bridge事件并释放资源。
35+ * @return 无返回值;服务未初始化时直接返回。
36+ */
37+void DedapServiceDeinit(void);
38+ 
39+#ifdef __cplusplus
40+}
41+#endif
42+ 
43+#endif /* DEDAP_SERVICE_H */
Minterfaces/kits/common/iotc_event_params.h+6-0
@@ -62,6 +62,12 @@ typedef struct {
62 char valid[IOTC_DATE_STR_MAX_LEN + 1];62 char valid[IOTC_DATE_STR_MAX_LEN + 1];
63} IotcPskInfo;63} IotcPskInfo;
64 64 
65+/* 扫描命令类型 */
66+typedef enum {
67+ IOTC_SCAN_CMD_START = 1, /* 启动扫描 */
68+ IOTC_SCAN_CMD_STOP = 2, /* 停止扫描 */
69+} IotcScanCmd;
70+ 
65/* 通信链路类型 */71/* 通信链路类型 */
66typedef enum {72typedef enum {
67 IOTC_LINK_NONE = 0,73 IOTC_LINK_NONE = 0,