diff options
-rw-r--r-- | attrib/att-database.h | 6 | ||||
-rw-r--r-- | attrib/att.c | 132 | ||||
-rw-r--r-- | attrib/att.h | 116 | ||||
-rw-r--r-- | attrib/client.c | 2 | ||||
-rw-r--r-- | attrib/gatt.c | 43 | ||||
-rw-r--r-- | attrib/gatt.h | 3 | ||||
-rw-r--r-- | attrib/gattrib.c | 4 | ||||
-rw-r--r-- | attrib/gattrib.h | 2 | ||||
-rw-r--r-- | attrib/gatttool.c | 2 | ||||
-rw-r--r-- | attrib/interactive.c | 2 | ||||
-rw-r--r-- | profiles/thermometer/thermometer.c | 2 | ||||
-rw-r--r-- | profiles/time/server.c | 2 | ||||
-rw-r--r-- | src/attrib-server.c | 43 | ||||
-rw-r--r-- | src/attrib-server.h | 9 |
14 files changed, 193 insertions, 175 deletions
diff --git a/attrib/att-database.h b/attrib/att-database.h index 3e854aa5..e022eeca 100644 --- a/attrib/att-database.h +++ b/attrib/att-database.h @@ -31,13 +31,13 @@ enum { struct attribute { uint16_t handle; bt_uuid_t uuid; - int read_reqs; - int write_reqs; + size_t read_reqs; + size_t write_reqs; uint8_t (*read_cb)(struct attribute *a, struct btd_device *device, gpointer user_data); uint8_t (*write_cb)(struct attribute *a, struct btd_device *device, gpointer user_data); gpointer cb_user_data; - int len; + size_t len; uint8_t *data; }; diff --git a/attrib/att.c b/attrib/att.c index 20a8efab..fc510f4f 100644 --- a/attrib/att.c +++ b/attrib/att.c @@ -114,9 +114,9 @@ struct att_data_list *att_data_list_alloc(uint16_t num, uint16_t len) } uint16_t enc_read_by_grp_req(uint16_t start, uint16_t end, bt_uuid_t *uuid, - uint8_t *pdu, int len) + uint8_t *pdu, size_t len) { - const uint16_t min_len = sizeof(pdu[0]) + sizeof(start) + sizeof(end); + uint16_t min_len = sizeof(pdu[0]) + sizeof(start) + sizeof(end); uint16_t length; if (!uuid) @@ -141,7 +141,7 @@ uint16_t enc_read_by_grp_req(uint16_t start, uint16_t end, bt_uuid_t *uuid, return min_len + length; } -uint16_t dec_read_by_grp_req(const uint8_t *pdu, int len, uint16_t *start, +uint16_t dec_read_by_grp_req(const uint8_t *pdu, size_t len, uint16_t *start, uint16_t *end, bt_uuid_t *uuid) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(*start) + sizeof(*end); @@ -169,7 +169,7 @@ uint16_t dec_read_by_grp_req(const uint8_t *pdu, int len, uint16_t *start, } uint16_t enc_read_by_grp_resp(struct att_data_list *list, uint8_t *pdu, - int len) + size_t len) { int i; uint16_t w; @@ -178,7 +178,7 @@ uint16_t enc_read_by_grp_resp(struct att_data_list *list, uint8_t *pdu, if (list == NULL) return 0; - if (len < list->len + 2) + if (len < list->len + sizeof(uint8_t) * 2) return 0; pdu[0] = ATT_OP_READ_BY_GROUP_RESP; @@ -195,7 +195,7 @@ uint16_t enc_read_by_grp_resp(struct att_data_list *list, uint8_t *pdu, return w; } -struct att_data_list *dec_read_by_grp_resp(const uint8_t *pdu, int len) +struct att_data_list *dec_read_by_grp_resp(const uint8_t *pdu, size_t len) { struct att_data_list *list; const uint8_t *ptr; @@ -220,7 +220,8 @@ struct att_data_list *dec_read_by_grp_resp(const uint8_t *pdu, int len) } uint16_t enc_find_by_type_req(uint16_t start, uint16_t end, bt_uuid_t *uuid, - const uint8_t *value, int vlen, uint8_t *pdu, int len) + const uint8_t *value, size_t vlen, + uint8_t *pdu, size_t len) { uint16_t min_len = sizeof(pdu[0]) + sizeof(start) + sizeof(end) + sizeof(uint16_t); @@ -253,10 +254,11 @@ uint16_t enc_find_by_type_req(uint16_t start, uint16_t end, bt_uuid_t *uuid, return min_len; } -uint16_t dec_find_by_type_req(const uint8_t *pdu, int len, uint16_t *start, - uint16_t *end, bt_uuid_t *uuid, uint8_t *value, int *vlen) +uint16_t dec_find_by_type_req(const uint8_t *pdu, size_t len, uint16_t *start, + uint16_t *end, bt_uuid_t *uuid, + uint8_t *value, size_t *vlen) { - int valuelen; + size_t valuelen; uint16_t min_len = sizeof(pdu[0]) + sizeof(*start) + sizeof(*end) + sizeof(uint16_t); @@ -293,7 +295,7 @@ uint16_t dec_find_by_type_req(const uint8_t *pdu, int len, uint16_t *start, return len; } -uint16_t enc_find_by_type_resp(GSList *matches, uint8_t *pdu, int len) +uint16_t enc_find_by_type_resp(GSList *matches, uint8_t *pdu, size_t len) { GSList *l; uint16_t offset; @@ -303,8 +305,9 @@ uint16_t enc_find_by_type_resp(GSList *matches, uint8_t *pdu, int len) pdu[0] = ATT_OP_FIND_BY_TYPE_RESP; - for (l = matches, offset = 1; l && len >= (offset + 4); - l = l->next, offset += 4) { + for (l = matches, offset = 1; + l && len >= (offset + sizeof(uint16_t) * 2); + l = l->next, offset += sizeof(uint16_t) * 2) { struct att_range *range = l->data; att_put_u16(range->start, &pdu[offset]); @@ -314,11 +317,11 @@ uint16_t enc_find_by_type_resp(GSList *matches, uint8_t *pdu, int len) return offset; } -GSList *dec_find_by_type_resp(const uint8_t *pdu, int len) +GSList *dec_find_by_type_resp(const uint8_t *pdu, size_t len) { struct att_range *range; GSList *matches; - int offset; + off_t offset; if (pdu == NULL || len < 5) return NULL; @@ -326,7 +329,9 @@ GSList *dec_find_by_type_resp(const uint8_t *pdu, int len) if (pdu[0] != ATT_OP_FIND_BY_TYPE_RESP) return NULL; - for (offset = 1, matches = NULL; len >= (offset + 4); offset += 4) { + for (offset = 1, matches = NULL; + len >= (offset + sizeof(uint16_t) * 2); + offset += sizeof(uint16_t) * 2) { range = g_new0(struct att_range, 1); range->start = att_get_u16(&pdu[offset]); range->end = att_get_u16(&pdu[offset + 2]); @@ -338,9 +343,9 @@ GSList *dec_find_by_type_resp(const uint8_t *pdu, int len) } uint16_t enc_read_by_type_req(uint16_t start, uint16_t end, bt_uuid_t *uuid, - uint8_t *pdu, int len) + uint8_t *pdu, size_t len) { - const uint16_t min_len = sizeof(pdu[0]) + sizeof(start) + sizeof(end); + uint16_t min_len = sizeof(pdu[0]) + sizeof(start) + sizeof(end); uint16_t length; if (!uuid) @@ -365,7 +370,7 @@ uint16_t enc_read_by_type_req(uint16_t start, uint16_t end, bt_uuid_t *uuid, return min_len + length; } -uint16_t dec_read_by_type_req(const uint8_t *pdu, int len, uint16_t *start, +uint16_t dec_read_by_type_req(const uint8_t *pdu, size_t len, uint16_t *start, uint16_t *end, bt_uuid_t *uuid) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(*start) + sizeof(*end); @@ -393,10 +398,11 @@ uint16_t dec_read_by_type_req(const uint8_t *pdu, int len, uint16_t *start, return len; } -uint16_t enc_read_by_type_resp(struct att_data_list *list, uint8_t *pdu, int len) +uint16_t enc_read_by_type_resp(struct att_data_list *list, uint8_t *pdu, + size_t len) { uint8_t *ptr; - int i, w, l; + size_t i, w, l; if (list == NULL) return 0; @@ -419,7 +425,7 @@ uint16_t enc_read_by_type_resp(struct att_data_list *list, uint8_t *pdu, int len return w; } -struct att_data_list *dec_read_by_type_resp(const uint8_t *pdu, int len) +struct att_data_list *dec_read_by_type_resp(const uint8_t *pdu, size_t len) { struct att_data_list *list; const uint8_t *ptr; @@ -443,8 +449,8 @@ struct att_data_list *dec_read_by_type_resp(const uint8_t *pdu, int len) return list; } -uint16_t enc_write_cmd(uint16_t handle, const uint8_t *value, int vlen, - uint8_t *pdu, int len) +uint16_t enc_write_cmd(uint16_t handle, const uint8_t *value, size_t vlen, + uint8_t *pdu, size_t len) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(handle); @@ -468,8 +474,8 @@ uint16_t enc_write_cmd(uint16_t handle, const uint8_t *value, int vlen, return min_len; } -uint16_t dec_write_cmd(const uint8_t *pdu, int len, uint16_t *handle, - uint8_t *value, int *vlen) +uint16_t dec_write_cmd(const uint8_t *pdu, size_t len, uint16_t *handle, + uint8_t *value, size_t *vlen) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(*handle); @@ -492,8 +498,8 @@ uint16_t dec_write_cmd(const uint8_t *pdu, int len, uint16_t *handle, return len; } -uint16_t enc_write_req(uint16_t handle, const uint8_t *value, int vlen, - uint8_t *pdu, int len) +uint16_t enc_write_req(uint16_t handle, const uint8_t *value, size_t vlen, + uint8_t *pdu, size_t len) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(handle); @@ -517,8 +523,8 @@ uint16_t enc_write_req(uint16_t handle, const uint8_t *value, int vlen, return min_len; } -uint16_t dec_write_req(const uint8_t *pdu, int len, uint16_t *handle, - uint8_t *value, int *vlen) +uint16_t dec_write_req(const uint8_t *pdu, size_t len, uint16_t *handle, + uint8_t *value, size_t *vlen) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(*handle); @@ -542,7 +548,7 @@ uint16_t dec_write_req(const uint8_t *pdu, int len, uint16_t *handle, return len; } -uint16_t enc_write_resp(uint8_t *pdu, int len) +uint16_t enc_write_resp(uint8_t *pdu, size_t len) { if (pdu == NULL) return 0; @@ -552,7 +558,7 @@ uint16_t enc_write_resp(uint8_t *pdu, int len) return sizeof(pdu[0]); } -uint16_t dec_write_resp(const uint8_t *pdu, int len) +uint16_t dec_write_resp(const uint8_t *pdu, size_t len) { if (pdu == NULL) return 0; @@ -563,7 +569,7 @@ uint16_t dec_write_resp(const uint8_t *pdu, int len) return len; } -uint16_t enc_read_req(uint16_t handle, uint8_t *pdu, int len) +uint16_t enc_read_req(uint16_t handle, uint8_t *pdu, size_t len) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(handle); @@ -580,7 +586,7 @@ uint16_t enc_read_req(uint16_t handle, uint8_t *pdu, int len) } uint16_t enc_read_blob_req(uint16_t handle, uint16_t offset, uint8_t *pdu, - int len) + size_t len) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(handle) + sizeof(offset); @@ -598,7 +604,7 @@ uint16_t enc_read_blob_req(uint16_t handle, uint16_t offset, uint8_t *pdu, return min_len; } -uint16_t dec_read_req(const uint8_t *pdu, int len, uint16_t *handle) +uint16_t dec_read_req(const uint8_t *pdu, size_t len, uint16_t *handle) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(*handle); @@ -619,7 +625,7 @@ uint16_t dec_read_req(const uint8_t *pdu, int len, uint16_t *handle) return min_len; } -uint16_t dec_read_blob_req(const uint8_t *pdu, int len, uint16_t *handle, +uint16_t dec_read_blob_req(const uint8_t *pdu, size_t len, uint16_t *handle, uint16_t *offset) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(*handle) + @@ -646,7 +652,7 @@ uint16_t dec_read_blob_req(const uint8_t *pdu, int len, uint16_t *handle, return min_len; } -uint16_t enc_read_resp(uint8_t *value, int vlen, uint8_t *pdu, int len) +uint16_t enc_read_resp(uint8_t *value, size_t vlen, uint8_t *pdu, size_t len) { if (pdu == NULL) return 0; @@ -664,8 +670,8 @@ uint16_t enc_read_resp(uint8_t *value, int vlen, uint8_t *pdu, int len) return vlen + 1; } -uint16_t enc_read_blob_resp(uint8_t *value, int vlen, uint16_t offset, - uint8_t *pdu, int len) +uint16_t enc_read_blob_resp(uint8_t *value, size_t vlen, uint16_t offset, + uint8_t *pdu, size_t len) { if (pdu == NULL) return 0; @@ -681,7 +687,7 @@ uint16_t enc_read_blob_resp(uint8_t *value, int vlen, uint16_t offset, return vlen + 1; } -ssize_t dec_read_resp(const uint8_t *pdu, int len, uint8_t *value, int vlen) +ssize_t dec_read_resp(const uint8_t *pdu, size_t len, uint8_t *value, size_t vlen) { if (pdu == NULL) return -EINVAL; @@ -701,7 +707,7 @@ ssize_t dec_read_resp(const uint8_t *pdu, int len, uint8_t *value, int vlen) } uint16_t enc_error_resp(uint8_t opcode, uint16_t handle, uint8_t status, - uint8_t *pdu, int len) + uint8_t *pdu, size_t len) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(opcode) + sizeof(handle) + sizeof(status); @@ -719,7 +725,7 @@ uint16_t enc_error_resp(uint8_t opcode, uint16_t handle, uint8_t status, return min_len; } -uint16_t enc_find_info_req(uint16_t start, uint16_t end, uint8_t *pdu, int len) +uint16_t enc_find_info_req(uint16_t start, uint16_t end, uint8_t *pdu, size_t len) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(start) + sizeof(end); @@ -736,7 +742,7 @@ uint16_t enc_find_info_req(uint16_t start, uint16_t end, uint8_t *pdu, int len) return min_len; } -uint16_t dec_find_info_req(const uint8_t *pdu, int len, uint16_t *start, +uint16_t dec_find_info_req(const uint8_t *pdu, size_t len, uint16_t *start, uint16_t *end) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(*start) + sizeof(*end); @@ -760,10 +766,10 @@ uint16_t dec_find_info_req(const uint8_t *pdu, int len, uint16_t *start, } uint16_t enc_find_info_resp(uint8_t format, struct att_data_list *list, - uint8_t *pdu, int len) + uint8_t *pdu, size_t len) { uint8_t *ptr; - int i, w; + size_t i, w; if (pdu == NULL) return 0; @@ -771,7 +777,7 @@ uint16_t enc_find_info_resp(uint8_t format, struct att_data_list *list, if (list == NULL) return 0; - if (len < list->len + 2) + if (len < list->len + sizeof(uint8_t) * 2) return 0; pdu[0] = ATT_OP_FIND_INFO_RESP; @@ -787,7 +793,7 @@ uint16_t enc_find_info_resp(uint8_t format, struct att_data_list *list, return w; } -struct att_data_list *dec_find_info_resp(const uint8_t *pdu, int len, +struct att_data_list *dec_find_info_resp(const uint8_t *pdu, size_t len, uint8_t *format) { struct att_data_list *list; @@ -825,8 +831,8 @@ struct att_data_list *dec_find_info_resp(const uint8_t *pdu, int len, return list; } -uint16_t enc_notification(uint16_t handle, uint8_t *value, int vlen, - uint8_t *pdu, int len) +uint16_t enc_notification(uint16_t handle, uint8_t *value, size_t vlen, + uint8_t *pdu, size_t len) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(uint16_t); @@ -843,8 +849,8 @@ uint16_t enc_notification(uint16_t handle, uint8_t *value, int vlen, return vlen + min_len; } -uint16_t enc_indication(uint16_t handle, uint8_t *value, int vlen, - uint8_t *pdu, int len) +uint16_t enc_indication(uint16_t handle, uint8_t *value, size_t vlen, + uint8_t *pdu, size_t len) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(uint16_t); @@ -861,8 +867,8 @@ uint16_t enc_indication(uint16_t handle, uint8_t *value, int vlen, return vlen + min_len; } -uint16_t dec_indication(const uint8_t *pdu, int len, uint16_t *handle, - uint8_t *value, int vlen) +uint16_t dec_indication(const uint8_t *pdu, size_t len, uint16_t *handle, + uint8_t *value, size_t vlen) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(uint16_t); uint16_t dlen; @@ -886,7 +892,7 @@ uint16_t dec_indication(const uint8_t *pdu, int len, uint16_t *handle, return dlen; } -uint16_t enc_confirmation(uint8_t *pdu, int len) +uint16_t enc_confirmation(uint8_t *pdu, size_t len) { const uint16_t min_len = sizeof(pdu[0]); @@ -901,7 +907,7 @@ uint16_t enc_confirmation(uint8_t *pdu, int len) return min_len; } -uint16_t enc_mtu_req(uint16_t mtu, uint8_t *pdu, int len) +uint16_t enc_mtu_req(uint16_t mtu, uint8_t *pdu, size_t len) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(mtu); @@ -917,7 +923,7 @@ uint16_t enc_mtu_req(uint16_t mtu, uint8_t *pdu, int len) return min_len; } -uint16_t dec_mtu_req(const uint8_t *pdu, int len, uint16_t *mtu) +uint16_t dec_mtu_req(const uint8_t *pdu, size_t len, uint16_t *mtu) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(*mtu); @@ -938,7 +944,7 @@ uint16_t dec_mtu_req(const uint8_t *pdu, int len, uint16_t *mtu) return min_len; } -uint16_t enc_mtu_resp(uint16_t mtu, uint8_t *pdu, int len) +uint16_t enc_mtu_resp(uint16_t mtu, uint8_t *pdu, size_t len) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(mtu); @@ -954,7 +960,7 @@ uint16_t enc_mtu_resp(uint16_t mtu, uint8_t *pdu, int len) return min_len; } -uint16_t dec_mtu_resp(const uint8_t *pdu, int len, uint16_t *mtu) +uint16_t dec_mtu_resp(const uint8_t *pdu, size_t len, uint16_t *mtu) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(*mtu); @@ -976,7 +982,7 @@ uint16_t dec_mtu_resp(const uint8_t *pdu, int len, uint16_t *mtu) } uint16_t enc_prep_write_req(uint16_t handle, uint16_t offset, - const uint8_t *value, int vlen, uint8_t *pdu, int len) + const uint8_t *value, size_t vlen, uint8_t *pdu, size_t len) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(handle) + sizeof(offset); @@ -1002,8 +1008,8 @@ uint16_t enc_prep_write_req(uint16_t handle, uint16_t offset, return min_len; } -uint16_t dec_prep_write_resp(const uint8_t *pdu, int len, uint16_t *handle, - uint16_t *offset, uint8_t *value, int *vlen) +uint16_t dec_prep_write_resp(const uint8_t *pdu, size_t len, uint16_t *handle, + uint16_t *offset, uint8_t *value, size_t *vlen) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(*handle) + sizeof(*offset); @@ -1029,7 +1035,7 @@ uint16_t dec_prep_write_resp(const uint8_t *pdu, int len, uint16_t *handle, return len; } -uint16_t enc_exec_write_req(uint8_t flags, uint8_t *pdu, int len) +uint16_t enc_exec_write_req(uint8_t flags, uint8_t *pdu, size_t len) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(flags); @@ -1048,7 +1054,7 @@ uint16_t enc_exec_write_req(uint8_t flags, uint8_t *pdu, int len) return min_len; } -uint16_t dec_exec_write_resp(const uint8_t *pdu, int len) +uint16_t dec_exec_write_resp(const uint8_t *pdu, size_t len) { const uint16_t min_len = sizeof(pdu[0]); diff --git a/attrib/att.h b/attrib/att.h index e7a29cbc..9384be53 100644 --- a/attrib/att.h +++ b/attrib/att.h @@ -201,69 +201,75 @@ void att_data_list_free(struct att_data_list *list); const char *att_ecode2str(uint8_t status); uint16_t enc_read_by_grp_req(uint16_t start, uint16_t end, bt_uuid_t *uuid, - uint8_t *pdu, int len); -uint16_t dec_read_by_grp_req(const uint8_t *pdu, int len, uint16_t *start, - uint16_t *end, bt_uuid_t *uuid); -uint16_t enc_read_by_grp_resp(struct att_data_list *list, uint8_t *pdu, int len); + uint8_t *pdu, size_t len); +uint16_t dec_read_by_grp_req(const uint8_t *pdu, size_t len, uint16_t *start, + uint16_t *end, bt_uuid_t *uuid); +uint16_t enc_read_by_grp_resp(struct att_data_list *list, uint8_t *pdu, + size_t len); uint16_t enc_find_by_type_req(uint16_t start, uint16_t end, bt_uuid_t *uuid, - const uint8_t *value, int vlen, uint8_t *pdu, int len); -uint16_t dec_find_by_type_req(const uint8_t *pdu, int len, uint16_t *start, - uint16_t *end, bt_uuid_t *uuid, uint8_t *value, int *vlen); -uint16_t enc_find_by_type_resp(GSList *ranges, uint8_t *pdu, int len); -GSList *dec_find_by_type_resp(const uint8_t *pdu, int len); -struct att_data_list *dec_read_by_grp_resp(const uint8_t *pdu, int len); + const uint8_t *value, size_t vlen, uint8_t *pdu, + size_t len); +uint16_t dec_find_by_type_req(const uint8_t *pdu, size_t len, uint16_t *start, + uint16_t *end, bt_uuid_t *uuid, uint8_t *value, size_t *vlen); +uint16_t enc_find_by_type_resp(GSList *ranges, uint8_t *pdu, size_t len); +GSList *dec_find_by_type_resp(const uint8_t *pdu, size_t len); +struct att_data_list *dec_read_by_grp_resp(const uint8_t *pdu, size_t len); uint16_t enc_read_by_type_req(uint16_t start, uint16_t end, bt_uuid_t *uuid, - uint8_t *pdu, int len); -uint16_t dec_read_by_type_req(const uint8_t *pdu, int len, uint16_t *start, - uint16_t *end, bt_uuid_t *uuid); + uint8_t *pdu, size_t len); +uint16_t dec_read_by_type_req(const uint8_t *pdu, size_t len, uint16_t *start, + uint16_t *end, bt_uuid_t *uuid); uint16_t enc_read_by_type_resp(struct att_data_list *list, uint8_t *pdu, - int len); -uint16_t enc_write_cmd(uint16_t handle, const uint8_t *value, int vlen, - uint8_t *pdu, int len); -uint16_t dec_write_cmd(const uint8_t *pdu, int len, uint16_t *handle, - uint8_t *value, int *vlen); -struct att_data_list *dec_read_by_type_resp(const uint8_t *pdu, int len); -uint16_t enc_write_req(uint16_t handle, const uint8_t *value, int vlen, - uint8_t *pdu, int len); -uint16_t dec_write_req(const uint8_t *pdu, int len, uint16_t *handle, - uint8_t *value, int *vlen); -uint16_t enc_write_resp(uint8_t *pdu, int len); -uint16_t dec_write_resp(const uint8_t *pdu, int len); -uint16_t enc_read_req(uint16_t handle, uint8_t *pdu, int len); + size_t len); +uint16_t enc_write_cmd(uint16_t handle, const uint8_t *value, size_t vlen, + uint8_t *pdu, size_t len); +uint16_t dec_write_cmd(const uint8_t *pdu, size_t len, uint16_t *handle, + uint8_t *value, size_t *vlen); +struct att_data_list *dec_read_by_type_resp(const uint8_t *pdu, size_t len); +uint16_t enc_write_req(uint16_t handle, const uint8_t *value, size_t vlen, + uint8_t *pdu, size_t len); +uint16_t dec_write_req(const uint8_t *pdu, size_t len, uint16_t *handle, + uint8_t *value, size_t *vlen); +uint16_t enc_write_resp(uint8_t *pdu, size_t len); +uint16_t dec_write_resp(const uint8_t *pdu, size_t len); +uint16_t enc_read_req(uint16_t handle, uint8_t *pdu, size_t len); uint16_t enc_read_blob_req(uint16_t handle, uint16_t offset, uint8_t *pdu, - int len); -uint16_t dec_read_req(const uint8_t *pdu, int len, uint16_t *handle); -uint16_t dec_read_blob_req(const uint8_t *pdu, int len, uint16_t *handle, + size_t len); +uint16_t dec_read_req(const uint8_t *pdu, size_t len, uint16_t *handle); +uint16_t dec_read_blob_req(const uint8_t *pdu, size_t len, uint16_t *handle, uint16_t *offset); -uint16_t enc_read_resp(uint8_t *value, int vlen, uint8_t *pdu, int len); -uint16_t enc_read_blob_resp(uint8_t *value, int vlen, uint16_t offset, - uint8_t *pdu, int len); -ssize_t dec_read_resp(const uint8_t *pdu, int len, uint8_t *value, int vlen); +uint16_t enc_read_resp(uint8_t *value, size_t vlen, uint8_t *pdu, size_t len); +uint16_t enc_read_blob_resp(uint8_t *value, size_t vlen, uint16_t offset, + uint8_t *pdu, size_t len); +ssize_t dec_read_resp(const uint8_t *pdu, size_t len, uint8_t *value, + size_t vlen); uint16_t enc_error_resp(uint8_t opcode, uint16_t handle, uint8_t status, - uint8_t *pdu, int len); -uint16_t enc_find_info_req(uint16_t start, uint16_t end, uint8_t *pdu, int len); -uint16_t dec_find_info_req(const uint8_t *pdu, int len, uint16_t *start, + uint8_t *pdu, size_t len); +uint16_t enc_find_info_req(uint16_t start, uint16_t end, uint8_t *pdu, + size_t len); +uint16_t dec_find_info_req(const uint8_t *pdu, size_t len, uint16_t *start, uint16_t *end); uint16_t enc_find_info_resp(uint8_t format, struct att_data_list *list, - uint8_t *pdu, int len); -struct att_data_list *dec_find_info_resp(const uint8_t *pdu, int len, + uint8_t *pdu, size_t len); +struct att_data_list *dec_find_info_resp(const uint8_t *pdu, size_t len, uint8_t *format); -uint16_t enc_notification(uint16_t handle, uint8_t *value, int vlen, - uint8_t *pdu, int len); -uint16_t enc_indication(uint16_t handle, uint8_t *value, int vlen, - uint8_t *pdu, int len); -uint16_t dec_indication(const uint8_t *pdu, int len, uint16_t *handle, - uint8_t *value, int vlen); -uint16_t enc_confirmation(uint8_t *pdu, int len); - -uint16_t enc_mtu_req(uint16_t mtu, uint8_t *pdu, int len); -uint16_t dec_mtu_req(const uint8_t *pdu, int len, uint16_t *mtu); -uint16_t enc_mtu_resp(uint16_t mtu, uint8_t *pdu, int len); -uint16_t dec_mtu_resp(const uint8_t *pdu, int len, uint16_t *mtu); +uint16_t enc_notification(uint16_t handle, uint8_t *value, size_t vlen, + uint8_t *pdu, size_t len); +uint16_t enc_indication(uint16_t handle, uint8_t *value, size_t vlen, + uint8_t *pdu, size_t len); +uint16_t dec_indication(const uint8_t *pdu, size_t len, uint16_t *handle, + uint8_t *value, size_t vlen); +uint16_t enc_confirmation(uint8_t *pdu, size_t len); + +uint16_t enc_mtu_req(uint16_t mtu, uint8_t *pdu, size_t len); +uint16_t dec_mtu_req(const uint8_t *pdu, size_t len, uint16_t *mtu); +uint16_t enc_mtu_resp(uint16_t mtu, uint8_t *pdu, size_t len); +uint16_t dec_mtu_resp(const uint8_t *pdu, size_t len, uint16_t *mtu); uint16_t enc_prep_write_req(uint16_t handle, uint16_t offset, - const uint8_t *value, int vlen, uint8_t *pdu, int len); -uint16_t dec_prep_write_resp(const uint8_t *pdu, int len, uint16_t *handle, - uint16_t *offset, uint8_t *value, int *vlen); -uint16_t enc_exec_write_req(uint8_t flags, uint8_t *pdu, int len); -uint16_t dec_exec_write_resp(const uint8_t *pdu, int len); + const uint8_t *value, size_t vlen, + uint8_t *pdu, size_t len); +uint16_t dec_prep_write_resp(const uint8_t *pdu, size_t len, uint16_t *handle, + uint16_t *offset, uint8_t *value, + size_t *vlen); +uint16_t enc_exec_write_req(uint8_t flags, uint8_t *pdu, size_t len); +uint16_t dec_exec_write_resp(const uint8_t *pdu, size_t len); diff --git a/attrib/client.c b/attrib/client.c index d9c1a2ac..c438d7ca 100644 --- a/attrib/client.c +++ b/attrib/client.c @@ -272,7 +272,7 @@ static void events_handler(const uint8_t *pdu, uint16_t len, uint8_t *opdu; guint handle; uint16_t olen; - int plen; + size_t plen; if (len < 3) { DBG("Malformed notification/indication packet (opcode 0x%02x)", diff --git a/attrib/gatt.c b/attrib/gatt.c index b7eb7368..9ab283f0 100644 --- a/attrib/gatt.c +++ b/attrib/gatt.c @@ -84,7 +84,7 @@ static guint16 encode_discover_primary(uint16_t start, uint16_t end, uint16_t u16; uint128_t u128; const void *value; - int vlen; + size_t vlen; /* Discover primary service by service UUID */ @@ -114,7 +114,8 @@ static void primary_by_uuid_cb(guint8 status, const guint8 *ipdu, struct att_range *range; uint8_t *buf; guint16 oplen; - int err = 0, buflen; + int err = 0; + size_t buflen; if (status) { err = status == ATT_ECODE_ATTR_NOT_FOUND ? 0 : status; @@ -201,7 +202,7 @@ static void primary_all_cb(guint8 status, const guint8 *ipdu, guint16 iplen, err = 0; if (end != 0xffff) { - int buflen; + size_t buflen; uint8_t *buf = g_attrib_get_buffer(dp->attrib, &buflen); guint16 oplen = encode_discover_primary(end + 1, 0xffff, NULL, buf, buflen); @@ -221,7 +222,7 @@ guint gatt_discover_primary(GAttrib *attrib, bt_uuid_t *uuid, gatt_cb_t func, gpointer user_data) { struct discover_primary *dp; - int buflen; + size_t buflen; uint8_t *buf = g_attrib_get_buffer(attrib, &buflen); GAttribResultFunc cb; guint16 plen; @@ -253,7 +254,7 @@ static void char_discovered_cb(guint8 status, const guint8 *ipdu, guint16 iplen, struct discover_char *dc = user_data; struct att_data_list *list; unsigned int i, err; - int buflen; + size_t buflen; uint8_t *buf; guint16 oplen; bt_uuid_t uuid; @@ -329,7 +330,7 @@ guint gatt_discover_char(GAttrib *attrib, uint16_t start, uint16_t end, bt_uuid_t *uuid, gatt_cb_t func, gpointer user_data) { - int buflen; + size_t buflen; uint8_t *buf = g_attrib_get_buffer(attrib, &buflen); struct discover_char *dc; bt_uuid_t type_uuid; @@ -359,7 +360,7 @@ guint gatt_read_char_by_uuid(GAttrib *attrib, uint16_t start, uint16_t end, bt_uuid_t *uuid, GAttribResultFunc func, gpointer user_data) { - int buflen; + size_t buflen; uint8_t *buf = g_attrib_get_buffer(attrib, &buflen); guint16 plen; @@ -400,7 +401,7 @@ static void read_blob_helper(guint8 status, const guint8 *rpdu, guint16 rlen, { struct read_long_data *long_read = user_data; uint8_t *buf; - int buflen; + size_t buflen; guint8 *tmp; guint16 plen; guint id; @@ -447,7 +448,7 @@ static void read_char_helper(guint8 status, const guint8 *rpdu, guint16 rlen, gpointer user_data) { struct read_long_data *long_read = user_data; - int buflen; + size_t buflen; uint8_t *buf = g_attrib_get_buffer(long_read->attrib, &buflen); guint16 plen; guint id; @@ -483,7 +484,7 @@ guint gatt_read_char(GAttrib *attrib, uint16_t handle, uint16_t offset, GAttribResultFunc func, gpointer user_data) { uint8_t *buf; - int buflen; + size_t buflen; guint16 plen; guint id; struct read_long_data *long_read; @@ -527,14 +528,14 @@ struct write_long_data { guint16 handle; uint16_t offset; uint8_t *value; - int vlen; + size_t vlen; }; static guint execute_write(GAttrib *attrib, uint8_t flags, GAttribResultFunc func, gpointer user_data) { uint8_t *buf; - int buflen; + size_t buflen; guint16 plen; buf = g_attrib_get_buffer(attrib, &buflen); @@ -547,7 +548,7 @@ static guint execute_write(GAttrib *attrib, uint8_t flags, } static guint prepare_write(GAttrib *attrib, uint16_t handle, uint16_t offset, - uint8_t *value, int vlen, GAttribResultFunc func, + uint8_t *value, size_t vlen, GAttribResultFunc func, gpointer user_data); static void prepare_write_cb(guint8 status, const guint8 *rpdu, @@ -578,11 +579,11 @@ static void prepare_write_cb(guint8 status, const guint8 *rpdu, } static guint prepare_write(GAttrib *attrib, uint16_t handle, uint16_t offset, - uint8_t *value, int vlen, GAttribResultFunc func, + uint8_t *value, size_t vlen, GAttribResultFunc func, gpointer user_data) { guint16 plen; - int buflen; + size_t buflen; uint8_t *buf; buf = g_attrib_get_buffer(attrib, &buflen); @@ -597,10 +598,10 @@ static guint prepare_write(GAttrib *attrib, uint16_t handle, uint16_t offset, } guint gatt_write_char(GAttrib *attrib, uint16_t handle, uint8_t *value, - int vlen, GAttribResultFunc func, gpointer user_data) + size_t vlen, GAttribResultFunc func, gpointer user_data) { uint8_t *buf; - int buflen; + size_t buflen; guint16 plen; struct write_long_data *long_write; @@ -629,7 +630,7 @@ guint gatt_write_char(GAttrib *attrib, uint16_t handle, uint8_t *value, long_write->func = func; long_write->user_data = user_data; long_write->handle = handle; - long_write->value = g_memdup(value,vlen); + long_write->value = g_memdup(value, vlen); long_write->vlen = vlen; return prepare_write(attrib, handle, long_write->offset, value, vlen, @@ -640,7 +641,7 @@ guint gatt_exchange_mtu(GAttrib *attrib, uint16_t mtu, GAttribResultFunc func, gpointer user_data) { uint8_t *buf; - int buflen; + size_t buflen; guint16 plen; buf = g_attrib_get_buffer(attrib, &buflen); @@ -653,7 +654,7 @@ guint gatt_find_info(GAttrib *attrib, uint16_t start, uint16_t end, GAttribResultFunc func, gpointer user_data) { uint8_t *buf; - int buflen; + size_t buflen; guint16 plen; buf = g_attrib_get_buffer(attrib, &buflen); @@ -669,7 +670,7 @@ guint gatt_write_cmd(GAttrib *attrib, uint16_t handle, uint8_t *value, int vlen, GDestroyNotify notify, gpointer user_data) { uint8_t *buf; - int buflen; + size_t buflen; guint16 plen; buf = g_attrib_get_buffer(attrib, &buflen); diff --git a/attrib/gatt.h b/attrib/gatt.h index aab93b62..7690fba7 100644 --- a/attrib/gatt.h +++ b/attrib/gatt.h @@ -78,7 +78,8 @@ guint gatt_read_char(GAttrib *attrib, uint16_t handle, uint16_t offset, GAttribResultFunc func, gpointer user_data); guint gatt_write_char(GAttrib *attrib, uint16_t handle, uint8_t *value, - int vlen, GAttribResultFunc func, gpointer user_data); + size_t vlen, GAttribResultFunc func, + gpointer user_data); guint gatt_find_info(GAttrib *attrib, uint16_t start, uint16_t end, GAttribResultFunc func, gpointer user_data); diff --git a/attrib/gattrib.c b/attrib/gattrib.c index 00f59d70..c91f5e98 100644 --- a/attrib/gattrib.c +++ b/attrib/gattrib.c @@ -42,7 +42,7 @@ struct _GAttrib { GIOChannel *io; gint refs; uint8_t *buf; - int buflen; + size_t buflen; guint read_watch; guint write_watch; guint timeout_watch; @@ -617,7 +617,7 @@ gboolean g_attrib_set_debug(GAttrib *attrib, return TRUE; } -uint8_t *g_attrib_get_buffer(GAttrib *attrib, int *len) +uint8_t *g_attrib_get_buffer(GAttrib *attrib, size_t *len) { if (len == NULL) return NULL; diff --git a/attrib/gattrib.h b/attrib/gattrib.h index f73b7416..bcff0398 100644 --- a/attrib/gattrib.h +++ b/attrib/gattrib.h @@ -66,7 +66,7 @@ guint g_attrib_register(GAttrib *attrib, guint8 opcode, gboolean g_attrib_is_encrypted(GAttrib *attrib); -uint8_t *g_attrib_get_buffer(GAttrib *attrib, int *len); +uint8_t *g_attrib_get_buffer(GAttrib *attrib, size_t *len); gboolean g_attrib_set_mtu(GAttrib *attrib, int mtu); gboolean g_attrib_unregister(GAttrib *attrib, guint id); diff --git a/attrib/gatttool.c b/attrib/gatttool.c index a11ca9fc..416bb711 100644 --- a/attrib/gatttool.c +++ b/attrib/gatttool.c @@ -77,7 +77,7 @@ static void events_handler(const uint8_t *pdu, uint16_t len, gpointer user_data) GAttrib *attrib = user_data; uint8_t *opdu; uint16_t handle, i, olen = 0; - int plen; + size_t plen; handle = att_get_u16(&pdu[1]); diff --git a/attrib/interactive.c b/attrib/interactive.c index 6cd8bd55..3e8a0d9c 100644 --- a/attrib/interactive.c +++ b/attrib/interactive.c @@ -103,7 +103,7 @@ static void events_handler(const uint8_t *pdu, uint16_t len, gpointer user_data) { uint8_t *opdu; uint16_t handle, i, olen; - int plen; + size_t plen; handle = att_get_u16(&pdu[1]); diff --git a/profiles/thermometer/thermometer.c b/profiles/thermometer/thermometer.c index 087662ef..ad352a95 100644 --- a/profiles/thermometer/thermometer.c +++ b/profiles/thermometer/thermometer.c @@ -1142,7 +1142,7 @@ static void ind_handler(const uint8_t *pdu, uint16_t len, gpointer user_data) uint8_t *opdu; uint16_t handle, olen; GSList *l; - int plen; + size_t plen; if (len < 3) { DBG("Bad pdu received"); diff --git a/profiles/time/server.c b/profiles/time/server.c index d38b9b85..db970565 100644 --- a/profiles/time/server.c +++ b/profiles/time/server.c @@ -151,7 +151,7 @@ static uint8_t time_update_control(struct attribute *a, DBG("handle 0x%04x", a->handle); if (a->len != 1) - DBG("Invalid control point value size: %d", a->len); + DBG("Invalid control point value size: %zu", a->len); switch (a->data[0]) { case GET_REFERENCE_UPDATE: diff --git a/src/attrib-server.c b/src/attrib-server.c index 9064d15c..bbed1a90 100644 --- a/src/attrib-server.c +++ b/src/attrib-server.c @@ -338,8 +338,9 @@ static uint32_t attrib_create_sdp_new(struct gatt_server *server, } static struct attribute *attrib_db_add_new(struct gatt_server *server, - uint16_t handle, bt_uuid_t *uuid, int read_reqs, - int write_reqs, const uint8_t *value, int len) + uint16_t handle, bt_uuid_t *uuid, + size_t read_reqs, size_t write_reqs, + const uint8_t *value, size_t len) { struct attribute *a; guint h = handle; @@ -400,7 +401,7 @@ static uint8_t att_check_reqs(struct gatt_channel *channel, uint8_t opcode, static uint16_t read_by_group(struct gatt_channel *channel, uint16_t start, uint16_t end, bt_uuid_t *uuid, - uint8_t *pdu, int len) + uint8_t *pdu, size_t len) { struct att_data_list *adl; struct attribute *a; @@ -516,7 +517,7 @@ static uint16_t read_by_group(struct gatt_channel *channel, uint16_t start, static uint16_t read_by_type(struct gatt_channel *channel, uint16_t start, uint16_t end, bt_uuid_t *uuid, - uint8_t *pdu, int len) + uint8_t *pdu, size_t len) { struct att_data_list *adl; GSList *l, *types; @@ -598,8 +599,8 @@ static uint16_t read_by_type(struct gatt_channel *channel, uint16_t start, return length; } -static int find_info(struct gatt_channel *channel, uint16_t start, uint16_t end, - uint8_t *pdu, int len) +static uint16_t find_info(struct gatt_channel *channel, uint16_t start, + uint16_t end, uint8_t *pdu, size_t len) { struct attribute *a; struct att_data_list *adl; @@ -673,15 +674,16 @@ static int find_info(struct gatt_channel *channel, uint16_t start, uint16_t end, return length; } -static int find_by_type(struct gatt_channel *channel, uint16_t start, - uint16_t end, bt_uuid_t *uuid, const uint8_t *value, - int vlen, uint8_t *opdu, int mtu) +static uint16_t find_by_type(struct gatt_channel *channel, uint16_t start, + uint16_t end, bt_uuid_t *uuid, + const uint8_t *value, size_t vlen, + uint8_t *opdu, size_t mtu) { struct attribute *a; struct att_range *range; GSList *matches; GList *dl, *database; - int len; + uint16_t len; if (start > end || start == 0x0000) return enc_error_resp(ATT_OP_FIND_BY_TYPE_REQ, start, @@ -733,7 +735,7 @@ static int find_by_type(struct gatt_channel *channel, uint16_t start, } static uint16_t read_value(struct gatt_channel *channel, uint16_t handle, - uint8_t *pdu, int len) + uint8_t *pdu, size_t len) { struct attribute *a; uint8_t status; @@ -774,7 +776,7 @@ static uint16_t read_value(struct gatt_channel *channel, uint16_t handle, } static uint16_t read_blob(struct gatt_channel *channel, uint16_t handle, - uint16_t offset, uint8_t *pdu, int len) + uint16_t offset, uint8_t *pdu, size_t len) { struct attribute *a; uint8_t status; @@ -820,8 +822,8 @@ static uint16_t read_blob(struct gatt_channel *channel, uint16_t handle, } static uint16_t write_value(struct gatt_channel *channel, uint16_t handle, - const uint8_t *value, int vlen, - uint8_t *pdu, int len) + const uint8_t *value, size_t vlen, + uint8_t *pdu, size_t len) { struct attribute *a; uint8_t status; @@ -865,7 +867,7 @@ static uint16_t write_value(struct gatt_channel *channel, uint16_t handle, } static uint16_t mtu_exchange(struct gatt_channel *channel, uint16_t mtu, - uint8_t *pdu, int len) + uint8_t *pdu, size_t len) { GError *gerr = NULL; GIOChannel *io; @@ -914,7 +916,7 @@ static void channel_handler(const uint8_t *ipdu, uint16_t len, uint16_t length, start, end, mtu, offset; bt_uuid_t uuid; uint8_t status = 0; - int vlen; + size_t vlen; DBG("op 0x%02x", ipdu[0]); @@ -1429,8 +1431,9 @@ uint16_t attrib_db_find_avail(struct btd_adapter *adapter, bt_uuid_t *svc_uuid, } struct attribute *attrib_db_add(struct btd_adapter *adapter, uint16_t handle, - bt_uuid_t *uuid, int read_reqs, int write_reqs, - const uint8_t *value, int len) + bt_uuid_t *uuid, size_t read_reqs, + size_t write_reqs, + const uint8_t *value, size_t len) { GSList *l; @@ -1444,7 +1447,7 @@ struct attribute *attrib_db_add(struct btd_adapter *adapter, uint16_t handle, int attrib_db_update(struct btd_adapter *adapter, uint16_t handle, bt_uuid_t *uuid, const uint8_t *value, - int len, struct attribute **attr) + size_t len, struct attribute **attr) { struct gatt_server *server; struct attribute *a; @@ -1513,7 +1516,7 @@ int attrib_db_del(struct btd_adapter *adapter, uint16_t handle) } int attrib_gap_set(struct btd_adapter *adapter, uint16_t uuid, - const uint8_t *value, int len) + const uint8_t *value, size_t len) { struct gatt_server *server; uint16_t handle; diff --git a/src/attrib-server.h b/src/attrib-server.h index 7af0cfaa..3ec62ed1 100644 --- a/src/attrib-server.h +++ b/src/attrib-server.h @@ -25,14 +25,15 @@ uint16_t attrib_db_find_avail(struct btd_adapter *adapter, bt_uuid_t *svc_uuid, uint16_t nitems); struct attribute *attrib_db_add(struct btd_adapter *adapter, uint16_t handle, - bt_uuid_t *uuid, int read_reqs, int write_reqs, - const uint8_t *value, int len); + bt_uuid_t *uuid, size_t read_reqs, + size_t write_reqs, const uint8_t *value, + size_t len); int attrib_db_update(struct btd_adapter *adapter, uint16_t handle, bt_uuid_t *uuid, const uint8_t *value, - int len, struct attribute **attr); + size_t len, struct attribute **attr); int attrib_db_del(struct btd_adapter *adapter, uint16_t handle); int attrib_gap_set(struct btd_adapter *adapter, uint16_t uuid, - const uint8_t *value, int len); + const uint8_t *value, size_t len); uint32_t attrib_create_sdp(struct btd_adapter *adapter, uint16_t handle, const char *name); void attrib_free_sdp(uint32_t sdp_handle); |