int result = 0;
-if (anjay_access_control_install(anjay)
- || anjay_security_object_install(anjay)
- || anjay_server_object_install(anjay)) {
- result = -1;
-}
+int result = 0;
+if (anjay_access_control_install(anjay)
+ || anjay_security_object_install(anjay)
+ || anjay_server_object_install(anjay)) {
+ result = -1;
+}
Then we setup two LwM2M Servers:
// LwM2M Server account with SSID = 1
-const anjay_security_instance_t security_instance1 = {
- .ssid = 1,
- .server_uri = "coap://eu.iot.avsystem.cloud:5683",
- .security_mode = ANJAY_SECURITY_NOSEC
-};
+const anjay_security_instance_t security_instance1 = {
+ .ssid = 1,
+ .server_uri = "coap://eu.iot.avsystem.cloud:5683",
+ .security_mode = ANJAY_SECURITY_NOSEC
+};
-const anjay_server_instance_t server_instance1 = {
- .ssid = 1,
- .lifetime = 86400,
- .default_min_period = -1,
- .default_max_period = -1,
- .disable_timeout = -1,
- .binding = "U"
-};
+const anjay_server_instance_t server_instance1 = {
+ .ssid = 1,
+ .lifetime = 86400,
+ .default_min_period = -1,
+ .default_max_period = -1,
+ .disable_timeout = -1,
+ .binding = "U"
+};
// LwM2M Server account with SSID = 2
-const anjay_security_instance_t security_instance2 = {
- .ssid = 2,
- .server_uri = "coap://127.0.0.1:5683",
- .security_mode = ANJAY_SECURITY_NOSEC
-};
+const anjay_security_instance_t security_instance2 = {
+ .ssid = 2,
+ .server_uri = "coap://127.0.0.1:5683",
+ .security_mode = ANJAY_SECURITY_NOSEC
+};
-const anjay_server_instance_t server_instance2 = {
- .ssid = 2,
- .lifetime = 86400,
- .default_min_period = -1,
- .default_max_period = -1,
- .disable_timeout = -1,
- .binding = "U"
-};
+const anjay_server_instance_t server_instance2 = {
+ .ssid = 2,
+ .lifetime = 86400,
+ .default_min_period = -1,
+ .default_max_period = -1,
+ .disable_timeout = -1,
+ .binding = "U"
+};
// Setup first LwM2M Server
-anjay_iid_t server_instance_iid1 = ANJAY_ID_INVALID;
-anjay_security_object_add_instance(anjay, &security_instance1,
- &(anjay_iid_t) { ANJAY_ID_INVALID });
-anjay_server_object_add_instance(anjay, &server_instance1,
- &server_instance_iid1);
+anjay_iid_t server_instance_iid1 = ANJAY_ID_INVALID;
+anjay_security_object_add_instance(anjay, &security_instance1,
+ &(anjay_iid_t) { ANJAY_ID_INVALID });
+anjay_server_object_add_instance(anjay, &server_instance1,
+ &server_instance_iid1);
// Setup second LwM2M Server
-anjay_iid_t server_instance_iid2 = ANJAY_ID_INVALID;
-anjay_security_object_add_instance(anjay, &security_instance2,
- &(anjay_iid_t) { ANJAY_ID_INVALID });
-anjay_server_object_add_instance(anjay, &server_instance2,
- &server_instance_iid2);
+anjay_iid_t server_instance_iid2 = ANJAY_ID_INVALID;
+anjay_security_object_add_instance(anjay, &security_instance2,
+ &(anjay_iid_t) { ANJAY_ID_INVALID });
+anjay_server_object_add_instance(anjay, &server_instance2,
+ &server_instance_iid2);
And finally, we are ready to set access lists:
// Make SSID = 1 the owner of the Test object
-anjay_access_control_set_owner(anjay, 1234, ANJAY_ID_INVALID,
- server_instance1.ssid, NULL);
+anjay_access_control_set_owner(anjay, 1234, ANJAY_ID_INVALID,
+ server_instance1.ssid, NULL);
// Set LwM2M Create permission rights for it as well
-anjay_access_control_set_acl(anjay, 1234, ANJAY_ID_INVALID,
- server_instance1.ssid,
- ANJAY_ACCESS_MASK_CREATE);
+anjay_access_control_set_acl(anjay, 1234, ANJAY_ID_INVALID,
+ server_instance1.ssid,
+ ANJAY_ACCESS_MASK_CREATE);
// Allow both LwM2M Servers to read their Server Instances
-anjay_access_control_set_acl(anjay, 1, server_instance_iid1,
- server_instance1.ssid, ANJAY_ACCESS_MASK_READ);
-anjay_access_control_set_acl(anjay, 1, server_instance_iid2,
- server_instance2.ssid, ANJAY_ACCESS_MASK_READ);
+anjay_access_control_set_acl(anjay, 1, server_instance_iid1,
+ server_instance1.ssid, ANJAY_ACCESS_MASK_READ);
+anjay_access_control_set_acl(anjay, 1, server_instance_iid2,
+ server_instance2.ssid, ANJAY_ACCESS_MASK_READ);
That way we have ensured an exclusive access of Server with SSID 1 to Test
@@ -309,10 +306,10 @@
5.1.3. Example usage