coap_observe.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /**
  2. * Copyright (c) 2014 - 2019, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #include <string.h>
  41. #include "coap_observe_api.h"
  42. #include "coap_observe.h"
  43. #include "nrf_error.h"
  44. #include "iot_common.h"
  45. #include "sdk_common.h"
  46. #include "sdk_config.h"
  47. #include "coap.h"
  48. #if IOT_COAP_CONFIG_LOG_ENABLED
  49. #define NRF_LOG_MODULE_NAME coapobs
  50. #define NRF_LOG_LEVEL IOT_COAP_CONFIG_LOG_LEVEL
  51. #define NRF_LOG_INFO_COLOR IOT_COAP_CONFIG_INFO_COLOR
  52. #define NRF_LOG_DEBUG_COLOR IOT_COAP_CONFIG_DEBUG_COLOR
  53. #include "nrf_log.h"
  54. NRF_LOG_MODULE_REGISTER();
  55. #define COAP_TRC NRF_LOG_DEBUG /**< Used for getting trace of execution in the module. */
  56. #define COAP_ERR NRF_LOG_ERROR /**< Used for logging errors in the module. */
  57. #define COAP_DUMP NRF_LOG_HEXDUMP_DEBUG /**< Used for dumping octet information to get details of bond information etc. */
  58. #define COAP_ENTRY() COAP_TRC(">> %s", __func__)
  59. #define COAP_EXIT() COAP_TRC("<< %s", __func__)
  60. #else // IOT_COAP_CONFIG_LOG_ENABLED
  61. #define COAP_TRC(...) /**< Disables traces. */
  62. #define COAP_DUMP(...) /**< Disables dumping of octet streams. */
  63. #define COAP_ERR(...) /**< Disables error logs. */
  64. #define COAP_ENTRY(...)
  65. #define COAP_EXIT(...)
  66. #endif // IOT_COAP_CONFIG_LOG_ENABLED
  67. #if (COAP_ENABLE_OBSERVE_SERVER == 1)
  68. static coap_observer_t m_observers[COAP_OBSERVE_MAX_NUM_OBSERVERS];
  69. static void observe_server_init(void)
  70. {
  71. COAP_ENTRY();
  72. // Loop through the observer array and clear the memory.
  73. for (uint32_t i = 0; i < COAP_OBSERVE_MAX_NUM_OBSERVERS; i++)
  74. {
  75. memset(&m_observers[i], 0, sizeof(coap_observer_t));
  76. }
  77. COAP_EXIT();
  78. }
  79. uint32_t internal_coap_observe_server_register(uint32_t * p_handle, coap_observer_t * p_observer)
  80. {
  81. COAP_ENTRY();
  82. NULL_PARAM_CHECK(p_handle);
  83. NULL_PARAM_CHECK(p_observer);
  84. NULL_PARAM_MEMBER_CHECK(p_observer->p_resource_of_interest);
  85. // Check if there is already a registered observer in the list to be reused.
  86. uint32_t handle;
  87. uint32_t err_code = coap_observe_server_search(&handle,
  88. &p_observer->remote,
  89. p_observer->p_resource_of_interest);
  90. if (err_code == NRF_SUCCESS)
  91. {
  92. memcpy(&m_observers[handle], p_observer, sizeof(coap_observer_t));
  93. *p_handle = handle;
  94. return NRF_SUCCESS;
  95. }
  96. // Check if there is an available spot in the observer list.
  97. for (uint32_t i = 0; i < COAP_OBSERVE_MAX_NUM_OBSERVERS; i++)
  98. {
  99. if (m_observers[i].p_resource_of_interest == NULL)
  100. {
  101. memcpy(&m_observers[i], p_observer, sizeof(coap_observer_t));
  102. *p_handle = i;
  103. return NRF_SUCCESS;
  104. }
  105. }
  106. COAP_EXIT();
  107. return (NRF_ERROR_NO_MEM | IOT_COAP_ERR_BASE);
  108. }
  109. uint32_t internal_coap_observe_server_unregister(uint32_t handle)
  110. {
  111. COAP_ENTRY();
  112. if (handle >= COAP_OBSERVE_MAX_NUM_OBSERVERS)
  113. {
  114. return (NRF_ERROR_NOT_FOUND | IOT_COAP_ERR_BASE);
  115. }
  116. if (m_observers[handle].p_resource_of_interest == NULL)
  117. {
  118. return (NRF_ERROR_NOT_FOUND | IOT_COAP_ERR_BASE);
  119. }
  120. m_observers[handle].p_resource_of_interest = NULL;
  121. COAP_EXIT();
  122. return NRF_SUCCESS;
  123. }
  124. uint32_t internal_coap_observe_server_search(uint32_t * p_handle,
  125. coap_remote_t * p_observer_addr,
  126. coap_resource_t * p_resource)
  127. {
  128. NULL_PARAM_CHECK(p_handle);
  129. NULL_PARAM_CHECK(p_observer_addr);
  130. NULL_PARAM_CHECK(p_resource);
  131. for (uint32_t i = 0; i < COAP_OBSERVE_MAX_NUM_OBSERVERS; i++)
  132. {
  133. if (m_observers[i].p_resource_of_interest == p_resource)
  134. {
  135. if (m_observers[i].remote.port_number == p_observer_addr->port_number)
  136. {
  137. if (memcmp(p_observer_addr->addr, m_observers[i].remote.addr, sizeof(p_observer_addr->addr)) == 0)
  138. {
  139. *p_handle = i;
  140. return NRF_SUCCESS;
  141. }
  142. }
  143. }
  144. }
  145. return (NRF_ERROR_NOT_FOUND | IOT_COAP_ERR_BASE);
  146. }
  147. uint32_t internal_coap_observe_server_next_get(coap_observer_t ** pp_observer,
  148. coap_observer_t * p_observer,
  149. coap_resource_t * p_resource)
  150. {
  151. NULL_PARAM_CHECK(p_resource);
  152. NULL_PARAM_CHECK(pp_observer);
  153. if (p_observer == NULL)
  154. {
  155. for (uint32_t i = 0; i < COAP_OBSERVE_MAX_NUM_OBSERVERS; i++)
  156. {
  157. if (m_observers[i].p_resource_of_interest == p_resource)
  158. {
  159. (*pp_observer) = &m_observers[i];
  160. return NRF_SUCCESS;
  161. }
  162. }
  163. }
  164. else
  165. {
  166. uint32_t index_to_previous = (uint8_t)(((uint32_t)p_observer - (uint32_t)m_observers) / (uint32_t)sizeof(coap_observer_t));
  167. for (uint32_t i = index_to_previous + 1; i < COAP_OBSERVE_MAX_NUM_OBSERVERS; i++)
  168. {
  169. if (m_observers[i].p_resource_of_interest == p_resource)
  170. {
  171. (*pp_observer) = &m_observers[i];
  172. return NRF_SUCCESS;
  173. }
  174. }
  175. }
  176. (*pp_observer) = NULL;
  177. return (NRF_ERROR_NOT_FOUND | IOT_COAP_ERR_BASE);
  178. }
  179. uint32_t internal_coap_observe_server_get(uint32_t handle, coap_observer_t ** pp_observer)
  180. {
  181. NULL_PARAM_CHECK(pp_observer);
  182. if (handle >= COAP_OBSERVE_MAX_NUM_OBSERVERS)
  183. {
  184. return (NRF_ERROR_NOT_FOUND | IOT_COAP_ERR_BASE);
  185. }
  186. if (m_observers[handle].p_resource_of_interest == NULL)
  187. {
  188. return (NRF_ERROR_NOT_FOUND | IOT_COAP_ERR_BASE);
  189. }
  190. *pp_observer = &m_observers[handle];
  191. return NRF_SUCCESS;
  192. }
  193. #else
  194. #define observe_server_init(...)
  195. #endif
  196. #if (COAP_ENABLE_OBSERVE_CLIENT == 1)
  197. static coap_observable_t m_observables[COAP_OBSERVE_MAX_NUM_OBSERVABLES];
  198. static void observe_client_init(void)
  199. {
  200. // Loop through the observable array and clear the memory.
  201. for (uint32_t i = 0; i < COAP_OBSERVE_MAX_NUM_OBSERVABLES; i++)
  202. {
  203. memset(&m_observables[i], 0, sizeof(coap_observable_t));
  204. }
  205. }
  206. uint32_t internal_coap_observe_client_register(uint32_t * p_handle,
  207. coap_observable_t * p_observable)
  208. {
  209. COAP_ENTRY();
  210. NULL_PARAM_CHECK(p_handle);
  211. NULL_PARAM_CHECK(p_observable);
  212. NULL_PARAM_MEMBER_CHECK(p_observable->response_callback);
  213. // Check if there is an available spot in the observer list.
  214. for (uint32_t i = 0; i < COAP_OBSERVE_MAX_NUM_OBSERVABLES; i++)
  215. {
  216. if (m_observables[i].response_callback == NULL)
  217. {
  218. memcpy(&m_observables[i], p_observable, sizeof(coap_observable_t));
  219. *p_handle = i;
  220. return NRF_SUCCESS;
  221. }
  222. }
  223. COAP_EXIT();
  224. return (NRF_ERROR_NO_MEM | IOT_COAP_ERR_BASE);
  225. }
  226. uint32_t internal_coap_observe_client_unregister(uint32_t handle)
  227. {
  228. COAP_ENTRY();
  229. if (handle >= COAP_OBSERVE_MAX_NUM_OBSERVABLES)
  230. {
  231. return (NRF_ERROR_NOT_FOUND | IOT_COAP_ERR_BASE);
  232. }
  233. if (m_observables[handle].response_callback == NULL)
  234. {
  235. return (NRF_ERROR_NOT_FOUND | IOT_COAP_ERR_BASE);
  236. }
  237. m_observables[handle].response_callback = NULL;
  238. COAP_EXIT();
  239. return NRF_SUCCESS;
  240. }
  241. uint32_t internal_coap_observe_client_search(uint32_t * p_handle, uint8_t * p_token, uint16_t token_len)
  242. {
  243. NULL_PARAM_CHECK(p_handle);
  244. NULL_PARAM_CHECK(p_token);
  245. for (uint32_t i = 0; i < COAP_OBSERVE_MAX_NUM_OBSERVABLES; i++)
  246. {
  247. if ((m_observables[i].response_callback != NULL) &&
  248. (0 != m_observables[i].token_len) &&
  249. (memcmp(m_observables[i].token, p_token, m_observables[i].token_len) == 0))
  250. {
  251. *p_handle = i;
  252. return NRF_SUCCESS;
  253. }
  254. }
  255. return (NRF_ERROR_NOT_FOUND | IOT_COAP_ERR_BASE);
  256. }
  257. uint32_t internal_coap_observe_client_get(uint32_t handle, coap_observable_t ** pp_observable)
  258. {
  259. NULL_PARAM_CHECK(pp_observable);
  260. if (handle >= COAP_OBSERVE_MAX_NUM_OBSERVABLES)
  261. {
  262. return (NRF_ERROR_NOT_FOUND | IOT_COAP_ERR_BASE);
  263. }
  264. if (m_observables[handle].response_callback == NULL)
  265. {
  266. return (NRF_ERROR_NOT_FOUND | IOT_COAP_ERR_BASE);
  267. }
  268. *pp_observable = &m_observables[handle];
  269. return NRF_SUCCESS;
  270. }
  271. uint32_t internal_coap_observe_client_next_get(coap_observable_t ** pp_observable,
  272. uint32_t * p_handle,
  273. coap_observable_t * p_observable)
  274. {
  275. NULL_PARAM_CHECK(pp_observable);
  276. if (p_observable == NULL)
  277. {
  278. for (uint32_t i = 0; i < COAP_OBSERVE_MAX_NUM_OBSERVABLES; i++)
  279. {
  280. if (m_observables[i].response_callback != NULL)
  281. {
  282. (*pp_observable) = &m_observables[i];
  283. (*p_handle) = i;
  284. return NRF_SUCCESS;
  285. }
  286. }
  287. }
  288. else
  289. {
  290. uint32_t index_to_previous = (uint8_t)(((uint32_t)p_observable - (uint32_t)m_observables) / (uint32_t)sizeof(coap_observable_t));
  291. for (uint32_t i = index_to_previous + 1; i < COAP_OBSERVE_MAX_NUM_OBSERVABLES; i++)
  292. {
  293. if (m_observables[i].response_callback != NULL)
  294. {
  295. (*pp_observable) = &m_observables[i];
  296. (*p_handle) = i;
  297. return NRF_SUCCESS;
  298. }
  299. }
  300. }
  301. (*pp_observable) = NULL;
  302. COAP_MUTEX_UNLOCK();
  303. return (NRF_ERROR_NOT_FOUND | IOT_COAP_ERR_BASE);
  304. }
  305. static uint32_t observe_opt_present(coap_message_t * p_message)
  306. {
  307. uint8_t index;
  308. for (index = 0; index < p_message->options_count; index++)
  309. {
  310. if (p_message->options[index].number == COAP_OPT_OBSERVE)
  311. {
  312. return NRF_SUCCESS;
  313. }
  314. }
  315. return NRF_ERROR_NOT_FOUND;
  316. }
  317. static void set_max_age(coap_observable_t * observable, coap_message_t * p_response)
  318. {
  319. uint8_t index;
  320. for (index = 0; index < p_response->options_count; index++)
  321. {
  322. if (p_response->options[index].number == COAP_OPT_MAX_AGE)
  323. {
  324. uint32_t max_age;
  325. observable->max_age = coap_opt_uint_decode(&max_age,
  326. p_response->options[index].length,
  327. p_response->options[index].p_data);
  328. observable->max_age = max_age;
  329. return;
  330. }
  331. }
  332. // Max-Age option is not present, set default value to 60.
  333. observable->max_age = 60;
  334. }
  335. void coap_observe_client_send_handle(coap_message_t * p_request)
  336. {
  337. COAP_ENTRY();
  338. if (p_request->header.code == COAP_CODE_GET)
  339. {
  340. uint32_t observe_option = 0;
  341. if (observe_opt_present(p_request) == NRF_SUCCESS)
  342. {
  343. // Locate option and check value.
  344. uint8_t index;
  345. for (index = 0; index < p_request->options_count; index++)
  346. {
  347. if (p_request->options[index].number == COAP_OPT_OBSERVE)
  348. {
  349. uint32_t err_code = coap_opt_uint_decode(&observe_option,
  350. p_request->options[index].length,
  351. p_request->options[index].p_data);
  352. if (err_code != NRF_SUCCESS)
  353. {
  354. return;
  355. }
  356. break;
  357. }
  358. }
  359. }
  360. if (observe_option == 1)
  361. {
  362. // Un-register observable instance.
  363. uint32_t handle;
  364. uint32_t err_code = internal_coap_observe_client_search(&handle,
  365. p_request->token,
  366. p_request->header.token_len);
  367. if (err_code == NRF_SUCCESS)
  368. {
  369. (void)internal_coap_observe_client_unregister(handle);
  370. COAP_TRC("OBSERVE=1 in request, client_unregister handle: %i", handle);
  371. }
  372. }
  373. }
  374. COAP_EXIT();
  375. }
  376. void coap_observe_client_response_handle(coap_message_t * p_response, coap_queue_item_t * p_item)
  377. {
  378. COAP_ENTRY();
  379. if (observe_opt_present(p_response) == NRF_SUCCESS)
  380. {
  381. if (p_item == NULL)
  382. {
  383. // Search for the token in the observable list.
  384. uint32_t handle;
  385. uint32_t err_code = internal_coap_observe_client_search(&handle, p_response->token, p_response->header.token_len);
  386. if (err_code == NRF_SUCCESS)
  387. {
  388. // Fetch the observable.
  389. coap_observable_t * p_observable;
  390. err_code = internal_coap_observe_client_get(handle, &p_observable);
  391. if (err_code == NRF_SUCCESS)
  392. {
  393. // Update max-age to the newly recieved message.
  394. set_max_age(p_observable, p_response);
  395. COAP_MUTEX_UNLOCK();
  396. // Callback to the application.
  397. p_observable->response_callback(NRF_SUCCESS, NULL, p_response);
  398. COAP_MUTEX_LOCK();
  399. COAP_TRC("Notification received on handle: %i", handle);
  400. #ifdef COAP_AUTOMODE
  401. if (p_response->header.type == COAP_TYPE_CON)
  402. {
  403. // Reply an ACK upon CON message.
  404. }
  405. else if (p_response->header.type == COAP_TYPE_RST)
  406. {
  407. // Remove observable from list.
  408. }
  409. #endif
  410. }
  411. else
  412. {
  413. #ifdef COAP_AUTOMODE
  414. if (p_response->header.type == COAP_TYPE_CON)
  415. {
  416. // Reply reset upon CON message when observer is not located.
  417. }
  418. #endif
  419. }
  420. }
  421. else
  422. {
  423. // Send RST message back to server to indicate there is no one listening.
  424. }
  425. }
  426. else // p_item set.
  427. {
  428. // If there is no observable instance created yet for thit token, add it.
  429. uint32_t handle;
  430. uint32_t err_code = internal_coap_observe_client_search(&handle, p_response->token, p_response->header.token_len);
  431. if (err_code == (NRF_ERROR_NOT_FOUND | IOT_COAP_ERR_BASE))
  432. {
  433. // If the response is a valid response, add the observable resource.
  434. if (p_response->header.code == COAP_CODE_205_CONTENT)
  435. {
  436. coap_observable_t observable;
  437. // Token Length.
  438. observable.token_len = p_response->header.token_len;
  439. // Remote.
  440. memcpy(&observable.remote, &p_response->remote, sizeof(coap_remote_t));
  441. // Token.
  442. memcpy(observable.token, p_response->token, observable.token_len);
  443. // Callback to be called upon notification.
  444. observable.response_callback = p_item->callback;
  445. // Update max-age to the newly recieved message.
  446. set_max_age(&observable, p_response);
  447. // Register the observable.
  448. uint32_t observable_resource_handle;
  449. (void)internal_coap_observe_client_register(&observable_resource_handle, &observable);
  450. // TODO: error check
  451. COAP_TRC("Subscription response received, client_register handle: %i", observable_resource_handle);
  452. }
  453. }
  454. }
  455. }
  456. else // COAP_OPT_OBSERVE not present
  457. {
  458. uint32_t handle;
  459. uint32_t err_code = internal_coap_observe_client_search(&handle, p_response->token, p_response->header.token_len);
  460. if (err_code == NRF_SUCCESS)
  461. {
  462. (void)internal_coap_observe_client_unregister(handle);
  463. COAP_TRC("OBSERVE not present in notification, client_unregister handle: %i", handle);
  464. }
  465. }
  466. COAP_EXIT();
  467. }
  468. #else
  469. #define observe_client_init(...)
  470. #endif
  471. void internal_coap_observe_init(void)
  472. {
  473. observe_server_init();
  474. observe_client_init();
  475. }
  476. #if (COAP_ENABLE_OBSERVE_SERVER == 1)
  477. uint32_t coap_observe_server_register(uint32_t * p_handle, coap_observer_t * p_observer)
  478. {
  479. COAP_MUTEX_UNLOCK();
  480. uint32_t err_code = internal_coap_observe_server_register(p_handle, p_observer);
  481. COAP_MUTEX_UNLOCK();
  482. return err_code;
  483. }
  484. uint32_t coap_observe_server_unregister(uint32_t handle)
  485. {
  486. COAP_MUTEX_UNLOCK();
  487. uint32_t err_code = internal_coap_observe_server_unregister(handle);
  488. COAP_MUTEX_UNLOCK();
  489. return err_code;
  490. }
  491. uint32_t coap_observe_server_search(uint32_t * p_handle, coap_remote_t * p_observer_addr, coap_resource_t * p_resource)
  492. {
  493. COAP_MUTEX_UNLOCK();
  494. uint32_t err_code = internal_coap_observe_server_search(p_handle, p_observer_addr, p_resource);
  495. COAP_MUTEX_UNLOCK();
  496. return err_code;
  497. }
  498. uint32_t coap_observe_server_next_get(coap_observer_t ** pp_observer, coap_observer_t * p_observer, coap_resource_t * p_resource)
  499. {
  500. COAP_MUTEX_UNLOCK();
  501. uint32_t err_code = internal_coap_observe_server_next_get(pp_observer, p_observer, p_resource);
  502. COAP_MUTEX_UNLOCK();
  503. return err_code;
  504. }
  505. uint32_t coap_observe_server_get(uint32_t handle, coap_observer_t ** pp_observer)
  506. {
  507. COAP_MUTEX_UNLOCK();
  508. uint32_t err_code = internal_coap_observe_server_get(handle, pp_observer);
  509. COAP_MUTEX_UNLOCK();
  510. return err_code;
  511. }
  512. #endif // COAP_ENABLE_OBSERVE_SERVER = 1
  513. #if (COAP_ENABLE_OBSERVE_CLIENT == 1)
  514. uint32_t coap_observe_client_register(uint32_t * p_handle, coap_observable_t * p_observable)
  515. {
  516. COAP_MUTEX_UNLOCK();
  517. uint32_t err_code = internal_coap_observe_client_register(p_handle, p_observable);
  518. COAP_MUTEX_UNLOCK();
  519. return err_code;
  520. }
  521. uint32_t coap_observe_client_unregister(uint32_t handle)
  522. {
  523. COAP_MUTEX_UNLOCK();
  524. uint32_t err_code = internal_coap_observe_client_unregister(handle);
  525. COAP_MUTEX_UNLOCK();
  526. return err_code;
  527. }
  528. uint32_t coap_observe_client_search(uint32_t * p_handle, uint8_t * p_token, uint16_t token_len)
  529. {
  530. COAP_MUTEX_UNLOCK();
  531. uint32_t err_code = internal_coap_observe_client_search(p_handle, p_token, token_len);
  532. COAP_MUTEX_UNLOCK();
  533. return err_code;
  534. }
  535. uint32_t coap_observe_client_get(uint32_t handle, coap_observable_t ** pp_observable)
  536. {
  537. COAP_MUTEX_UNLOCK();
  538. uint32_t err_code = internal_coap_observe_client_get(handle, pp_observable);
  539. COAP_MUTEX_UNLOCK();
  540. return err_code;
  541. }
  542. uint32_t coap_observe_client_next_get(coap_observable_t ** pp_observable, uint32_t * p_handle, coap_observable_t * p_observable)
  543. {
  544. COAP_MUTEX_UNLOCK();
  545. uint32_t err_code = internal_coap_observe_client_next_get(pp_observable, p_handle, p_observable);
  546. COAP_MUTEX_UNLOCK();
  547. return err_code;
  548. }
  549. #endif // COAP_ENABLE_OBSERVE_CLIENT == 1