net: lwm2m: Initialize empty string sizes correctly on objects
When objects are initialized, empty strings should be set to length of zero, instead of length of the full buffer. So use INIT_OBJ_RES_DATA_LEN() to give both, the buffer size and data length. Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
This commit is contained in:
parent
015b1103fb
commit
bd0ad5bd66
|
@ -177,8 +177,8 @@ static struct lwm2m_engine_obj_inst *current_sensor_create(uint16_t obj_inst_id)
|
|||
INIT_OBJ_RES(SENSOR_VALUE_RID, res[index], i, res_inst[index], j, 1,
|
||||
false, true, &sensor_value[index], sizeof(*sensor_value),
|
||||
NULL, NULL, NULL, sensor_value_write_cb, NULL);
|
||||
INIT_OBJ_RES_DATA(SENSOR_UNITS_RID, res[index], i, res_inst[index], j,
|
||||
units[index], UNIT_STR_MAX_SIZE);
|
||||
INIT_OBJ_RES_DATA_LEN(SENSOR_UNITS_RID, res[index], i, res_inst[index], j,
|
||||
units[index], UNIT_STR_MAX_SIZE, 0);
|
||||
INIT_OBJ_RES_DATA(MIN_MEASURED_VALUE_RID, res[index], i,
|
||||
res_inst[index], j, &min_measured_value[index],
|
||||
sizeof(*min_measured_value));
|
||||
|
@ -194,8 +194,8 @@ static struct lwm2m_engine_obj_inst *current_sensor_create(uint16_t obj_inst_id)
|
|||
INIT_OBJ_RES_DATA(CURRENT_CALIBRATION_RID, res[index], i,
|
||||
res_inst[index], j, &calibration_coefficient[index],
|
||||
sizeof(*calibration_coefficient));
|
||||
INIT_OBJ_RES_DATA(APPLICATION_TYPE_RID, res[index], i, res_inst[index],
|
||||
j, app_type[index], APP_TYPE_STR_MAX_SIZE);
|
||||
INIT_OBJ_RES_DATA_LEN(APPLICATION_TYPE_RID, res[index], i, res_inst[index],
|
||||
j, app_type[index], APP_TYPE_STR_MAX_SIZE, 0);
|
||||
|
||||
#if defined(CONFIG_LWM2M_IPSO_CURRENT_SENSOR_VERSION_1_1)
|
||||
INIT_OBJ_RES_OPTDATA(TIMESTAMP_RID, res[index], i, res_inst[index], j);
|
||||
|
|
|
@ -186,8 +186,8 @@ static struct lwm2m_engine_obj_inst *generic_sensor_create(uint16_t obj_inst_id)
|
|||
INIT_OBJ_RES(SENSOR_VALUE_RID, res[index], i, res_inst[index], j, 1,
|
||||
false, true, &sensor_value[index], sizeof(*sensor_value),
|
||||
NULL, NULL, NULL, sensor_value_write_cb, NULL);
|
||||
INIT_OBJ_RES_DATA(SENSOR_UNITS_RID, res[index], i, res_inst[index], j,
|
||||
units[index], UNIT_STR_MAX_SIZE);
|
||||
INIT_OBJ_RES_DATA_LEN(SENSOR_UNITS_RID, res[index], i, res_inst[index], j,
|
||||
units[index], UNIT_STR_MAX_SIZE, 0);
|
||||
INIT_OBJ_RES_DATA(MIN_MEASURED_VALUE_RID, res[index], i,
|
||||
res_inst[index], j, &min_measured_value[index],
|
||||
sizeof(*min_measured_value));
|
||||
|
@ -200,10 +200,10 @@ static struct lwm2m_engine_obj_inst *generic_sensor_create(uint16_t obj_inst_id)
|
|||
j, &max_range_value[index], sizeof(*max_range_value));
|
||||
INIT_OBJ_RES_EXECUTE(RESET_MIN_MAX_MEASURED_VALUES_RID, res[index], i,
|
||||
reset_min_max_measured_values_cb);
|
||||
INIT_OBJ_RES_DATA(APPLICATION_TYPE_RID, res[index], i, res_inst[index],
|
||||
j, app_type[index], APP_TYPE_STR_MAX_SIZE);
|
||||
INIT_OBJ_RES_DATA(SENSOR_TYPE_RID, res[index], i, res_inst[index], j,
|
||||
sensor_type[index], SENSOR_TYPE_STR_MAX_SIZE);
|
||||
INIT_OBJ_RES_DATA_LEN(APPLICATION_TYPE_RID, res[index], i, res_inst[index],
|
||||
j, app_type[index], APP_TYPE_STR_MAX_SIZE, 0);
|
||||
INIT_OBJ_RES_DATA_LEN(SENSOR_TYPE_RID, res[index], i, res_inst[index], j,
|
||||
sensor_type[index], SENSOR_TYPE_STR_MAX_SIZE, 0);
|
||||
|
||||
#if defined(CONFIG_LWM2M_IPSO_GENERIC_SENSOR_VERSION_1_1)
|
||||
INIT_OBJ_RES_OPTDATA(TIMESTAMP_RID, res[index], i, res_inst[index], j);
|
||||
|
|
|
@ -170,8 +170,8 @@ humidity_sensor_create(uint16_t obj_inst_id)
|
|||
INIT_OBJ_RES(SENSOR_VALUE_RID, res[index], i, res_inst[index], j, 1,
|
||||
false, true, &sensor_value[index], sizeof(*sensor_value),
|
||||
NULL, NULL, NULL, sensor_value_write_cb, NULL);
|
||||
INIT_OBJ_RES_DATA(SENSOR_UNITS_RID, res[index], i, res_inst[index], j,
|
||||
units[index], UNIT_STR_MAX_SIZE);
|
||||
INIT_OBJ_RES_DATA_LEN(SENSOR_UNITS_RID, res[index], i, res_inst[index], j,
|
||||
units[index], UNIT_STR_MAX_SIZE, 0);
|
||||
INIT_OBJ_RES_DATA(MIN_MEASURED_VALUE_RID, res[index], i,
|
||||
res_inst[index], j, &min_measured_value[index],
|
||||
sizeof(*min_measured_value));
|
||||
|
|
|
@ -171,10 +171,10 @@ static struct lwm2m_engine_obj_inst *light_control_create(uint16_t obj_inst_id)
|
|||
INIT_OBJ_RES_DATA(POWER_FACTOR_RID, res[avail], i, res_inst[avail], j,
|
||||
&power_factor_value[avail],
|
||||
sizeof(*power_factor_value));
|
||||
INIT_OBJ_RES_DATA(COLOUR_RID, res[avail], i, res_inst[avail], j,
|
||||
colour[avail], LIGHT_STRING_LONG);
|
||||
INIT_OBJ_RES_DATA(SENSOR_UNITS_RID, res[avail], i, res_inst[avail], j,
|
||||
units[avail], LIGHT_STRING_SHORT);
|
||||
INIT_OBJ_RES_DATA_LEN(COLOUR_RID, res[avail], i, res_inst[avail], j,
|
||||
colour[avail], LIGHT_STRING_LONG, 0);
|
||||
INIT_OBJ_RES_DATA_LEN(SENSOR_UNITS_RID, res[avail], i, res_inst[avail], j,
|
||||
units[avail], LIGHT_STRING_SHORT, 0);
|
||||
INIT_OBJ_RES_OPTDATA(APPLICATION_TYPE_RID, res[avail], i,
|
||||
res_inst[avail], j);
|
||||
|
||||
|
|
|
@ -171,8 +171,8 @@ pressure_sensor_create(uint16_t obj_inst_id)
|
|||
INIT_OBJ_RES(SENSOR_VALUE_RID, res[index], i, res_inst[index], j, 1,
|
||||
false, true, &sensor_value[index], sizeof(*sensor_value),
|
||||
NULL, NULL, NULL, sensor_value_write_cb, NULL);
|
||||
INIT_OBJ_RES_DATA(SENSOR_UNITS_RID, res[index], i, res_inst[index], j,
|
||||
units[index], UNIT_STR_MAX_SIZE);
|
||||
INIT_OBJ_RES_DATA_LEN(SENSOR_UNITS_RID, res[index], i, res_inst[index], j,
|
||||
units[index], UNIT_STR_MAX_SIZE, 0);
|
||||
INIT_OBJ_RES_DATA(MIN_MEASURED_VALUE_RID, res[index], i,
|
||||
res_inst[index], j, &min_measured_value[index],
|
||||
sizeof(*min_measured_value));
|
||||
|
|
|
@ -172,8 +172,8 @@ static struct lwm2m_engine_obj_inst *temp_sensor_create(uint16_t obj_inst_id)
|
|||
res_inst[index], j, 1, false, true,
|
||||
&sensor_value[index], sizeof(*sensor_value),
|
||||
NULL, NULL, NULL, sensor_value_write_cb, NULL);
|
||||
INIT_OBJ_RES_DATA(SENSOR_UNITS_RID, res[index], i, res_inst[index], j,
|
||||
units[index], UNIT_STR_MAX_SIZE);
|
||||
INIT_OBJ_RES_DATA_LEN(SENSOR_UNITS_RID, res[index], i, res_inst[index], j,
|
||||
units[index], UNIT_STR_MAX_SIZE, 0);
|
||||
INIT_OBJ_RES_DATA(MIN_MEASURED_VALUE_RID, res[index], i,
|
||||
res_inst[index], j, &min_measured_value[index],
|
||||
sizeof(*min_measured_value));
|
||||
|
|
|
@ -178,8 +178,8 @@ static struct lwm2m_engine_obj_inst *voltage_sensor_create(uint16_t obj_inst_id)
|
|||
INIT_OBJ_RES(SENSOR_VALUE_RID, res[index], i, res_inst[index], j, 1,
|
||||
false, true, &sensor_value[index], sizeof(*sensor_value),
|
||||
NULL, NULL, NULL, sensor_value_write_cb, NULL);
|
||||
INIT_OBJ_RES_DATA(SENSOR_UNITS_RID, res[index], i, res_inst[index], j,
|
||||
units[index], UNIT_STR_MAX_SIZE);
|
||||
INIT_OBJ_RES_DATA_LEN(SENSOR_UNITS_RID, res[index], i, res_inst[index], j,
|
||||
units[index], UNIT_STR_MAX_SIZE, 0);
|
||||
INIT_OBJ_RES_DATA(MIN_MEASURED_VALUE_RID, res[index], i,
|
||||
res_inst[index], j, &min_measured_value[index],
|
||||
sizeof(*min_measured_value));
|
||||
|
@ -195,8 +195,8 @@ static struct lwm2m_engine_obj_inst *voltage_sensor_create(uint16_t obj_inst_id)
|
|||
INIT_OBJ_RES_DATA(CURRENT_CALIBRATION_RID, res[index], i,
|
||||
res_inst[index], j, &calibration_coefficient[index],
|
||||
sizeof(*calibration_coefficient));
|
||||
INIT_OBJ_RES_DATA(APPLICATION_TYPE_RID, res[index], i, res_inst[index],
|
||||
j, app_type[index], APP_TYPE_STR_MAX_SIZE);
|
||||
INIT_OBJ_RES_DATA_LEN(APPLICATION_TYPE_RID, res[index], i, res_inst[index],
|
||||
j, app_type[index], APP_TYPE_STR_MAX_SIZE, 0);
|
||||
|
||||
#if defined(CONFIG_LWM2M_IPSO_VOLTAGE_SENSOR_VERSION_1_1)
|
||||
INIT_OBJ_RES_OPTDATA(TIMESTAMP_RID, res[index], i, res_inst[index], j);
|
||||
|
|
|
@ -251,8 +251,8 @@ static struct lwm2m_engine_obj_inst *device_create(uint16_t obj_inst_id)
|
|||
NULL, current_time_post_write_cb, NULL);
|
||||
INIT_OBJ_RES_OPTDATA(DEVICE_UTC_OFFSET_ID, res, i, res_inst, j);
|
||||
INIT_OBJ_RES_OPTDATA(DEVICE_TIMEZONE_ID, res, i, res_inst, j);
|
||||
INIT_OBJ_RES_DATA(DEVICE_SUPPORTED_BINDING_MODES_ID, res, i,
|
||||
res_inst, j, binding_mode, DEVICE_STRING_SHORT);
|
||||
INIT_OBJ_RES_DATA_LEN(DEVICE_SUPPORTED_BINDING_MODES_ID, res, i,
|
||||
res_inst, j, binding_mode, DEVICE_STRING_SHORT, strlen(binding_mode) + 1);
|
||||
INIT_OBJ_RES_OPTDATA(DEVICE_TYPE_ID, res, i, res_inst, j);
|
||||
INIT_OBJ_RES_OPTDATA(DEVICE_HARDWARE_VERSION_ID, res, i, res_inst, j);
|
||||
INIT_OBJ_RES_OPTDATA(DEVICE_SOFTWARE_VERSION_ID, res, i, res_inst, j);
|
||||
|
|
|
@ -127,15 +127,18 @@ static struct lwm2m_engine_obj_inst *lwm2m_gw_create(uint16_t obj_inst_id)
|
|||
init_res_instance(res_inst[index], ARRAY_SIZE(res_inst[index]));
|
||||
|
||||
/* initialize instance resource data */
|
||||
INIT_OBJ_RES_DATA(LWM2M_GATEWAY_DEVICE_RID, res[index], i, res_inst[index], j,
|
||||
device_table[index].device_id,
|
||||
CONFIG_LWM2M_GATEWAY_DEVICE_ID_MAX_STR_SIZE);
|
||||
INIT_OBJ_RES(LWM2M_GATEWAY_PREFIX_RID, res[index], i, res_inst[index], j, 1, false, true,
|
||||
device_table[index].prefix, CONFIG_LWM2M_GATEWAY_PREFIX_MAX_STR_SIZE, NULL,
|
||||
NULL, prefix_validation_cb, NULL, NULL);
|
||||
INIT_OBJ_RES_DATA(LWM2M_GATEWAY_IOT_DEVICE_OBJECTS_RID, res[index], i, res_inst[index], j,
|
||||
device_table[index].iot_device_objects,
|
||||
sizeof(device_table[index].iot_device_objects));
|
||||
INIT_OBJ_RES_DATA_LEN(LWM2M_GATEWAY_DEVICE_RID, res[index], i, res_inst[index], j,
|
||||
device_table[index].device_id,
|
||||
CONFIG_LWM2M_GATEWAY_DEVICE_ID_MAX_STR_SIZE,
|
||||
strlen(device_table[index].device_id) + 1);
|
||||
INIT_OBJ_RES_LEN(LWM2M_GATEWAY_PREFIX_RID, res[index], i, res_inst[index], j, 1, false,
|
||||
true, device_table[index].prefix, CONFIG_LWM2M_GATEWAY_PREFIX_MAX_STR_SIZE,
|
||||
strlen(device_table[index].prefix) + 1, NULL, NULL, prefix_validation_cb,
|
||||
NULL, NULL);
|
||||
INIT_OBJ_RES_DATA_LEN(LWM2M_GATEWAY_IOT_DEVICE_OBJECTS_RID, res[index], i, res_inst[index],
|
||||
j, device_table[index].iot_device_objects,
|
||||
sizeof(device_table[index].iot_device_objects),
|
||||
strlen(device_table[index].iot_device_objects) + 1);
|
||||
|
||||
inst[index].resources = res[index];
|
||||
inst[index].resource_count = i;
|
||||
|
|
|
@ -301,11 +301,10 @@ static struct lwm2m_engine_obj_inst *server_create(uint16_t obj_inst_id)
|
|||
&server_flag_store_notify[index],
|
||||
sizeof(*server_flag_store_notify));
|
||||
/* Mark Transport Binding RO as we only support UDP atm */
|
||||
INIT_OBJ_RES_DATA(SERVER_TRANSPORT_BINDING_ID, res[index], i,
|
||||
res_inst[index], j,
|
||||
transport_binding[index], TRANSPORT_BINDING_LEN);
|
||||
INIT_OBJ_RES_EXECUTE(SERVER_REG_UPDATE_TRIGGER_ID, res[index], i,
|
||||
update_trigger_cb);
|
||||
INIT_OBJ_RES_DATA_LEN(SERVER_TRANSPORT_BINDING_ID, res[index], i, res_inst[index], j,
|
||||
transport_binding[index], TRANSPORT_BINDING_LEN,
|
||||
strlen(transport_binding[index]) + 1);
|
||||
INIT_OBJ_RES_EXECUTE(SERVER_REG_UPDATE_TRIGGER_ID, res[index], i, update_trigger_cb);
|
||||
#if defined(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1)
|
||||
INIT_OBJ_RES_EXECUTE(SERVER_BOOTSTRAP_UPDATE_TRIGGER_ID, res[index], i,
|
||||
bootstrap_trigger_cb);
|
||||
|
|
|
@ -132,8 +132,8 @@ static struct lwm2m_engine_obj_inst *lpwan_create(uint16_t obj_inst_id)
|
|||
j, NETWORK_ADDRESS_MAX, false);
|
||||
INIT_OBJ_RES_MULTI_OPTDATA(UCIFI_LPWAN_SECONDARY_ADDRESS_RID, res[index], i,
|
||||
res_inst[index], j, SECONDARY_NETWORK_ADDRESS_MAX, false);
|
||||
INIT_OBJ_RES_DATA(UCIFI_LPWAN_MAC_ADDRESS_RID, res[index], i, res_inst[index], j,
|
||||
mac[index], MAC_ADDRESS_SIZE);
|
||||
INIT_OBJ_RES_DATA_LEN(UCIFI_LPWAN_MAC_ADDRESS_RID, res[index], i, res_inst[index], j,
|
||||
mac[index], MAC_ADDRESS_SIZE, 0);
|
||||
INIT_OBJ_RES_MULTI_OPTDATA(UCIFI_LPWAN_PEER_ADDRESS_RID, res[index], i, res_inst[index], j,
|
||||
PEER_ADDRESS_MAX, false);
|
||||
INIT_OBJ_RES_MULTI_OPTDATA(UCIFI_LPWAN_MULTICAST_GRP_ADDRESS_RID, res[index], i,
|
||||
|
|
Loading…
Reference in a new issue