Bluetooth: RFCOMM: Respond to Test command

Test command is to test the connection between two stations.
The pattern recieved should be sent back in the response.

> ACL Data RX: Handle 256 flags 0x02 dlen 14
      Channel: 64 len 10 [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: 6
         FCS: 0x70
         MCC Message type: Test Command CMD (0x08)
           Length: 4
           Test Data: 0x 5f 54 65 73

< ACL Data TX: Handle 256 flags 0x00 dlen 14
      Channel: 64 len 10 [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: 6
         FCS: 0xaa
         MCC Message type: Test Command RSP (0x08)
           Length: 4
           Test Data: 0x 5f 54 65 73

Change-Id: I16beb4cf857cc8bbc049514dbf840d84e13c8fb5
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
This commit is contained in:
Jaganath Kanakkassery 2016-12-15 22:17:55 +05:30 committed by Johan Hedberg
commit fb07eb9022
2 changed files with 25 additions and 0 deletions

View file

@ -618,6 +618,22 @@ static int rfcomm_send_rpn(struct bt_rfcomm_session *session, uint8_t cr,
return bt_l2cap_chan_send(&session->br_chan.chan, buf);
}
static int rfcomm_send_test(struct bt_rfcomm_session *session, uint8_t cr,
uint8_t *pattern, uint8_t len)
{
struct net_buf *buf;
uint8_t fcs;
buf = rfcomm_make_uih_msg(session, cr, BT_RFCOMM_TEST, len);
net_buf_add_mem(buf, pattern, len);
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;
@ -1102,6 +1118,13 @@ static void rfcomm_handle_msg(struct bt_rfcomm_session *session,
case BT_RFCOMM_RPN:
rfcomm_handle_rpn(session, buf, cr);
break;
case BT_RFCOMM_TEST:
if (!cr) {
break;
}
rfcomm_send_test(session, BT_RFCOMM_MSG_RESP_CR, buf->data,
buf->len - 1);
break;
default:
BT_WARN("Unknown/Unsupported RFCOMM Msg type 0x%02x", msg_type);
break;

View file

@ -94,6 +94,8 @@ struct bt_rfcomm_rpn {
uint16_t param_mask;
} __packed;
#define BT_RFCOMM_TEST 0x08
/* Default RPN Settings */
#define BT_RFCOMM_RPN_BAUD_RATE_9600 0x03
#define BT_RFCOMM_RPN_DATA_BITS_8 0x03