summaryrefslogtreecommitdiff
path: root/profiles/network/bnep.c
diff options
context:
space:
mode:
authorGrzegorz Kolodziejczyk <grzegorz.kolodziejczyk@tieto.com>2015-03-09 17:24:48 +0100
committerSzymon Janc <szymon.janc@tieto.com>2015-03-12 11:08:00 +0100
commit10125a912d7f251e5f01bdfcfa0a3cf5d845be2c (patch)
treec8ae908f92c9661bb14d250cad4314a6d815f776 /profiles/network/bnep.c
parentb104ec8263f1cf6ffad56ebb1edc8adb58a060aa (diff)
downloadbluez-10125a912d7f251e5f01bdfcfa0a3cf5d845be2c.tar.gz
profiles/network: Fix sending command responses
Command response can be three bytes long (in case if command is not understood) 1 byte(packet type) + 1 byte(control type) + 1 byte(unknown control type). Command response can be also four bytes long if it's response for setup connection, filter net type and filter multi addr, 1 byte(packet type) + 1 byte(control type) + 2 byte(response message).
Diffstat (limited to 'profiles/network/bnep.c')
-rw-r--r--profiles/network/bnep.c60
1 files changed, 43 insertions, 17 deletions
diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
index afd94c599..3fe63f0bb 100644
--- a/profiles/network/bnep.c
+++ b/profiles/network/bnep.c
@@ -524,16 +524,40 @@ static int bnep_del_from_bridge(const char *devname, const char *bridge)
return err;
}
-static ssize_t bnep_send_ctrl_rsp(int sk, uint8_t type, uint8_t ctrl,
- uint16_t resp)
+static ssize_t bnep_send_ctrl_rsp(int sk, uint8_t ctrl, uint16_t resp)
{
- struct bnep_control_rsp rsp;
+ ssize_t sent;
- rsp.type = type;
- rsp.ctrl = ctrl;
- rsp.resp = htons(resp);
+ switch (ctrl) {
+ case BNEP_CMD_NOT_UNDERSTOOD: {
+ struct bnep_ctrl_cmd_not_understood_cmd rsp;
- return send(sk, &rsp, sizeof(rsp), 0);
+ rsp.type = BNEP_CONTROL;
+ rsp.ctrl = ctrl;
+ rsp.unkn_ctrl = (uint8_t) resp;
+
+ sent = send(sk, &rsp, sizeof(rsp), 0);
+ break;
+ }
+ case BNEP_FILTER_MULT_ADDR_RSP:
+ case BNEP_FILTER_NET_TYPE_RSP:
+ case BNEP_SETUP_CONN_RSP: {
+ struct bnep_control_rsp rsp;
+
+ rsp.type = BNEP_CONTROL;
+ rsp.ctrl = ctrl;
+ rsp.resp = htons(resp);
+
+ sent = send(sk, &rsp, sizeof(rsp), 0);
+ break;
+ }
+ default:
+ error("bnep: wrong response type");
+ sent = -1;
+ break;
+ }
+
+ return sent;
}
static uint16_t bnep_setup_decode(int sk, struct bnep_setup_conn_req *req,
@@ -612,16 +636,15 @@ int bnep_server_add(int sk, char *bridge, char *iface, const bdaddr_t *addr,
/* Highest known Control command ID
* is BNEP_FILTER_MULT_ADDR_RSP = 0x06 */
if (req->type == BNEP_CONTROL &&
- req->ctrl > BNEP_FILTER_MULT_ADDR_RSP) {
- uint8_t pkt[3];
-
- pkt[0] = BNEP_CONTROL;
- pkt[1] = BNEP_CMD_NOT_UNDERSTOOD;
- pkt[2] = req->ctrl;
+ req->ctrl > BNEP_FILTER_MULT_ADDR_RSP) {
+ error("bnep: cmd not understood");
+ err = bnep_send_ctrl_rsp(sk, BNEP_CMD_NOT_UNDERSTOOD,
+ req->ctrl);
+ if (err < 0)
+ error("send not understood ctrl rsp error: %s (%d)",
+ strerror(errno), errno);
- send(sk, pkt, sizeof(pkt), 0);
-
- return -EINVAL;
+ return err;
}
/* Processing BNEP_SETUP_CONNECTION_REQUEST_MSG */
@@ -657,7 +680,10 @@ int bnep_server_add(int sk, char *bridge, char *iface, const bdaddr_t *addr,
rsp = BNEP_CONN_NOT_ALLOWED;
reply:
- bnep_send_ctrl_rsp(sk, BNEP_CONTROL, BNEP_SETUP_CONN_RSP, rsp);
+ err = bnep_send_ctrl_rsp(sk, BNEP_SETUP_CONN_RSP, rsp);
+ if (err < 0)
+ error("bnep: send ctrl rsp error: %s (%d)", strerror(errno),
+ errno);
return err;
}