lwm2m_objects.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. /**
  2. * Copyright (c) 2015 - 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 <stddef.h>
  42. #include "lwm2m_objects.h"
  43. #include "lwm2m.h"
  44. //lint -e516 -save // Symbol '__INTADDR__()' has arg. type conflict
  45. #define LWM2M_INSTANCE_OFFSET_SET(instance, type) \
  46. instance->proto.operations_offset = offsetof(type, operations); \
  47. instance->proto.resource_ids_offset = offsetof(type, resource_ids);
  48. //lint -restore
  49. void lwm2m_instance_security_init(lwm2m_security_t * p_instance)
  50. {
  51. // Set prototype variables.
  52. LWM2M_INSTANCE_OFFSET_SET(p_instance, lwm2m_security_t);
  53. p_instance->proto.object_id = LWM2M_OBJ_SECURITY;
  54. p_instance->proto.instance_id = 0;
  55. p_instance->proto.num_resources = sizeof(((lwm2m_security_t *)0)->operations);
  56. // Set access types.
  57. p_instance->operations[0] = LWM2M_OPERATION_CODE_NONE;
  58. p_instance->operations[1] = LWM2M_OPERATION_CODE_NONE;
  59. p_instance->operations[2] = LWM2M_OPERATION_CODE_NONE;
  60. p_instance->operations[3] = LWM2M_OPERATION_CODE_NONE;
  61. p_instance->operations[4] = LWM2M_OPERATION_CODE_NONE;
  62. p_instance->operations[5] = LWM2M_OPERATION_CODE_NONE;
  63. p_instance->operations[6] = LWM2M_OPERATION_CODE_NONE;
  64. p_instance->operations[7] = LWM2M_OPERATION_CODE_NONE;
  65. p_instance->operations[8] = LWM2M_OPERATION_CODE_NONE;
  66. p_instance->operations[9] = LWM2M_OPERATION_CODE_NONE;
  67. p_instance->operations[10] = LWM2M_OPERATION_CODE_NONE;
  68. p_instance->operations[11] = LWM2M_OPERATION_CODE_NONE;
  69. // Set resource IDs.
  70. p_instance->resource_ids[0] = LWM2M_SECURITY_SERVER_URI;
  71. p_instance->resource_ids[1] = LWM2M_SECURITY_BOOTSTRAP_SERVER;
  72. p_instance->resource_ids[2] = LWM2M_SECURITY_SECURITY_MODE;
  73. p_instance->resource_ids[3] = LWM2M_SECURITY_PUBLIC_KEY;
  74. p_instance->resource_ids[4] = LWM2M_SECURITY_SERVER_PUBLIC_KEY;
  75. p_instance->resource_ids[5] = LWM2M_SECURITY_SECRET_KEY;
  76. p_instance->resource_ids[6] = LWM2M_SECURITY_SMS_SECURITY_MODE;
  77. p_instance->resource_ids[7] = LWM2M_SECURITY_SMS_BINDING_KEY_PARAM;
  78. p_instance->resource_ids[8] = LWM2M_SECURITY_SMS_BINDING_SECRET_KEY;
  79. p_instance->resource_ids[9] = LWM2M_SECURITY_SERVER_SMS_NUMBER;
  80. p_instance->resource_ids[10] = LWM2M_SECURITY_SHORT_SERVER_ID;
  81. p_instance->resource_ids[11] = LWM2M_SECURITY_CLIENT_HOLD_OFF_TIME;
  82. }
  83. void lwm2m_instance_server_init(lwm2m_server_t * p_instance)
  84. {
  85. // Set prototype variables.
  86. LWM2M_INSTANCE_OFFSET_SET(p_instance, lwm2m_server_t);
  87. p_instance->proto.object_id = LWM2M_OBJ_SERVER;
  88. p_instance->proto.instance_id = 0;
  89. p_instance->proto.num_resources = sizeof(((lwm2m_server_t *)0)->operations);
  90. // Set access types.
  91. p_instance->operations[0] = LWM2M_OPERATION_CODE_READ;
  92. p_instance->operations[1] = (LWM2M_OPERATION_CODE_READ | LWM2M_OPERATION_CODE_WRITE);
  93. p_instance->operations[2] = (LWM2M_OPERATION_CODE_READ | LWM2M_OPERATION_CODE_WRITE);
  94. p_instance->operations[3] = (LWM2M_OPERATION_CODE_READ | LWM2M_OPERATION_CODE_WRITE);
  95. p_instance->operations[4] = LWM2M_OPERATION_CODE_EXECUTE;
  96. p_instance->operations[5] = (LWM2M_OPERATION_CODE_READ | LWM2M_OPERATION_CODE_WRITE);
  97. p_instance->operations[6] = (LWM2M_OPERATION_CODE_READ | LWM2M_OPERATION_CODE_WRITE);
  98. p_instance->operations[7] = (LWM2M_OPERATION_CODE_READ | LWM2M_OPERATION_CODE_WRITE);
  99. p_instance->operations[8] = LWM2M_OPERATION_CODE_EXECUTE;
  100. // Set resource IDs.
  101. p_instance->resource_ids[0] = LWM2M_SERVER_SHORT_SERVER_ID;
  102. p_instance->resource_ids[1] = LWM2M_SERVER_LIFETIME;
  103. p_instance->resource_ids[2] = LWM2M_SERVER_DEFAULT_MIN_PERIOD;
  104. p_instance->resource_ids[3] = LWM2M_SERVER_DEFAULT_MAX_PERIOD;
  105. p_instance->resource_ids[4] = LWM2M_SERVER_DISABLE;
  106. p_instance->resource_ids[5] = LWM2M_SERVER_DISABLE_TIMEOUT;
  107. p_instance->resource_ids[6] = LWM2M_SERVER_NOTIFY_WHEN_DISABLED;
  108. p_instance->resource_ids[7] = LWM2M_SERVER_BINDING;
  109. p_instance->resource_ids[8] = LWM2M_SERVER_REGISTRATION_UPDATE_TRIGGER;
  110. }
  111. void lwm2m_instance_firmware_init(lwm2m_firmware_t * p_instance)
  112. {
  113. // Set prototype variables.
  114. LWM2M_INSTANCE_OFFSET_SET(p_instance, lwm2m_firmware_t);
  115. p_instance->proto.object_id = LWM2M_OBJ_FIRMWARE;
  116. p_instance->proto.instance_id = 0;
  117. p_instance->proto.num_resources = sizeof(((lwm2m_firmware_t *)0)->operations);
  118. // Set access types.
  119. p_instance->operations[0] = LWM2M_OPERATION_CODE_WRITE;
  120. p_instance->operations[1] = LWM2M_OPERATION_CODE_WRITE;
  121. p_instance->operations[2] = LWM2M_OPERATION_CODE_EXECUTE;
  122. p_instance->operations[3] = LWM2M_OPERATION_CODE_READ;
  123. p_instance->operations[4] = (LWM2M_OPERATION_CODE_READ | LWM2M_OPERATION_CODE_WRITE);
  124. p_instance->operations[5] = LWM2M_OPERATION_CODE_READ;
  125. // Set resource IDs.
  126. p_instance->resource_ids[0] = LWM2M_FIRMWARE_PACKAGE;
  127. p_instance->resource_ids[1] = LWM2M_FIRMWARE_PACKAGE_URI;
  128. p_instance->resource_ids[2] = LWM2M_FIRMWARE_UPDATE;
  129. p_instance->resource_ids[3] = LWM2M_FIRMWARE_STATE;
  130. p_instance->resource_ids[4] = LWM2M_FIRMWARE_UPDATE_SUPPORTED_OBJECTS;
  131. p_instance->resource_ids[5] = LWM2M_FIRMWARE_UPDATE_RESULT;
  132. }
  133. void lwm2m_instance_acl_init(lwm2m_acl_t * p_instance)
  134. {
  135. // Set prototype variables.
  136. LWM2M_INSTANCE_OFFSET_SET(p_instance, lwm2m_acl_t);
  137. p_instance->proto.object_id = LWM2M_OBJ_ACL;
  138. p_instance->proto.instance_id = 0;
  139. p_instance->proto.num_resources = sizeof(((lwm2m_acl_t *)0)->operations);
  140. // Set access types.
  141. p_instance->operations[0] = LWM2M_OPERATION_CODE_READ;
  142. p_instance->operations[1] = LWM2M_OPERATION_CODE_READ;
  143. p_instance->operations[2] = (LWM2M_OPERATION_CODE_READ | LWM2M_OPERATION_CODE_WRITE);
  144. p_instance->operations[3] = (LWM2M_OPERATION_CODE_READ | LWM2M_OPERATION_CODE_WRITE);
  145. // Set resource IDs.
  146. p_instance->resource_ids[0] = LWM2M_ACL_OBJECT_ID;
  147. p_instance->resource_ids[1] = LWM2M_ACL_INSTANCE_ID;
  148. p_instance->resource_ids[2] = LWM2M_ACL_ACL;
  149. p_instance->resource_ids[3] = LWM2M_ACL_CONTROL_OWNER;
  150. }
  151. void lwm2m_instance_connectivity_monitoring_init(lwm2m_connectivity_monitoring_t * p_instance)
  152. {
  153. // Set prototype variables.
  154. LWM2M_INSTANCE_OFFSET_SET(p_instance, lwm2m_connectivity_monitoring_t);
  155. p_instance->proto.object_id = LWM2M_OBJ_CONN_MON;
  156. p_instance->proto.instance_id = 0;
  157. p_instance->proto.num_resources = sizeof(((lwm2m_connectivity_monitoring_t *)0)->operations);
  158. // Set access types.
  159. p_instance->operations[0] = LWM2M_OPERATION_CODE_READ;
  160. p_instance->operations[1] = LWM2M_OPERATION_CODE_READ;
  161. p_instance->operations[2] = LWM2M_OPERATION_CODE_READ;
  162. p_instance->operations[3] = LWM2M_OPERATION_CODE_READ;
  163. p_instance->operations[4] = LWM2M_OPERATION_CODE_READ;
  164. p_instance->operations[5] = LWM2M_OPERATION_CODE_READ;
  165. p_instance->operations[6] = LWM2M_OPERATION_CODE_READ;
  166. p_instance->operations[7] = LWM2M_OPERATION_CODE_READ;
  167. p_instance->operations[8] = LWM2M_OPERATION_CODE_READ;
  168. p_instance->operations[9] = LWM2M_OPERATION_CODE_READ;
  169. p_instance->operations[10] = LWM2M_OPERATION_CODE_READ;
  170. // Set resource IDs.
  171. p_instance->resource_ids[0] = LWM2M_CONN_MON_NETWORK_BEARER;
  172. p_instance->resource_ids[1] = LWM2M_CONN_MON_AVAILABLE_NETWORK_BEARER;
  173. p_instance->resource_ids[2] = LWM2M_CONN_MON_RADIO_SIGNAL_STRENGHT;
  174. p_instance->resource_ids[3] = LWM2M_CONN_MON_LINK_QUALITY;
  175. p_instance->resource_ids[4] = LWM2M_CONN_MON_IP_ADDRESSES;
  176. p_instance->resource_ids[5] = LWM2M_CONN_MON_ROUTER_IP_ADRESSES;
  177. p_instance->resource_ids[6] = LWM2M_CONN_MON_LINK_UTILIZATION;
  178. p_instance->resource_ids[7] = LWM2M_CONN_MON_APN;
  179. p_instance->resource_ids[8] = LWM2M_CONN_MON_CELL_ID;
  180. p_instance->resource_ids[9] = LWM2M_CONN_MON_SMNC;
  181. p_instance->resource_ids[10] = LWM2M_CONN_MON_SMCC;
  182. }
  183. void lwm2m_instance_connectivity_statistics_init(lwm2m_connectivity_statistics_t * p_instance)
  184. {
  185. // Set prototype variables.
  186. LWM2M_INSTANCE_OFFSET_SET(p_instance, lwm2m_connectivity_statistics_t);
  187. p_instance->proto.object_id = LWM2M_OBJ_CONN_STAT;
  188. p_instance->proto.instance_id = 0;
  189. p_instance->proto.num_resources = sizeof(((lwm2m_connectivity_statistics_t *)0)->operations);
  190. // Set access types.
  191. p_instance->operations[0] = LWM2M_OPERATION_CODE_READ;
  192. p_instance->operations[1] = LWM2M_OPERATION_CODE_READ;
  193. p_instance->operations[2] = LWM2M_OPERATION_CODE_READ;
  194. p_instance->operations[3] = LWM2M_OPERATION_CODE_READ;
  195. p_instance->operations[4] = LWM2M_OPERATION_CODE_READ;
  196. p_instance->operations[5] = LWM2M_OPERATION_CODE_READ;
  197. p_instance->operations[6] = LWM2M_OPERATION_CODE_EXECUTE;
  198. // Set resource IDs.
  199. p_instance->resource_ids[0] = LWM2M_CONN_STAT_SMS_TX_COUNTER;
  200. p_instance->resource_ids[1] = LWM2M_CONN_STAT_SMS_RX_COUNTER;
  201. p_instance->resource_ids[2] = LWM2M_CONN_STAT_TX_DATA;
  202. p_instance->resource_ids[3] = LWM2M_CONN_STAT_RX_DATA;
  203. p_instance->resource_ids[4] = LWM2M_CONN_STAT_MAX_MSG_SIZE;
  204. p_instance->resource_ids[5] = LWM2M_CONN_STAT_AVG_MSG_SIZE;
  205. p_instance->resource_ids[6] = LWM2M_CONN_STAT_START_RESET;
  206. }
  207. void lwm2m_instance_device_init(lwm2m_device_t * p_instance)
  208. {
  209. // Set prototype variables.
  210. LWM2M_INSTANCE_OFFSET_SET(p_instance, lwm2m_device_t);
  211. p_instance->proto.object_id = LWM2M_OBJ_DEVICE;
  212. p_instance->proto.instance_id = 0;
  213. p_instance->proto.num_resources = sizeof(((lwm2m_device_t *)0)->operations);
  214. // Set access types.
  215. p_instance->operations[0] = LWM2M_OPERATION_CODE_READ;
  216. p_instance->operations[1] = LWM2M_OPERATION_CODE_READ;
  217. p_instance->operations[2] = LWM2M_OPERATION_CODE_READ;
  218. p_instance->operations[3] = LWM2M_OPERATION_CODE_READ;
  219. p_instance->operations[4] = LWM2M_OPERATION_CODE_EXECUTE;
  220. p_instance->operations[5] = LWM2M_OPERATION_CODE_EXECUTE;
  221. p_instance->operations[6] = LWM2M_OPERATION_CODE_READ;
  222. p_instance->operations[7] = LWM2M_OPERATION_CODE_READ;
  223. p_instance->operations[8] = LWM2M_OPERATION_CODE_READ;
  224. p_instance->operations[9] = LWM2M_OPERATION_CODE_READ;
  225. p_instance->operations[10] = LWM2M_OPERATION_CODE_READ;
  226. p_instance->operations[11] = LWM2M_OPERATION_CODE_READ;
  227. p_instance->operations[12] = LWM2M_OPERATION_CODE_EXECUTE;
  228. p_instance->operations[13] = (LWM2M_OPERATION_CODE_READ | LWM2M_OPERATION_CODE_WRITE);
  229. p_instance->operations[14] = (LWM2M_OPERATION_CODE_READ | LWM2M_OPERATION_CODE_WRITE);
  230. p_instance->operations[15] = (LWM2M_OPERATION_CODE_READ | LWM2M_OPERATION_CODE_WRITE);
  231. p_instance->operations[16] = LWM2M_OPERATION_CODE_READ;
  232. // Set resource IDs.
  233. p_instance->resource_ids[0] = LWM2M_DEVICE_MANUFACTURER;
  234. p_instance->resource_ids[1] = LWM2M_DEVICE_MODEL_NUMBER;
  235. p_instance->resource_ids[2] = LWM2M_DEVICE_SERIAL_NUMBER;
  236. p_instance->resource_ids[3] = LWM2M_DEVICE_FIRMWARE_VERSION;
  237. p_instance->resource_ids[4] = LWM2M_DEVICE_REBOOT;
  238. p_instance->resource_ids[5] = LWM2M_DEVICE_FACTORY_RESET;
  239. p_instance->resource_ids[6] = LWM2M_DEVICE_AVAILABLE_POWER_SOURCES;
  240. p_instance->resource_ids[7] = LWM2M_DEVICE_POWER_SOURCE_VOLTAGE;
  241. p_instance->resource_ids[8] = LWM2M_DEVICE_POWER_SOURCE_CURRENT;
  242. p_instance->resource_ids[9] = LWM2M_DEVICE_BATTERY_LEVEL;
  243. p_instance->resource_ids[10] = LWM2M_DEVICE_MEMORY_FREE;
  244. p_instance->resource_ids[11] = LWM2M_DEVICE_ERROR_CODE;
  245. p_instance->resource_ids[12] = LWM2M_DEVICE_RESET_ERROR_CODE;
  246. p_instance->resource_ids[13] = LWM2M_DEVICE_CURRENT_TIME;
  247. p_instance->resource_ids[14] = LWM2M_DEVICE_UTC_OFFSET;
  248. p_instance->resource_ids[15] = LWM2M_DEVICE_TIMEZONE;
  249. p_instance->resource_ids[16] = LWM2M_DEVICE_SUPPORTED_BINDINGS;
  250. }
  251. void lwm2m_instance_location_init(lwm2m_location_t * p_instance)
  252. {
  253. // Set prototype variables.
  254. LWM2M_INSTANCE_OFFSET_SET(p_instance, lwm2m_location_t);
  255. p_instance->proto.object_id = LWM2M_OBJ_LOCATION;
  256. p_instance->proto.instance_id = 0;
  257. p_instance->proto.num_resources = sizeof(((lwm2m_location_t *)0)->operations);
  258. // Set access types.
  259. p_instance->operations[0] = LWM2M_OPERATION_CODE_READ;
  260. p_instance->operations[1] = LWM2M_OPERATION_CODE_READ;
  261. p_instance->operations[2] = LWM2M_OPERATION_CODE_READ;
  262. p_instance->operations[3] = LWM2M_OPERATION_CODE_READ;
  263. p_instance->operations[4] = LWM2M_OPERATION_CODE_READ;
  264. p_instance->operations[5] = LWM2M_OPERATION_CODE_READ;
  265. // Set resource IDs.
  266. p_instance->resource_ids[0] = LWM2M_LOCATION_ALTITUDE;
  267. p_instance->resource_ids[1] = LWM2M_LOCATION_LONGITUDE;
  268. p_instance->resource_ids[2] = LWM2M_LOCATION_ALTITUDE;
  269. p_instance->resource_ids[3] = LWM2M_LOCATION_UNCERTAINTY;
  270. p_instance->resource_ids[4] = LWM2M_LOCATION_VELOCITY;
  271. p_instance->resource_ids[5] = LWM2M_LOCATION_TIMESTAMP;
  272. }
  273. void lwm2m_instance_software_update_init(lwm2m_software_update_t * p_instance)
  274. {
  275. // Set prototype variables.
  276. LWM2M_INSTANCE_OFFSET_SET(p_instance, lwm2m_software_update_t);
  277. p_instance->proto.object_id = LWM2M_OBJ_SOFTWARE_UPDATE;
  278. p_instance->proto.instance_id = 0;
  279. p_instance->proto.num_resources = sizeof(((lwm2m_software_update_t *)0)->operations);
  280. // Set access types.
  281. p_instance->operations[0] = LWM2M_OPERATION_CODE_READ;
  282. p_instance->operations[1] = LWM2M_OPERATION_CODE_READ;
  283. p_instance->operations[2] = LWM2M_OPERATION_CODE_WRITE;
  284. p_instance->operations[3] = LWM2M_OPERATION_CODE_WRITE;
  285. p_instance->operations[4] = LWM2M_OPERATION_CODE_EXECUTE;
  286. p_instance->operations[5] = LWM2M_OPERATION_CODE_READ;
  287. p_instance->operations[6] = LWM2M_OPERATION_CODE_EXECUTE;
  288. p_instance->operations[7] = LWM2M_OPERATION_CODE_READ;
  289. p_instance->operations[8] = (LWM2M_OPERATION_CODE_READ | LWM2M_OPERATION_CODE_WRITE);
  290. // Set resource IDs.
  291. p_instance->resource_ids[0] = LWM2M_SW_UPDATE_PKG_NAME;
  292. p_instance->resource_ids[1] = LWM2M_SW_UPDATE_PKG_VERSION;
  293. p_instance->resource_ids[2] = LWM2M_SW_UPDATE_PACKAGE;
  294. p_instance->resource_ids[3] = LWM2M_SW_UPDATE_PACKAGE_URI;
  295. p_instance->resource_ids[4] = LWM2M_SW_UPDATE_INSTALL;
  296. p_instance->resource_ids[5] = LWM2M_SW_UPDATE_CHECKPOINT;
  297. p_instance->resource_ids[6] = LWM2M_SW_UPDATE_UNINSTALL;
  298. p_instance->resource_ids[7] = LWM2M_SW_UPDATE_UPDATE_STATE;
  299. p_instance->resource_ids[8] = LWM2M_SW_UPDATE_SUPPORTED_OBJECTS;
  300. }