Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-os-example-mbed5-blinky by
DuerOS-Light-SDK-v1.1.0/duer-os-light/src/iot-baidu-ca/include/baidu_ca.h@47:9e361da97763, 2017-07-18 (annotated)
- Committer:
- TMBOY
- Date:
- Tue Jul 18 16:54:45 2017 +0800
- Revision:
- 47:9e361da97763
?
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| TMBOY | 47:9e361da97763 | 1 | // Copyright 2017 Baidu Inc. All Rights Reserved. |
| TMBOY | 47:9e361da97763 | 2 | // Author: Su Hao (suhao@baidu.com) |
| TMBOY | 47:9e361da97763 | 3 | // |
| TMBOY | 47:9e361da97763 | 4 | // Desc: Provide the API for external applications. |
| TMBOY | 47:9e361da97763 | 5 | |
| TMBOY | 47:9e361da97763 | 6 | #ifndef BAIDU_IOT_TINYDU_IOT_OS_SRC_IOT_BAIDU_CA_INCLUDE_BAIDU_CA_H |
| TMBOY | 47:9e361da97763 | 7 | #define BAIDU_IOT_TINYDU_IOT_OS_SRC_IOT_BAIDU_CA_INCLUDE_BAIDU_CA_H |
| TMBOY | 47:9e361da97763 | 8 | |
| TMBOY | 47:9e361da97763 | 9 | #include "baidu_ca_types.h" |
| TMBOY | 47:9e361da97763 | 10 | |
| TMBOY | 47:9e361da97763 | 11 | #ifdef __cplusplus |
| TMBOY | 47:9e361da97763 | 12 | extern "C" { |
| TMBOY | 47:9e361da97763 | 13 | #endif |
| TMBOY | 47:9e361da97763 | 14 | |
| TMBOY | 47:9e361da97763 | 15 | /* |
| TMBOY | 47:9e361da97763 | 16 | * The message codes. |
| TMBOY | 47:9e361da97763 | 17 | */ |
| TMBOY | 47:9e361da97763 | 18 | typedef enum { |
| TMBOY | 47:9e361da97763 | 19 | |
| TMBOY | 47:9e361da97763 | 20 | // Request message code |
| TMBOY | 47:9e361da97763 | 21 | BCA_MSG_REQ_GET = 1, |
| TMBOY | 47:9e361da97763 | 22 | BCA_MSG_REQ_POST = 2, |
| TMBOY | 47:9e361da97763 | 23 | BCA_MSG_REQ_PUT = 3, |
| TMBOY | 47:9e361da97763 | 24 | BCA_MSG_REQ_DELETE = 4, |
| TMBOY | 47:9e361da97763 | 25 | |
| TMBOY | 47:9e361da97763 | 26 | // Response message code |
| TMBOY | 47:9e361da97763 | 27 | BCA_MSG_RSP_CREATED = 65, // 2.01 |
| TMBOY | 47:9e361da97763 | 28 | BCA_MSG_RSP_DELETED = 66, // 2.02 |
| TMBOY | 47:9e361da97763 | 29 | BCA_MSG_RSP_VALID = 67, // 2.03 |
| TMBOY | 47:9e361da97763 | 30 | BCA_MSG_RSP_CHANGED = 68, // 2.04 |
| TMBOY | 47:9e361da97763 | 31 | BCA_MSG_RSP_CONTENT = 69, // 2.05 |
| TMBOY | 47:9e361da97763 | 32 | BCA_MSG_RSP_CONTINUE = 95, // 2.31 |
| TMBOY | 47:9e361da97763 | 33 | BCA_MSG_RSP_BAD_REQUEST = 128, // 4.00 |
| TMBOY | 47:9e361da97763 | 34 | BCA_MSG_RSP_UNAUTHORIZED = 129, // 4.01 |
| TMBOY | 47:9e361da97763 | 35 | BCA_MSG_RSP_BAD_OPTION = 130, // 4.02 |
| TMBOY | 47:9e361da97763 | 36 | BCA_MSG_RSP_FORBIDDEN = 131, // 4.03 |
| TMBOY | 47:9e361da97763 | 37 | BCA_MSG_RSP_NOT_FOUND = 132, // 4.04 |
| TMBOY | 47:9e361da97763 | 38 | BCA_MSG_RSP_METHOD_NOT_ALLOWED = 133, // 4.05 |
| TMBOY | 47:9e361da97763 | 39 | BCA_MSG_RSP_NOT_ACCEPTABLE = 134, // 4.06 |
| TMBOY | 47:9e361da97763 | 40 | BCA_MSG_RSP_REQUEST_ENTITY_INCOMPLETE = 136, // 4.08 |
| TMBOY | 47:9e361da97763 | 41 | BCA_MSG_RSP_PRECONDITION_FAILED = 140, // 4.12 |
| TMBOY | 47:9e361da97763 | 42 | BCA_MSG_RSP_REQUEST_ENTITY_TOO_LARGE = 141, // 4.13 |
| TMBOY | 47:9e361da97763 | 43 | BCA_MSG_RSP_UNSUPPORTED_CONTENT_FORMAT = 143, // 4.15 |
| TMBOY | 47:9e361da97763 | 44 | BCA_MSG_RSP_INTERNAL_SERVER_ERROR = 160, // 5.00 |
| TMBOY | 47:9e361da97763 | 45 | BCA_MSG_RSP_NOT_IMPLEMENTED = 161, // 5.01 |
| TMBOY | 47:9e361da97763 | 46 | BCA_MSG_RSP_BAD_GATEWAY = 162, // 5.02 |
| TMBOY | 47:9e361da97763 | 47 | BCA_MSG_RSP_SERVICE_UNAVAILABLE = 163, // 5.03 |
| TMBOY | 47:9e361da97763 | 48 | BCA_MSG_RSP_GATEWAY_TIMEOUT = 164, // 5.04 |
| TMBOY | 47:9e361da97763 | 49 | BCA_MSG_RSP_PROXYING_NOT_SUPPORTED = 165, // 5.05 |
| TMBOY | 47:9e361da97763 | 50 | |
| TMBOY | 47:9e361da97763 | 51 | } bca_msg_code_e; |
| TMBOY | 47:9e361da97763 | 52 | |
| TMBOY | 47:9e361da97763 | 53 | /** |
| TMBOY | 47:9e361da97763 | 54 | * CoAP Message type, used in CoAP Header |
| TMBOY | 47:9e361da97763 | 55 | */ |
| TMBOY | 47:9e361da97763 | 56 | typedef enum { |
| TMBOY | 47:9e361da97763 | 57 | BCA_MSG_TYPE_CONFIRMABLE = 0x00, // Reliable Request messages |
| TMBOY | 47:9e361da97763 | 58 | BCA_MSG_TYPE_NON_CONFIRMABLE = 0x10, // Non-reliable Request and Response messages |
| TMBOY | 47:9e361da97763 | 59 | BCA_MSG_TYPE_ACKNOWLEDGEMENT = 0x20, // Response to a Confirmable Request |
| TMBOY | 47:9e361da97763 | 60 | BCA_MSG_TYPE_RESET = 0x30 // Answer a Bad Request |
| TMBOY | 47:9e361da97763 | 61 | } bca_msg_type_e; |
| TMBOY | 47:9e361da97763 | 62 | |
| TMBOY | 47:9e361da97763 | 63 | /* |
| TMBOY | 47:9e361da97763 | 64 | * The resource operation permission |
| TMBOY | 47:9e361da97763 | 65 | */ |
| TMBOY | 47:9e361da97763 | 66 | typedef enum { |
| TMBOY | 47:9e361da97763 | 67 | BCA_RES_OP_GET = 0x01, // Get operation allowed |
| TMBOY | 47:9e361da97763 | 68 | BCA_RES_OP_PUT = 0x02, // Put operation allowed |
| TMBOY | 47:9e361da97763 | 69 | BCA_RES_OP_POST = 0x04, // Post operation allowed |
| TMBOY | 47:9e361da97763 | 70 | BCA_RES_OP_DELETE = 0x08 // Delete operation allowed |
| TMBOY | 47:9e361da97763 | 71 | } bca_resource_operation_e; |
| TMBOY | 47:9e361da97763 | 72 | |
| TMBOY | 47:9e361da97763 | 73 | /* |
| TMBOY | 47:9e361da97763 | 74 | * The resource mode |
| TMBOY | 47:9e361da97763 | 75 | */ |
| TMBOY | 47:9e361da97763 | 76 | typedef enum { |
| TMBOY | 47:9e361da97763 | 77 | BCA_RES_MODE_STATIC, // Static resources have some value that doesn't change |
| TMBOY | 47:9e361da97763 | 78 | BCA_RES_MODE_DYNAMIC, // Dynamic resources are handled in application |
| TMBOY | 47:9e361da97763 | 79 | } bca_resource_mode_e; |
| TMBOY | 47:9e361da97763 | 80 | |
| TMBOY | 47:9e361da97763 | 81 | enum _baidu_ca_protocol_enum { |
| TMBOY | 47:9e361da97763 | 82 | BCA_PROTO_TCP, |
| TMBOY | 47:9e361da97763 | 83 | BCA_PROTO_UDP |
| TMBOY | 47:9e361da97763 | 84 | }; |
| TMBOY | 47:9e361da97763 | 85 | |
| TMBOY | 47:9e361da97763 | 86 | /* |
| TMBOY | 47:9e361da97763 | 87 | * The message definition |
| TMBOY | 47:9e361da97763 | 88 | */ |
| TMBOY | 47:9e361da97763 | 89 | typedef struct _bca_message_s { |
| TMBOY | 47:9e361da97763 | 90 | bca_u16_t token_len; |
| TMBOY | 47:9e361da97763 | 91 | |
| TMBOY | 47:9e361da97763 | 92 | bca_u8_t msg_type; |
| TMBOY | 47:9e361da97763 | 93 | bca_u8_t msg_code; |
| TMBOY | 47:9e361da97763 | 94 | bca_u16_t msg_id; |
| TMBOY | 47:9e361da97763 | 95 | |
| TMBOY | 47:9e361da97763 | 96 | bca_u16_t path_len; |
| TMBOY | 47:9e361da97763 | 97 | bca_u16_t query_len; |
| TMBOY | 47:9e361da97763 | 98 | bca_u16_t payload_len; |
| TMBOY | 47:9e361da97763 | 99 | |
| TMBOY | 47:9e361da97763 | 100 | bca_u8_t* token; |
| TMBOY | 47:9e361da97763 | 101 | bca_u8_t* path; |
| TMBOY | 47:9e361da97763 | 102 | bca_u8_t* query; |
| TMBOY | 47:9e361da97763 | 103 | bca_u8_t* payload; |
| TMBOY | 47:9e361da97763 | 104 | } bca_msg_t; |
| TMBOY | 47:9e361da97763 | 105 | |
| TMBOY | 47:9e361da97763 | 106 | /* |
| TMBOY | 47:9e361da97763 | 107 | * Adapt the memory management functions. |
| TMBOY | 47:9e361da97763 | 108 | */ |
| TMBOY | 47:9e361da97763 | 109 | typedef void* (*bca_malloc_f)(bca_context context, bca_size_t size); |
| TMBOY | 47:9e361da97763 | 110 | |
| TMBOY | 47:9e361da97763 | 111 | typedef void* (*bca_realloc_f)(bca_context context, void*, bca_size_t size); |
| TMBOY | 47:9e361da97763 | 112 | |
| TMBOY | 47:9e361da97763 | 113 | typedef void (*bca_free_f)(bca_context context, void* p); |
| TMBOY | 47:9e361da97763 | 114 | |
| TMBOY | 47:9e361da97763 | 115 | /* |
| TMBOY | 47:9e361da97763 | 116 | * The network address structure |
| TMBOY | 47:9e361da97763 | 117 | */ |
| TMBOY | 47:9e361da97763 | 118 | typedef struct _bca_address_s { |
| TMBOY | 47:9e361da97763 | 119 | bca_u8_t type; // the socket type |
| TMBOY | 47:9e361da97763 | 120 | bca_u16_t port; // the host port |
| TMBOY | 47:9e361da97763 | 121 | void* host; // the host address |
| TMBOY | 47:9e361da97763 | 122 | bca_size_t host_size; // the host address length |
| TMBOY | 47:9e361da97763 | 123 | } bca_addr_t; |
| TMBOY | 47:9e361da97763 | 124 | |
| TMBOY | 47:9e361da97763 | 125 | /* |
| TMBOY | 47:9e361da97763 | 126 | * The network transfer data callbacks. |
| TMBOY | 47:9e361da97763 | 127 | * See the detail in @{link baidu_ca_transport_init} |
| TMBOY | 47:9e361da97763 | 128 | */ |
| TMBOY | 47:9e361da97763 | 129 | typedef void* bca_socket_t; |
| TMBOY | 47:9e361da97763 | 130 | |
| TMBOY | 47:9e361da97763 | 131 | typedef bca_socket_t (*bca_soc_create_f)(bca_context ctx); |
| TMBOY | 47:9e361da97763 | 132 | |
| TMBOY | 47:9e361da97763 | 133 | typedef bca_status_t (*bca_soc_connect_f)(bca_socket_t sock, |
| TMBOY | 47:9e361da97763 | 134 | const bca_addr_t* addr); |
| TMBOY | 47:9e361da97763 | 135 | |
| TMBOY | 47:9e361da97763 | 136 | typedef bca_status_t (*bca_soc_send_f)(bca_socket_t sock, |
| TMBOY | 47:9e361da97763 | 137 | const void* data, |
| TMBOY | 47:9e361da97763 | 138 | bca_size_t size, |
| TMBOY | 47:9e361da97763 | 139 | const bca_addr_t* addr); |
| TMBOY | 47:9e361da97763 | 140 | |
| TMBOY | 47:9e361da97763 | 141 | typedef bca_status_t (*bca_soc_recv_f)(bca_socket_t sock, |
| TMBOY | 47:9e361da97763 | 142 | void* data, |
| TMBOY | 47:9e361da97763 | 143 | bca_size_t size, |
| TMBOY | 47:9e361da97763 | 144 | bca_addr_t* addr); |
| TMBOY | 47:9e361da97763 | 145 | |
| TMBOY | 47:9e361da97763 | 146 | typedef bca_status_t (*bca_soc_recv_timeout_f)(bca_socket_t sock, |
| TMBOY | 47:9e361da97763 | 147 | void* data, |
| TMBOY | 47:9e361da97763 | 148 | bca_size_t size, |
| TMBOY | 47:9e361da97763 | 149 | bca_u32_t timeout, |
| TMBOY | 47:9e361da97763 | 150 | bca_addr_t* addr); |
| TMBOY | 47:9e361da97763 | 151 | |
| TMBOY | 47:9e361da97763 | 152 | typedef bca_status_t (*bca_soc_close_f)(bca_socket_t sock); |
| TMBOY | 47:9e361da97763 | 153 | |
| TMBOY | 47:9e361da97763 | 154 | typedef bca_status_t (*bca_soc_destroy_f)(bca_socket_t sock); |
| TMBOY | 47:9e361da97763 | 155 | |
| TMBOY | 47:9e361da97763 | 156 | /* |
| TMBOY | 47:9e361da97763 | 157 | * The mutex callbacks |
| TMBOY | 47:9e361da97763 | 158 | */ |
| TMBOY | 47:9e361da97763 | 159 | |
| TMBOY | 47:9e361da97763 | 160 | typedef void* bca_mutex_t; |
| TMBOY | 47:9e361da97763 | 161 | typedef bca_mutex_t (*bca_mutex_create_f)(); |
| TMBOY | 47:9e361da97763 | 162 | typedef bca_status_t (*bca_mutex_lock_f)(bca_mutex_t mtx); |
| TMBOY | 47:9e361da97763 | 163 | typedef bca_status_t (*bca_mutex_unlock_f)(bca_mutex_t mtx); |
| TMBOY | 47:9e361da97763 | 164 | typedef bca_status_t (*bca_mutex_destroy_f)(bca_mutex_t mtx); |
| TMBOY | 47:9e361da97763 | 165 | |
| TMBOY | 47:9e361da97763 | 166 | /* |
| TMBOY | 47:9e361da97763 | 167 | * The timestamp callbacks |
| TMBOY | 47:9e361da97763 | 168 | */ |
| TMBOY | 47:9e361da97763 | 169 | |
| TMBOY | 47:9e361da97763 | 170 | // Return the timestamp by milliseconds |
| TMBOY | 47:9e361da97763 | 171 | typedef bca_u32_t (*bca_timestamp_f)(); |
| TMBOY | 47:9e361da97763 | 172 | |
| TMBOY | 47:9e361da97763 | 173 | /* |
| TMBOY | 47:9e361da97763 | 174 | * The random callbacks |
| TMBOY | 47:9e361da97763 | 175 | */ |
| TMBOY | 47:9e361da97763 | 176 | |
| TMBOY | 47:9e361da97763 | 177 | // Return the random number |
| TMBOY | 47:9e361da97763 | 178 | typedef bca_s32_t (*bca_random_f)(); |
| TMBOY | 47:9e361da97763 | 179 | |
| TMBOY | 47:9e361da97763 | 180 | /* |
| TMBOY | 47:9e361da97763 | 181 | * The handler |
| TMBOY | 47:9e361da97763 | 182 | */ |
| TMBOY | 47:9e361da97763 | 183 | typedef void* bca_handler; |
| TMBOY | 47:9e361da97763 | 184 | |
| TMBOY | 47:9e361da97763 | 185 | /* |
| TMBOY | 47:9e361da97763 | 186 | * The status notification to user. |
| TMBOY | 47:9e361da97763 | 187 | */ |
| TMBOY | 47:9e361da97763 | 188 | |
| TMBOY | 47:9e361da97763 | 189 | typedef bca_status_t (*bca_notify_f)(bca_context ctx, |
| TMBOY | 47:9e361da97763 | 190 | bca_msg_t* msg, |
| TMBOY | 47:9e361da97763 | 191 | bca_addr_t* addr); |
| TMBOY | 47:9e361da97763 | 192 | |
| TMBOY | 47:9e361da97763 | 193 | /* |
| TMBOY | 47:9e361da97763 | 194 | * The debug output |
| TMBOY | 47:9e361da97763 | 195 | */ |
| TMBOY | 47:9e361da97763 | 196 | typedef void (*bca_debug_f)(bca_context ctx, |
| TMBOY | 47:9e361da97763 | 197 | bca_u32_t level, |
| TMBOY | 47:9e361da97763 | 198 | const char* file, |
| TMBOY | 47:9e361da97763 | 199 | bca_u32_t line, |
| TMBOY | 47:9e361da97763 | 200 | const char* fmt); |
| TMBOY | 47:9e361da97763 | 201 | |
| TMBOY | 47:9e361da97763 | 202 | /* |
| TMBOY | 47:9e361da97763 | 203 | * The resource for user |
| TMBOY | 47:9e361da97763 | 204 | */ |
| TMBOY | 47:9e361da97763 | 205 | typedef struct _bca_resource_s { |
| TMBOY | 47:9e361da97763 | 206 | bca_u8_t mode: 2; // the resource mode, SEE in ${link bca_resource_mode_e} |
| TMBOY | 47:9e361da97763 | 207 | bca_u8_t allowed: 6; // operation permission, SEE in ${link bca_resource_operation_e} |
| TMBOY | 47:9e361da97763 | 208 | char* path; // the resource path identify |
| TMBOY | 47:9e361da97763 | 209 | |
| TMBOY | 47:9e361da97763 | 210 | union { |
| TMBOY | 47:9e361da97763 | 211 | bca_notify_f f_res; // dynamic resource handle function, NULL if static |
| TMBOY | 47:9e361da97763 | 212 | struct { |
| TMBOY | 47:9e361da97763 | 213 | void* data; // static resource value data, NULL if dynamic |
| TMBOY | 47:9e361da97763 | 214 | bca_size_t size; // static resource size |
| TMBOY | 47:9e361da97763 | 215 | } s_res; |
| TMBOY | 47:9e361da97763 | 216 | } res; |
| TMBOY | 47:9e361da97763 | 217 | } bca_res_t; |
| TMBOY | 47:9e361da97763 | 218 | |
| TMBOY | 47:9e361da97763 | 219 | /* |
| TMBOY | 47:9e361da97763 | 220 | * Set the debug output |
| TMBOY | 47:9e361da97763 | 221 | * |
| TMBOY | 47:9e361da97763 | 222 | * @Param ctx, bca_context, the debug context for user |
| TMBOY | 47:9e361da97763 | 223 | * @Param f_debug, bca_debug_f, the debug output function |
| TMBOY | 47:9e361da97763 | 224 | */ |
| TMBOY | 47:9e361da97763 | 225 | BCA_EXT void baidu_ca_debug_init(bca_context ctx, bca_debug_f f_debug); |
| TMBOY | 47:9e361da97763 | 226 | |
| TMBOY | 47:9e361da97763 | 227 | /* |
| TMBOY | 47:9e361da97763 | 228 | * Set the memory management functions. |
| TMBOY | 47:9e361da97763 | 229 | * |
| TMBOY | 47:9e361da97763 | 230 | * @Param ctx, bca_context, in, the memory context for user |
| TMBOY | 47:9e361da97763 | 231 | * @Param f_malloc, bca_malloc_f, the memory alloc function for user |
| TMBOY | 47:9e361da97763 | 232 | * @Param f_realloc, bca_realloc_f, the memory realloc function for user, |
| TMBOY | 47:9e361da97763 | 233 | * @Param f_free, bca_free_f, the memory free function for user |
| TMBOY | 47:9e361da97763 | 234 | * |
| TMBOY | 47:9e361da97763 | 235 | * If f_malloc or f_free set to NULL, we will use default libc instead all of it; |
| TMBOY | 47:9e361da97763 | 236 | * If only f_realloc set to NULL, we will realized it by f_malloc and f_free. |
| TMBOY | 47:9e361da97763 | 237 | */ |
| TMBOY | 47:9e361da97763 | 238 | BCA_EXT void baidu_ca_memory_init(bca_context context, |
| TMBOY | 47:9e361da97763 | 239 | bca_malloc_f f_malloc, |
| TMBOY | 47:9e361da97763 | 240 | bca_realloc_f f_realloc, |
| TMBOY | 47:9e361da97763 | 241 | bca_free_f f_free); |
| TMBOY | 47:9e361da97763 | 242 | |
| TMBOY | 47:9e361da97763 | 243 | /* |
| TMBOY | 47:9e361da97763 | 244 | * Set network input/ouput function |
| TMBOY | 47:9e361da97763 | 245 | * |
| TMBOY | 47:9e361da97763 | 246 | * @Param f_create, in, the function create socket context |
| TMBOY | 47:9e361da97763 | 247 | * @Param f_conn, in, the function connect socket to host |
| TMBOY | 47:9e361da97763 | 248 | * @Param f_send, in, the function send message |
| TMBOY | 47:9e361da97763 | 249 | * @Param f_recv, in, the function receive message |
| TMBOY | 47:9e361da97763 | 250 | * @Param f_recv_timeout, in, the function receive message with timeout |
| TMBOY | 47:9e361da97763 | 251 | * @Param f_close, in, the function close the socket |
| TMBOY | 47:9e361da97763 | 252 | * @Param f_destroy, in, the function destroy the socket context |
| TMBOY | 47:9e361da97763 | 253 | */ |
| TMBOY | 47:9e361da97763 | 254 | BCA_EXT void baidu_ca_transport_init(bca_soc_create_f f_create, |
| TMBOY | 47:9e361da97763 | 255 | bca_soc_connect_f f_conn, |
| TMBOY | 47:9e361da97763 | 256 | bca_soc_send_f f_send, |
| TMBOY | 47:9e361da97763 | 257 | bca_soc_recv_f f_recv, |
| TMBOY | 47:9e361da97763 | 258 | bca_soc_recv_timeout_f f_recv_timeout, |
| TMBOY | 47:9e361da97763 | 259 | bca_soc_close_f f_close, |
| TMBOY | 47:9e361da97763 | 260 | bca_soc_destroy_f f_destroy); |
| TMBOY | 47:9e361da97763 | 261 | |
| TMBOY | 47:9e361da97763 | 262 | /* |
| TMBOY | 47:9e361da97763 | 263 | * Initial the mutex callbacks for Baidu CA |
| TMBOY | 47:9e361da97763 | 264 | * |
| TMBOY | 47:9e361da97763 | 265 | * @Param f_create, in, the function create mutex context |
| TMBOY | 47:9e361da97763 | 266 | * @Param f_lock, in, the function mutex lock |
| TMBOY | 47:9e361da97763 | 267 | * @Param f_unlock, in, the function mutex unlock |
| TMBOY | 47:9e361da97763 | 268 | * @Param f_destroy, in, the function destroy mutex context |
| TMBOY | 47:9e361da97763 | 269 | */ |
| TMBOY | 47:9e361da97763 | 270 | BCA_EXT void baidu_ca_mutex_init(bca_mutex_create_f f_create, |
| TMBOY | 47:9e361da97763 | 271 | bca_mutex_lock_f f_lock, |
| TMBOY | 47:9e361da97763 | 272 | bca_mutex_unlock_f f_unlock, |
| TMBOY | 47:9e361da97763 | 273 | bca_mutex_destroy_f f_destroy); |
| TMBOY | 47:9e361da97763 | 274 | |
| TMBOY | 47:9e361da97763 | 275 | /* |
| TMBOY | 47:9e361da97763 | 276 | * Initial the timestamp callbacks for Baidu CA |
| TMBOY | 47:9e361da97763 | 277 | * |
| TMBOY | 47:9e361da97763 | 278 | * @Param f_timestamp, in, the function obtain the timestamp |
| TMBOY | 47:9e361da97763 | 279 | */ |
| TMBOY | 47:9e361da97763 | 280 | BCA_EXT void baidu_ca_timestamp_init(bca_timestamp_f f_timestamp); |
| TMBOY | 47:9e361da97763 | 281 | |
| TMBOY | 47:9e361da97763 | 282 | /* |
| TMBOY | 47:9e361da97763 | 283 | * Initial the random callbacks for Baidu CA |
| TMBOY | 47:9e361da97763 | 284 | * |
| TMBOY | 47:9e361da97763 | 285 | * @Param bca_random_f, in, the function random generator function |
| TMBOY | 47:9e361da97763 | 286 | */ |
| TMBOY | 47:9e361da97763 | 287 | BCA_EXT void baidu_ca_random_init(bca_random_f f_random); |
| TMBOY | 47:9e361da97763 | 288 | |
| TMBOY | 47:9e361da97763 | 289 | /* |
| TMBOY | 47:9e361da97763 | 290 | * Acquire the handler |
| TMBOY | 47:9e361da97763 | 291 | * |
| TMBOY | 47:9e361da97763 | 292 | * @Param data, in, the configuration data |
| TMBOY | 47:9e361da97763 | 293 | * @Param size, in, the data size |
| TMBOY | 47:9e361da97763 | 294 | * @Param soc_ctx, in socket context |
| TMBOY | 47:9e361da97763 | 295 | * @Return bca_handler, the global context handler |
| TMBOY | 47:9e361da97763 | 296 | */ |
| TMBOY | 47:9e361da97763 | 297 | BCA_EXT bca_handler baidu_ca_acquire(const void* data, |
| TMBOY | 47:9e361da97763 | 298 | bca_size_t size, |
| TMBOY | 47:9e361da97763 | 299 | bca_context soc_ctx); |
| TMBOY | 47:9e361da97763 | 300 | |
| TMBOY | 47:9e361da97763 | 301 | /* |
| TMBOY | 47:9e361da97763 | 302 | * Acquire the resources for response |
| TMBOY | 47:9e361da97763 | 303 | * |
| TMBOY | 47:9e361da97763 | 304 | * @Param hdlr, in, the handler will be operated |
| TMBOY | 47:9e361da97763 | 305 | * @Param list_res, in, resource list |
| TMBOY | 47:9e361da97763 | 306 | * @Param list_res_size, in resource list length |
| TMBOY | 47:9e361da97763 | 307 | * @Return bca_status_t, in, the operation result |
| TMBOY | 47:9e361da97763 | 308 | */ |
| TMBOY | 47:9e361da97763 | 309 | BCA_EXT bca_status_t baidu_ca_add_resources(bca_handler hdlr, |
| TMBOY | 47:9e361da97763 | 310 | const bca_res_t list_res[], |
| TMBOY | 47:9e361da97763 | 311 | bca_size_t list_res_size); |
| TMBOY | 47:9e361da97763 | 312 | |
| TMBOY | 47:9e361da97763 | 313 | /* |
| TMBOY | 47:9e361da97763 | 314 | * Start run the Baidu CA, prepare the environment. |
| TMBOY | 47:9e361da97763 | 315 | * |
| TMBOY | 47:9e361da97763 | 316 | * @Param hdlr, in, the handler will be operated |
| TMBOY | 47:9e361da97763 | 317 | * @Return bca_status_t, in, the operation result |
| TMBOY | 47:9e361da97763 | 318 | */ |
| TMBOY | 47:9e361da97763 | 319 | BCA_EXT bca_status_t baidu_ca_start(bca_handler hdlr); |
| TMBOY | 47:9e361da97763 | 320 | |
| TMBOY | 47:9e361da97763 | 321 | /* |
| TMBOY | 47:9e361da97763 | 322 | * Set the Reporter report response callback. |
| TMBOY | 47:9e361da97763 | 323 | * |
| TMBOY | 47:9e361da97763 | 324 | * @Param hdlr, in, the handler will be operated |
| TMBOY | 47:9e361da97763 | 325 | * @Param f_response, in, the callback for notify user the report data response |
| TMBOY | 47:9e361da97763 | 326 | * @Return bca_status_t, in, the operation result |
| TMBOY | 47:9e361da97763 | 327 | */ |
| TMBOY | 47:9e361da97763 | 328 | BCA_EXT bca_status_t baidu_ca_report_set_response_callback(bca_handler hdlr, |
| TMBOY | 47:9e361da97763 | 329 | bca_notify_f f_response, |
| TMBOY | 47:9e361da97763 | 330 | bca_context context); |
| TMBOY | 47:9e361da97763 | 331 | |
| TMBOY | 47:9e361da97763 | 332 | /* |
| TMBOY | 47:9e361da97763 | 333 | * Build the message body that will be reported. |
| TMBOY | 47:9e361da97763 | 334 | * |
| TMBOY | 47:9e361da97763 | 335 | * @Param hdlr, in, the handler will be operated |
| TMBOY | 47:9e361da97763 | 336 | * @Param data, in, the message report data |
| TMBOY | 47:9e361da97763 | 337 | * @Param size, in, the data size |
| TMBOY | 47:9e361da97763 | 338 | * @Param confirmable, in, the report data QoS |
| TMBOY | 47:9e361da97763 | 339 | * @Return bca_msg_t *, in, the generated message body, |
| TMBOY | 47:9e361da97763 | 340 | * it SHOULD be released by ${link baidu_ca_release_message} |
| TMBOY | 47:9e361da97763 | 341 | */ |
| TMBOY | 47:9e361da97763 | 342 | BCA_EXT bca_msg_t* baidu_ca_build_report_message(bca_handler hdlr, |
| TMBOY | 47:9e361da97763 | 343 | bca_bool confirmable); |
| TMBOY | 47:9e361da97763 | 344 | |
| TMBOY | 47:9e361da97763 | 345 | /* |
| TMBOY | 47:9e361da97763 | 346 | * Build the message body that will be responsed to remote. |
| TMBOY | 47:9e361da97763 | 347 | * |
| TMBOY | 47:9e361da97763 | 348 | * @Param hdlr, in, the handler will be operated |
| TMBOY | 47:9e361da97763 | 349 | * @Param msg, in, the message that remote requested |
| TMBOY | 47:9e361da97763 | 350 | * @Param msg_code, out, the response message code |
| TMBOY | 47:9e361da97763 | 351 | * @Return bca_msg_t *, in, the generated message body, |
| TMBOY | 47:9e361da97763 | 352 | * it SHOULD be released by ${link baidu_ca_release_message} |
| TMBOY | 47:9e361da97763 | 353 | */ |
| TMBOY | 47:9e361da97763 | 354 | BCA_EXT bca_msg_t* baidu_ca_build_response_message(bca_handler hdlr, |
| TMBOY | 47:9e361da97763 | 355 | const bca_msg_t* msg, |
| TMBOY | 47:9e361da97763 | 356 | bca_u8_t msg_code); |
| TMBOY | 47:9e361da97763 | 357 | |
| TMBOY | 47:9e361da97763 | 358 | /* |
| TMBOY | 47:9e361da97763 | 359 | * Release the message that generated by baidu_ca_build_XXXX_message. |
| TMBOY | 47:9e361da97763 | 360 | * |
| TMBOY | 47:9e361da97763 | 361 | * @Param hdlr, in, the handler will be operated |
| TMBOY | 47:9e361da97763 | 362 | * @Param msg, in, the message that remote requested |
| TMBOY | 47:9e361da97763 | 363 | */ |
| TMBOY | 47:9e361da97763 | 364 | BCA_EXT void baidu_ca_release_message(bca_handler hdlr, bca_msg_t* msg); |
| TMBOY | 47:9e361da97763 | 365 | |
| TMBOY | 47:9e361da97763 | 366 | /* |
| TMBOY | 47:9e361da97763 | 367 | * Send the message |
| TMBOY | 47:9e361da97763 | 368 | * |
| TMBOY | 47:9e361da97763 | 369 | * @Param hdlr, in, the handler will be operated |
| TMBOY | 47:9e361da97763 | 370 | * @Param msg, in, the msg will be sent |
| TMBOY | 47:9e361da97763 | 371 | * @Param addr, in, the remote addr |
| TMBOY | 47:9e361da97763 | 372 | * @Return bca_status_t, in, the operation result |
| TMBOY | 47:9e361da97763 | 373 | */ |
| TMBOY | 47:9e361da97763 | 374 | BCA_EXT bca_status_t baidu_ca_send_data(bca_handler hdlr, |
| TMBOY | 47:9e361da97763 | 375 | const bca_msg_t* msg, |
| TMBOY | 47:9e361da97763 | 376 | const bca_addr_t* addr); |
| TMBOY | 47:9e361da97763 | 377 | |
| TMBOY | 47:9e361da97763 | 378 | /* |
| TMBOY | 47:9e361da97763 | 379 | * When the message data has ready to be received |
| TMBOY | 47:9e361da97763 | 380 | * |
| TMBOY | 47:9e361da97763 | 381 | * @Param hdlr, in, the handler will be operated |
| TMBOY | 47:9e361da97763 | 382 | * @Param addr, in, the remote addr |
| TMBOY | 47:9e361da97763 | 383 | * @Return bca_status_t, in, the operation result |
| TMBOY | 47:9e361da97763 | 384 | */ |
| TMBOY | 47:9e361da97763 | 385 | BCA_EXT bca_status_t baidu_ca_data_available(bca_handler hdlr, |
| TMBOY | 47:9e361da97763 | 386 | const bca_addr_t* addr); |
| TMBOY | 47:9e361da97763 | 387 | |
| TMBOY | 47:9e361da97763 | 388 | /* |
| TMBOY | 47:9e361da97763 | 389 | * Execute the cached CoAP data, such as blockwise, resending... |
| TMBOY | 47:9e361da97763 | 390 | * |
| TMBOY | 47:9e361da97763 | 391 | * @Param hdlr, in, the handler will be operated |
| TMBOY | 47:9e361da97763 | 392 | * @Return bca_status_t, in, the operation result |
| TMBOY | 47:9e361da97763 | 393 | */ |
| TMBOY | 47:9e361da97763 | 394 | BCA_EXT bca_status_t baidu_ca_exec(bca_handler hdlr); |
| TMBOY | 47:9e361da97763 | 395 | |
| TMBOY | 47:9e361da97763 | 396 | /* |
| TMBOY | 47:9e361da97763 | 397 | * Stop the Baidu CA. |
| TMBOY | 47:9e361da97763 | 398 | * |
| TMBOY | 47:9e361da97763 | 399 | * @Param hdlr, in, the handler will be operated |
| TMBOY | 47:9e361da97763 | 400 | * @Return bca_status_t, in, the operation result |
| TMBOY | 47:9e361da97763 | 401 | */ |
| TMBOY | 47:9e361da97763 | 402 | BCA_EXT bca_status_t baidu_ca_stop(bca_handler hdlr); |
| TMBOY | 47:9e361da97763 | 403 | |
| TMBOY | 47:9e361da97763 | 404 | /* |
| TMBOY | 47:9e361da97763 | 405 | * Release the handler |
| TMBOY | 47:9e361da97763 | 406 | * |
| TMBOY | 47:9e361da97763 | 407 | * @Param hdlr, in, the handler will be operated |
| TMBOY | 47:9e361da97763 | 408 | * @Return bca_status_t, in, the operation result |
| TMBOY | 47:9e361da97763 | 409 | */ |
| TMBOY | 47:9e361da97763 | 410 | BCA_EXT bca_status_t baidu_ca_release(bca_handler hdlr); |
| TMBOY | 47:9e361da97763 | 411 | |
| TMBOY | 47:9e361da97763 | 412 | #ifdef __cplusplus |
| TMBOY | 47:9e361da97763 | 413 | } |
| TMBOY | 47:9e361da97763 | 414 | #endif |
| TMBOY | 47:9e361da97763 | 415 | |
| TMBOY | 47:9e361da97763 | 416 | #endif // BAIDU_IOT_TINYDU_IOT_OS_SRC_IOT_BAIDU_CA_INCLUDE_BAIDU_CA_H |
