Skip to content

Commit

Permalink
Bluetooth: RFCOMM: Handle non supported message types
Browse files Browse the repository at this point in the history
If peer sends any non supported message then it has to be
responded with NSC (Non Supported Command) response.

> ACL Data RX: Handle 256 flags 0x02 dlen 18
      Channel: 64 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0x70
         MCC Message type: Unknown CMD (0x33)
           Length: 8
        01 22 34 55 67 88 9a bb 70

< ACL Data TX: Handle 256 flags 0x00 dlen 11
      Channel: 64 len 7 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x01 cr 0 dlci 0x00
         Control: 0xef poll/final 0
         Length: 3
         FCS: 0xaa
         MCC Message type: Non Supported Command RSP (0x04)
           Length: 1
           cr 1, mcc_cmd_type 33

Change-Id: I7be3b64a9cf437276c10868d52e0b9c555018df0
Signed-off-by: Jaganath Kanakkassery <[email protected]>
  • Loading branch information
jkanakkx authored and Johan Hedberg committed Jan 5, 2017
1 parent fb07eb9 commit 41984c7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions subsys/bluetooth/host/rfcomm.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,22 @@ static int rfcomm_send_test(struct bt_rfcomm_session *session, uint8_t cr,
return bt_l2cap_chan_send(&session->br_chan.chan, buf);
}

static int rfcomm_send_nsc(struct bt_rfcomm_session *session, uint8_t cmd_type)
{
struct net_buf *buf;
uint8_t fcs;

buf = rfcomm_make_uih_msg(session, BT_RFCOMM_MSG_RESP_CR,
BT_RFCOMM_NSC, sizeof(cmd_type));

net_buf_add_u8(buf, cmd_type);

fcs = rfcomm_calc_fcs(BT_RFCOMM_FCS_LEN_UIH, buf->data);
net_buf_add_u8(buf, fcs);

return bt_l2cap_chan_send(&session->br_chan.chan, buf);
}

static void rfcomm_dlc_connected(struct bt_rfcomm_dlc *dlc)
{
dlc->state = BT_RFCOMM_STATE_CONNECTED;
Expand Down Expand Up @@ -1127,6 +1143,7 @@ static void rfcomm_handle_msg(struct bt_rfcomm_session *session,
break;
default:
BT_WARN("Unknown/Unsupported RFCOMM Msg type 0x%02x", msg_type);
rfcomm_send_nsc(session, hdr->type);
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions subsys/bluetooth/host/rfcomm_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ struct bt_rfcomm_rpn {
} __packed;

#define BT_RFCOMM_TEST 0x08
#define BT_RFCOMM_NSC 0x04

/* Default RPN Settings */
#define BT_RFCOMM_RPN_BAUD_RATE_9600 0x03
Expand Down

0 comments on commit 41984c7

Please sign in to comment.