Bluetooth: Take advantage of net_buf_pull_mem()
Convert the remaining places of the host stack where net_buf_pull_mem() makes more sense than net_buf_pull(). Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
c10b9ac228
commit
fe7f1e17de
|
@ -624,12 +624,12 @@ static u8_t att_find_type_req(struct bt_att *att, struct net_buf *buf)
|
|||
u16_t start_handle, end_handle, err_handle, type;
|
||||
u8_t *value;
|
||||
|
||||
req = (void *)buf->data;
|
||||
req = net_buf_pull_mem(buf, sizeof(*req));
|
||||
|
||||
start_handle = sys_le16_to_cpu(req->start_handle);
|
||||
end_handle = sys_le16_to_cpu(req->end_handle);
|
||||
type = sys_le16_to_cpu(req->type);
|
||||
value = net_buf_pull(buf, sizeof(*req));
|
||||
value = buf->data;
|
||||
|
||||
BT_DBG("start_handle 0x%04x end_handle 0x%04x type %u", start_handle,
|
||||
end_handle, type);
|
||||
|
@ -847,11 +847,10 @@ static u8_t att_read_type_req(struct bt_att *att, struct net_buf *buf)
|
|||
return BT_ATT_ERR_INVALID_PDU;
|
||||
}
|
||||
|
||||
req = (void *)buf->data;
|
||||
req = net_buf_pull_mem(buf, sizeof(*req));
|
||||
|
||||
start_handle = sys_le16_to_cpu(req->start_handle);
|
||||
end_handle = sys_le16_to_cpu(req->end_handle);
|
||||
net_buf_pull(buf, sizeof(*req));
|
||||
|
||||
if (!uuid_create(&u.uuid, buf)) {
|
||||
return BT_ATT_ERR_UNLIKELY;
|
||||
|
@ -1149,11 +1148,10 @@ static u8_t att_read_group_req(struct bt_att *att, struct net_buf *buf)
|
|||
return BT_ATT_ERR_INVALID_PDU;
|
||||
}
|
||||
|
||||
req = (void *)buf->data;
|
||||
req = net_buf_pull_mem(buf, sizeof(*req));
|
||||
|
||||
start_handle = sys_le16_to_cpu(req->start_handle);
|
||||
end_handle = sys_le16_to_cpu(req->end_handle);
|
||||
net_buf_pull(buf, sizeof(*req));
|
||||
|
||||
if (!uuid_create(&u.uuid, buf)) {
|
||||
return BT_ATT_ERR_UNLIKELY;
|
||||
|
@ -1402,11 +1400,10 @@ static u8_t att_prepare_write_req(struct bt_att *att, struct net_buf *buf)
|
|||
struct bt_att_prepare_write_req *req;
|
||||
u16_t handle, offset;
|
||||
|
||||
req = (void *)buf->data;
|
||||
req = net_buf_pull_mem(buf, sizeof(*req));
|
||||
|
||||
handle = sys_le16_to_cpu(req->handle);
|
||||
offset = sys_le16_to_cpu(req->offset);
|
||||
net_buf_pull(buf, sizeof(*req));
|
||||
|
||||
BT_DBG("handle 0x%04x offset %u", handle, offset);
|
||||
|
||||
|
@ -1884,7 +1881,7 @@ static att_type_t att_op_get_type(u8_t op)
|
|||
static int bt_att_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
{
|
||||
struct bt_att *att = ATT_CHAN(chan);
|
||||
struct bt_att_hdr *hdr = (void *)buf->data;
|
||||
struct bt_att_hdr *hdr;
|
||||
const struct att_handler *handler;
|
||||
u8_t err;
|
||||
size_t i;
|
||||
|
@ -1894,10 +1891,9 @@ static int bt_att_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
|||
return 0;
|
||||
}
|
||||
|
||||
hdr = net_buf_pull_mem(buf, sizeof(*hdr));
|
||||
BT_DBG("Received ATT code 0x%02x len %u", hdr->code, buf->len);
|
||||
|
||||
net_buf_pull(buf, sizeof(*hdr));
|
||||
|
||||
for (i = 0, handler = NULL; i < ARRAY_SIZE(handlers); i++) {
|
||||
if (hdr->code == handlers[i].op) {
|
||||
handler = &handlers[i];
|
||||
|
|
|
@ -145,7 +145,7 @@ void bt_avdtp_l2cap_encrypt_changed(struct bt_l2cap_chan *chan, u8_t status)
|
|||
|
||||
int bt_avdtp_l2cap_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
{
|
||||
struct bt_avdtp_single_sig_hdr *hdr = (void *)buf->data;
|
||||
struct bt_avdtp_single_sig_hdr *hdr;
|
||||
struct bt_avdtp *session = AVDTP_CHAN(chan);
|
||||
u8_t i, msgtype, sigid, tid;
|
||||
|
||||
|
@ -154,13 +154,13 @@ int bt_avdtp_l2cap_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
|||
return 0;
|
||||
}
|
||||
|
||||
hdr = net_buf_pull_mem(buf, sizeof(*hdr));
|
||||
msgtype = AVDTP_GET_MSG_TYPE(hdr->hdr);
|
||||
sigid = AVDTP_GET_SIG_ID(hdr->signal_id);
|
||||
tid = AVDTP_GET_TR_ID(hdr->hdr);
|
||||
|
||||
BT_DBG("msg_type[0x%02x] sig_id[0x%02x] tid[0x%02x]",
|
||||
msgtype, sigid, tid);
|
||||
net_buf_pull(buf, sizeof(*hdr));
|
||||
|
||||
/* validate if there is an outstanding resp expected*/
|
||||
if (msgtype != BT_AVDTP_CMD) {
|
||||
|
|
|
@ -1278,7 +1278,7 @@ static void reject_cmd(struct bt_l2cap *l2cap, u8_t ident,
|
|||
static int l2cap_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
{
|
||||
struct bt_l2cap *l2cap = CONTAINER_OF(chan, struct bt_l2cap, chan);
|
||||
struct bt_l2cap_sig_hdr *hdr = (void *)buf->data;
|
||||
struct bt_l2cap_sig_hdr *hdr;
|
||||
u16_t len;
|
||||
|
||||
if (buf->len < sizeof(*hdr)) {
|
||||
|
@ -1286,8 +1286,8 @@ static int l2cap_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
|||
return 0;
|
||||
}
|
||||
|
||||
hdr = net_buf_pull_mem(buf, sizeof(*hdr));
|
||||
len = sys_le16_to_cpu(hdr->len);
|
||||
net_buf_pull(buf, sizeof(*hdr));
|
||||
|
||||
BT_DBG("Signaling code 0x%02x ident %u len %u", hdr->code,
|
||||
hdr->ident, len);
|
||||
|
@ -1575,7 +1575,7 @@ static void l2cap_chan_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
|||
|
||||
void bt_l2cap_recv(struct bt_conn *conn, struct net_buf *buf)
|
||||
{
|
||||
struct bt_l2cap_hdr *hdr = (void *)buf->data;
|
||||
struct bt_l2cap_hdr *hdr;
|
||||
struct bt_l2cap_chan *chan;
|
||||
u16_t cid;
|
||||
|
||||
|
@ -1591,8 +1591,8 @@ void bt_l2cap_recv(struct bt_conn *conn, struct net_buf *buf)
|
|||
return;
|
||||
}
|
||||
|
||||
hdr = net_buf_pull_mem(buf, sizeof(*hdr));
|
||||
cid = sys_le16_to_cpu(hdr->cid);
|
||||
net_buf_pull(buf, sizeof(*hdr));
|
||||
|
||||
BT_DBG("Packet for CID %u len %u", cid, buf->len);
|
||||
|
||||
|
|
|
@ -312,7 +312,7 @@ static void connect_optional_fixed_channels(struct bt_l2cap_br *l2cap)
|
|||
static int l2cap_br_info_rsp(struct bt_l2cap_br *l2cap, u8_t ident,
|
||||
struct net_buf *buf)
|
||||
{
|
||||
struct bt_l2cap_info_rsp *rsp = (void *)buf->data;
|
||||
struct bt_l2cap_info_rsp *rsp;
|
||||
u16_t type, result;
|
||||
int err = 0;
|
||||
|
||||
|
@ -341,6 +341,7 @@ static int l2cap_br_info_rsp(struct bt_l2cap_br *l2cap, u8_t ident,
|
|||
goto done;
|
||||
}
|
||||
|
||||
rsp = net_buf_pull_mem(buf, sizeof(*rsp));
|
||||
result = sys_le16_to_cpu(rsp->result);
|
||||
if (result != BT_L2CAP_INFO_SUCCESS) {
|
||||
BT_WARN("Result unsuccessful");
|
||||
|
@ -349,7 +350,6 @@ static int l2cap_br_info_rsp(struct bt_l2cap_br *l2cap, u8_t ident,
|
|||
}
|
||||
|
||||
type = sys_le16_to_cpu(rsp->type);
|
||||
net_buf_pull(buf, sizeof(*rsp));
|
||||
|
||||
switch (type) {
|
||||
case BT_L2CAP_INFO_FEAT_MASK:
|
||||
|
@ -926,7 +926,7 @@ static void l2cap_br_conf_req(struct bt_l2cap_br *l2cap, u8_t ident,
|
|||
{
|
||||
struct bt_conn *conn = l2cap->chan.chan.conn;
|
||||
struct bt_l2cap_chan *chan;
|
||||
struct bt_l2cap_conf_req *req = (void *)buf->data;
|
||||
struct bt_l2cap_conf_req *req;
|
||||
struct bt_l2cap_sig_hdr *hdr;
|
||||
struct bt_l2cap_conf_rsp *rsp;
|
||||
struct bt_l2cap_conf_opt *opt;
|
||||
|
@ -937,6 +937,7 @@ static void l2cap_br_conf_req(struct bt_l2cap_br *l2cap, u8_t ident,
|
|||
return;
|
||||
}
|
||||
|
||||
req = net_buf_pull_mem(buf, sizeof(*req));
|
||||
flags = sys_le16_to_cpu(req->flags);
|
||||
dcid = sys_le16_to_cpu(req->dcid);
|
||||
opt_len = len - sizeof(*req);
|
||||
|
@ -961,15 +962,8 @@ static void l2cap_br_conf_req(struct bt_l2cap_br *l2cap, u8_t ident,
|
|||
goto send_rsp;
|
||||
}
|
||||
|
||||
/*
|
||||
* initialize config option data dedicated object with proper
|
||||
* offset set to beginnig of config options data
|
||||
*/
|
||||
opt = net_buf_pull(buf, sizeof(*req));
|
||||
|
||||
while (buf->len >= sizeof(*opt)) {
|
||||
/* pull buf to always point to option data item */
|
||||
net_buf_pull(buf, sizeof(*opt));
|
||||
opt = net_buf_pull_mem(buf, sizeof(*opt));
|
||||
|
||||
/* make sure opt object can get safe dereference in iteration */
|
||||
if (buf->len < opt->len) {
|
||||
|
@ -997,8 +991,8 @@ static void l2cap_br_conf_req(struct bt_l2cap_br *l2cap, u8_t ident,
|
|||
goto send_rsp;
|
||||
}
|
||||
|
||||
/* set opt object to next option chunk */
|
||||
opt = net_buf_pull(buf, opt->len);
|
||||
/* Update buffer to point at next option */
|
||||
net_buf_pull(buf, opt->len);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1347,7 +1341,7 @@ int bt_l2cap_br_chan_send(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
|||
static int l2cap_br_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
{
|
||||
struct bt_l2cap_br *l2cap = CONTAINER_OF(chan, struct bt_l2cap_br, chan);
|
||||
struct bt_l2cap_sig_hdr *hdr = (void *)buf->data;
|
||||
struct bt_l2cap_sig_hdr *hdr;
|
||||
u16_t len;
|
||||
|
||||
if (buf->len < sizeof(*hdr)) {
|
||||
|
@ -1355,8 +1349,8 @@ static int l2cap_br_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
|||
return 0;
|
||||
}
|
||||
|
||||
hdr = net_buf_pull_mem(buf, sizeof(*hdr));
|
||||
len = sys_le16_to_cpu(hdr->len);
|
||||
net_buf_pull(buf, sizeof(*hdr));
|
||||
|
||||
BT_DBG("Signaling code 0x%02x ident %u len %u", hdr->code,
|
||||
hdr->ident, len);
|
||||
|
@ -1492,7 +1486,7 @@ static void check_fixed_channel(struct bt_l2cap_chan *chan)
|
|||
|
||||
void bt_l2cap_br_recv(struct bt_conn *conn, struct net_buf *buf)
|
||||
{
|
||||
struct bt_l2cap_hdr *hdr = (void *)buf->data;
|
||||
struct bt_l2cap_hdr *hdr;
|
||||
struct bt_l2cap_chan *chan;
|
||||
u16_t cid;
|
||||
|
||||
|
@ -1502,8 +1496,8 @@ void bt_l2cap_br_recv(struct bt_conn *conn, struct net_buf *buf)
|
|||
return;
|
||||
}
|
||||
|
||||
hdr = net_buf_pull_mem(buf, sizeof(*hdr));
|
||||
cid = sys_le16_to_cpu(hdr->cid);
|
||||
net_buf_pull(buf, sizeof(*hdr));
|
||||
|
||||
chan = bt_l2cap_br_lookup_rx_cid(conn, cid);
|
||||
if (!chan) {
|
||||
|
|
|
@ -1262,17 +1262,21 @@ static void rfcomm_handle_disc(struct bt_rfcomm_session *session, u8_t dlci)
|
|||
static void rfcomm_handle_msg(struct bt_rfcomm_session *session,
|
||||
struct net_buf *buf)
|
||||
{
|
||||
struct bt_rfcomm_msg_hdr *hdr = (void *)buf->data;
|
||||
struct bt_rfcomm_msg_hdr *hdr;
|
||||
u8_t msg_type, len, cr;
|
||||
|
||||
if (buf->len < sizeof(*hdr)) {
|
||||
BT_ERR("Too small RFCOMM message");
|
||||
return;
|
||||
}
|
||||
|
||||
hdr = net_buf_pull_mem(buf, sizeof(*hdr));
|
||||
msg_type = BT_RFCOMM_GET_MSG_TYPE(hdr->type);
|
||||
cr = BT_RFCOMM_GET_MSG_CR(hdr->type);
|
||||
len = BT_RFCOMM_GET_LEN(hdr->len);
|
||||
|
||||
BT_DBG("msg type %x cr %x", msg_type, cr);
|
||||
|
||||
net_buf_pull(buf, sizeof(*hdr));
|
||||
|
||||
switch (msg_type) {
|
||||
case BT_RFCOMM_PN:
|
||||
rfcomm_handle_pn(session, buf, cr);
|
||||
|
|
|
@ -1339,7 +1339,7 @@ static int bt_sdp_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
|||
struct bt_l2cap_br_chan *ch = CONTAINER_OF(chan,
|
||||
struct bt_l2cap_br_chan, chan);
|
||||
struct bt_sdp *sdp = CONTAINER_OF(ch, struct bt_sdp, chan);
|
||||
struct bt_sdp_hdr *hdr = (struct bt_sdp_hdr *)buf->data;
|
||||
struct bt_sdp_hdr *hdr;
|
||||
u16_t err = BT_SDP_INVALID_SYNTAX;
|
||||
size_t i;
|
||||
|
||||
|
@ -1352,10 +1352,9 @@ static int bt_sdp_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
|||
return 0;
|
||||
}
|
||||
|
||||
hdr = net_buf_pull_mem(buf, sizeof(*hdr));
|
||||
BT_DBG("Received SDP code 0x%02x len %u", hdr->op_code, buf->len);
|
||||
|
||||
net_buf_pull(buf, sizeof(*hdr));
|
||||
|
||||
if (sys_cpu_to_be16(hdr->param_len) != buf->len) {
|
||||
err = BT_SDP_INVALID_PDU_SIZE;
|
||||
} else {
|
||||
|
@ -1719,7 +1718,7 @@ static void sdp_client_notify_result(struct bt_sdp_client *session,
|
|||
static int sdp_client_receive(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
{
|
||||
struct bt_sdp_client *session = SDP_CLIENT_CHAN(chan);
|
||||
struct bt_sdp_hdr *hdr = (void *)buf->data;
|
||||
struct bt_sdp_hdr *hdr;
|
||||
struct bt_sdp_pdu_cstate *cstate;
|
||||
u16_t len, tid, frame_len;
|
||||
u16_t total;
|
||||
|
@ -1731,6 +1730,7 @@ static int sdp_client_receive(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
|||
return 0;
|
||||
}
|
||||
|
||||
hdr = net_buf_pull_mem(buf, sizeof(*hdr));
|
||||
if (hdr->op_code == BT_SDP_ERROR_RSP) {
|
||||
BT_INFO("Error SDP PDU response");
|
||||
return 0;
|
||||
|
@ -1738,7 +1738,6 @@ static int sdp_client_receive(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
|||
|
||||
len = sys_be16_to_cpu(hdr->param_len);
|
||||
tid = sys_be16_to_cpu(hdr->tid);
|
||||
net_buf_pull(buf, sizeof(*hdr));
|
||||
|
||||
BT_DBG("SDP PDU tid %u len %u", tid, len);
|
||||
|
||||
|
|
|
@ -1299,7 +1299,7 @@ static int smp_br_error(struct bt_smp_br *smp, u8_t reason)
|
|||
static int bt_smp_br_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
{
|
||||
struct bt_smp_br *smp = CONTAINER_OF(chan, struct bt_smp_br, chan);
|
||||
struct bt_smp_hdr *hdr = (void *)buf->data;
|
||||
struct bt_smp_hdr *hdr;
|
||||
u8_t err;
|
||||
|
||||
if (buf->len < sizeof(*hdr)) {
|
||||
|
@ -1307,10 +1307,9 @@ static int bt_smp_br_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
|||
return 0;
|
||||
}
|
||||
|
||||
hdr = net_buf_pull_mem(buf, sizeof(*hdr));
|
||||
BT_DBG("Received SMP code 0x%02x len %u", hdr->code, buf->len);
|
||||
|
||||
net_buf_pull(buf, sizeof(*hdr));
|
||||
|
||||
/*
|
||||
* If SMP timeout occurred "no further SMP commands shall be sent over
|
||||
* the L2CAP Security Manager Channel. A new SM procedure shall only be
|
||||
|
@ -3513,7 +3512,7 @@ static const struct {
|
|||
static int bt_smp_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
{
|
||||
struct bt_smp *smp = CONTAINER_OF(chan, struct bt_smp, chan);
|
||||
struct bt_smp_hdr *hdr = (void *)buf->data;
|
||||
struct bt_smp_hdr *hdr;
|
||||
u8_t err;
|
||||
|
||||
if (buf->len < sizeof(*hdr)) {
|
||||
|
@ -3521,10 +3520,9 @@ static int bt_smp_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
|||
return 0;
|
||||
}
|
||||
|
||||
hdr = net_buf_pull_mem(buf, sizeof(*hdr));
|
||||
BT_DBG("Received SMP code 0x%02x len %u", hdr->code, buf->len);
|
||||
|
||||
net_buf_pull(buf, sizeof(*hdr));
|
||||
|
||||
/*
|
||||
* If SMP timeout occurred "no further SMP commands shall be sent over
|
||||
* the L2CAP Security Manager Channel. A new SM procedure shall only be
|
||||
|
|
Loading…
Reference in a new issue