Skip to content

Commit d53fb57

Browse files
rluboscarlescufi
authored andcommitted
net: lwm2m: Introduce attribute handling helper functions
Introduce LwM2M engine helper functions that allows to work with LwM2M attributes outside of lwm2m_engine.c. This is a groundwork for application/lwm2m-format content writer. Signed-off-by: Robert Lubos <[email protected]>
1 parent 6ca6b22 commit d53fb57

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

subsys/net/lib/lwm2m/lwm2m_engine.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,37 @@ static int path_to_objs(const struct lwm2m_obj_path *path,
13671367
return 0;
13681368
}
13691369

1370+
struct lwm2m_attr *lwm2m_engine_get_next_attr(const void *ref,
1371+
struct lwm2m_attr *prev)
1372+
{
1373+
struct lwm2m_attr *iter = (prev == NULL) ? write_attr_pool : prev + 1;
1374+
struct lwm2m_attr *result = NULL;
1375+
1376+
if (!PART_OF_ARRAY(write_attr_pool, iter)) {
1377+
return NULL;
1378+
}
1379+
1380+
while (iter < &write_attr_pool[ARRAY_SIZE(write_attr_pool)]) {
1381+
if (ref == iter->ref) {
1382+
result = iter;
1383+
break;
1384+
}
1385+
1386+
++iter;
1387+
}
1388+
1389+
return result;
1390+
}
1391+
1392+
const char *lwm2m_engine_get_attr_name(const struct lwm2m_attr *attr)
1393+
{
1394+
if (attr->type >= NR_LWM2M_ATTR) {
1395+
return NULL;
1396+
}
1397+
1398+
return LWM2M_ATTR_STR[attr->type];
1399+
}
1400+
13701401
int lwm2m_engine_create_obj_inst(char *pathstr)
13711402
{
13721403
struct lwm2m_obj_path path;
@@ -3486,6 +3517,44 @@ int lwm2m_get_or_create_engine_obj(struct lwm2m_message *msg,
34863517
return ret;
34873518
}
34883519

3520+
struct lwm2m_engine_obj *lwm2m_engine_get_obj(
3521+
const struct lwm2m_obj_path *path)
3522+
{
3523+
if (path->level < LWM2M_PATH_LEVEL_OBJECT) {
3524+
return NULL;
3525+
}
3526+
3527+
return get_engine_obj(path->obj_id);
3528+
}
3529+
3530+
struct lwm2m_engine_obj_inst *lwm2m_engine_get_obj_inst(
3531+
const struct lwm2m_obj_path *path)
3532+
{
3533+
if (path->level < LWM2M_PATH_LEVEL_OBJECT_INST) {
3534+
return NULL;
3535+
}
3536+
3537+
return get_engine_obj_inst(path->obj_id, path->obj_inst_id);
3538+
}
3539+
3540+
struct lwm2m_engine_res *lwm2m_engine_get_res(
3541+
const struct lwm2m_obj_path *path)
3542+
{
3543+
struct lwm2m_engine_res *res = NULL;
3544+
int ret;
3545+
3546+
if (path->level < LWM2M_PATH_LEVEL_RESOURCE) {
3547+
return NULL;
3548+
}
3549+
3550+
ret = path_to_objs(path, NULL, NULL, &res, NULL);
3551+
if (ret < 0) {
3552+
return NULL;
3553+
}
3554+
3555+
return res;
3556+
}
3557+
34893558
static int do_write_op(struct lwm2m_message *msg,
34903559
uint16_t format)
34913560
{

subsys/net/lib/lwm2m/lwm2m_engine.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ int lwm2m_get_or_create_engine_obj(struct lwm2m_message *msg,
6565
struct lwm2m_engine_obj_inst **obj_inst,
6666
uint8_t *created);
6767

68+
struct lwm2m_engine_obj *lwm2m_engine_get_obj(
69+
const struct lwm2m_obj_path *path);
70+
struct lwm2m_engine_obj_inst *lwm2m_engine_get_obj_inst(
71+
const struct lwm2m_obj_path *path);
72+
struct lwm2m_engine_res *lwm2m_engine_get_res(
73+
const struct lwm2m_obj_path *path);
74+
6875
/* LwM2M context functions */
6976
int lwm2m_engine_context_close(struct lwm2m_ctx *client_ctx);
7077
void lwm2m_engine_context_init(struct lwm2m_ctx *client_ctx);
@@ -118,6 +125,12 @@ void lwm2m_firmware_set_update_result(uint8_t result);
118125
uint8_t lwm2m_firmware_get_update_result(void);
119126
#endif
120127

128+
/* Attribute handling. */
129+
130+
struct lwm2m_attr *lwm2m_engine_get_next_attr(const void *ref,
131+
struct lwm2m_attr *prev);
132+
const char *lwm2m_engine_get_attr_name(const struct lwm2m_attr *attr);
133+
121134
/* Network Layer */
122135
int lwm2m_socket_add(struct lwm2m_ctx *ctx);
123136
void lwm2m_socket_del(struct lwm2m_ctx *ctx);

subsys/net/lib/lwm2m/lwm2m_object.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@
140140
struct lwm2m_engine_obj;
141141
struct lwm2m_message;
142142

143+
#define LWM2M_PATH_LEVEL_NONE 0
144+
#define LWM2M_PATH_LEVEL_OBJECT 1
145+
#define LWM2M_PATH_LEVEL_OBJECT_INST 2
146+
#define LWM2M_PATH_LEVEL_RESOURCE 3
147+
#define LWM2M_PATH_LEVEL_RESOURCE_INST 4
148+
143149
/* path representing object instances */
144150
struct lwm2m_obj_path {
145151
uint16_t obj_id;

0 commit comments

Comments
 (0)