diff options
Diffstat (limited to 'samples')
-rw-r--r-- | samples/bluetooth/peripheral/src/main.c | 10 | ||||
-rw-r--r-- | samples/bluetooth/peripheral_csc/src/main.c | 5 | ||||
-rw-r--r-- | samples/bluetooth/peripheral_esp/src/main.c | 37 |
3 files changed, 25 insertions, 27 deletions
diff --git a/samples/bluetooth/peripheral/src/main.c b/samples/bluetooth/peripheral/src/main.c index b13b7ad15..08ab9a494 100644 --- a/samples/bluetooth/peripheral/src/main.c +++ b/samples/bluetooth/peripheral/src/main.c @@ -141,7 +141,7 @@ static int write_ct(struct bt_conn *conn, const struct bt_gatt_attr *attr, uint8_t *value = attr->user_data; if (offset + len > sizeof(ct)) { - return -EINVAL; + return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); } memcpy(value + offset, buf, len); @@ -198,7 +198,7 @@ static int write_vnd(struct bt_conn *conn, const struct bt_gatt_attr *attr, uint8_t *value = attr->user_data; if (offset + len > sizeof(vnd_value)) { - return -EINVAL; + return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); } memcpy(value + offset, buf, len); @@ -233,7 +233,7 @@ static int write_long_vnd(struct bt_conn *conn, struct vnd_long_value *value = attr->user_data; if (offset + len > sizeof(value->buf)) { - return -EINVAL; + return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); } /* Copy to buffer */ @@ -258,7 +258,7 @@ static int flush_long_vnd(struct bt_conn *conn, return 0; } - return -EINVAL; + return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY); } static const struct bt_uuid_128 vnd_long_uuid = BT_UUID_INIT_128( @@ -286,7 +286,7 @@ static int write_signed(struct bt_conn *conn, const struct bt_gatt_attr *attr, uint8_t *value = attr->user_data; if (offset + len > sizeof(signed_value)) { - return -EINVAL; + return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); } memcpy(value + offset, buf, len); diff --git a/samples/bluetooth/peripheral_csc/src/main.c b/samples/bluetooth/peripheral_csc/src/main.c index eeaa28055..04f985f67 100644 --- a/samples/bluetooth/peripheral_csc/src/main.c +++ b/samples/bluetooth/peripheral_csc/src/main.c @@ -238,12 +238,11 @@ static int write_ctrl_point(struct bt_conn *conn, int i; if (!ctrl_point_configured) { - /* TODO: Return CSC_ERR_CCC_CONFIG */ - return -EINVAL; + return BT_GATT_ERR(CSC_ERR_CCC_CONFIG); } if (!len) { - return -EINVAL; + return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); } switch (req->op) { diff --git a/samples/bluetooth/peripheral_esp/src/main.c b/samples/bluetooth/peripheral_esp/src/main.c index 3dbc10b24..a55741060 100644 --- a/samples/bluetooth/peripheral_esp/src/main.c +++ b/samples/bluetooth/peripheral_esp/src/main.c @@ -328,15 +328,16 @@ static int write_temp_trigger_setting(struct bt_conn *conn, uint16_t offset) { const struct write_es_trigger_setting_req *req = buf; + const struct es_trigger_setting_reference *ref; struct temperature_sensor *sensor = attr->user_data; + uint16_t ref_val; if (!len) { - return -EFBIG; + return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); } if (req->condition > 0x09) { - /* TODO: Return ESS_ERR_COND_NOT_SUPP */ - return -EINVAL; + return BT_GATT_ERR(ESS_ERR_COND_NOT_SUPP); } switch (req->condition) { @@ -345,7 +346,7 @@ static int write_temp_trigger_setting(struct bt_conn *conn, /* fallthrough */ case ESS_VALUE_CHANGED: if (len != sizeof(sensor->condition)) { - return -EINVAL; + return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); } sensor->condition = req->condition; @@ -355,30 +356,28 @@ static int write_temp_trigger_setting(struct bt_conn *conn, /* fallthrough */ case ESS_NO_LESS_THAN_SPECIFIED_TIME: if (len != sizeof(struct es_trigger_setting_seconds)) { - return -EINVAL; + return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); } sensor->condition = req->condition; sensor->seconds = le24_to_int(req->operand); break; /* Reference temperature */ - default: { - const struct es_trigger_setting_reference *req = buf; - uint16_t ref_val = sys_le16_to_cpu(req->ref_val); - - if (len != sizeof(*req)) { - return -EINVAL; - } + default: + if (len != sizeof(*ref)) { + return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); + } - if (sensor->lower_limit > ref_val || - sensor->upper_limit < ref_val) { - /* TODO: Return ERR_OUT_OF_RANGE */ - return -EINVAL; - } + ref = buf; + ref_val = sys_le16_to_cpu(ref->ref_val); - sensor->condition = req->condition; - sensor->ref_val = ref_val; + if (sensor->lower_limit > ref_val || + sensor->upper_limit < ref_val) { + return BT_GATT_ERR(BT_ATT_ERR_OUT_OF_RANGE); } + + sensor->condition = req->condition; + sensor->ref_val = ref_val; } return len; |