Bluetooth: RFCOMM: Perform MSC transaction after dlc

MSC (Modem status command) is used to convey RS-232 control and break
signals. This shall be sent prior to any user data after dlc. Remote
also would have sent it which is handled in this patch

This has meaning only if a port emulation entity is there on top (which
is not there in zephyr right now). So currently v24 signal is hard
coded like below.
DV = 1 IC = 0 RTR = 1 RTC = 1 FC = 0 EXT = 0

< ACL Data TX: Handle 256 flags 0x00 dlen 12
      Channel: 64 len 8 [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: 4
         FCS: 0xaa
         MCC Message type: Modem Status Command CMD (0x38)
           Length: 2
           dlci 2
           fc 0 rtc 1 rtr 1 ic 0 dv 1
> ACL Data RX: Handle 256 flags 0x02 dlen 12
      Channel: 64 len 8 [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: 4
         FCS: 0x70
         MCC Message type: Modem Status Command CMD (0x38)
           Length: 2
           dlci 2
           fc 0 rtc 1 rtr 1 ic 0 dv 1
< ACL Data TX: Handle 256 flags 0x00 dlen 12
      Channel: 64 len 8 [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: 4
         FCS: 0xaa
         MCC Message type: Modem Status Command RSP (0x38)
           Length: 2
           dlci 2
           fc 0 rtc 1 rtr 1 ic 0 dv 1
> ACL Data RX: Handle 256 flags 0x02 dlen 12
      Channel: 64 len 8 [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: 4
         FCS: 0x70
         MCC Message type: Modem Status Command RSP (0x38)
           Length: 2
           dlci 2
           fc 0 rtc 1 rtr 1 ic 0 dv 1

Change-Id: Iab06f12de2f2357485309eb622c8c5e13db7011c
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
This commit is contained in:
Jaganath Kanakkassery 2016-08-22 18:17:29 +05:30 committed by Johan Hedberg
commit d6af0ef091
2 changed files with 54 additions and 0 deletions

View file

@ -289,10 +289,33 @@ static int rfcomm_send_ua(struct bt_rfcomm_session *session, uint8_t dlci)
return bt_l2cap_chan_send(&session->br_chan.chan, buf);
}
static int rfcomm_send_msc(struct bt_rfcomm_dlc *dlc, uint8_t cr)
{
struct bt_rfcomm_msc *msc;
struct net_buf *buf;
uint8_t fcs;
buf = rfcomm_make_uih_msg(dlc, cr, BT_RFCOMM_MSC, sizeof(*msc));
if (!buf) {
return -ENOMEM;
}
msc = net_buf_add(buf, sizeof(*msc));
msc->dlci = BT_RFCOMM_SET_ADDR(dlc->dlci, cr);
msc->v24_signal = BT_RFCOMM_DEFAULT_V24_SIG;
fcs = rfcomm_calc_fcs(BT_RFCOMM_FCS_LEN_UIH, buf->data);
net_buf_add_u8(buf, fcs);
return bt_l2cap_chan_send(&dlc->session->br_chan.chan, buf);
}
static void rfcomm_dlc_connected(struct bt_rfcomm_dlc *dlc)
{
dlc->state = BT_RFCOMM_STATE_CONNECTED;
rfcomm_send_msc(dlc, BT_RFCOMM_MSG_CMD);
if (dlc->ops && dlc->ops->connected) {
dlc->ops->connected(dlc);
}
@ -360,6 +383,25 @@ static int rfcomm_send_pn(struct bt_rfcomm_dlc *dlc, uint8_t cr)
return bt_l2cap_chan_send(&dlc->session->br_chan.chan, buf);
}
static void rfcomm_handle_msc(struct bt_rfcomm_session *session,
struct net_buf *buf, uint8_t cr)
{
struct bt_rfcomm_msc *msc = (void *)buf->data;
struct bt_rfcomm_dlc *dlc;
uint8_t dlci = BT_RFCOMM_GET_DLCI(msc->dlci);
BT_DBG("dlci %d", dlci);
dlc = rfcomm_dlcs_lookup_dlci(session->dlcs, dlci);
if (!dlc) {
return;
}
if (cr == BT_RFCOMM_MSG_CMD) {
rfcomm_send_msc(dlc, BT_RFCOMM_MSG_RESP);
}
}
static void rfcomm_handle_pn(struct bt_rfcomm_session *session,
struct net_buf *buf, uint8_t cr)
{
@ -409,6 +451,9 @@ static void rfcomm_handle_msg(struct bt_rfcomm_session *session,
case BT_RFCOMM_PN:
rfcomm_handle_pn(session, buf, cr);
break;
case BT_RFCOMM_MSC:
rfcomm_handle_msc(session, buf, cr);
break;
default:
BT_WARN("Unknown/Unsupported RFCOMM Msg type 0x%02x", msg_type);
break;

View file

@ -63,6 +63,15 @@ struct bt_rfcomm_pn {
uint8_t credits;
} __packed;
#define BT_RFCOMM_MSC 0x38
struct bt_rfcomm_msc {
uint8_t dlci;
uint8_t v24_signal;
} __packed;
/* DV = 1 IC = 0 RTR = 1 RTC = 1 FC = 0 EXT = 0 */
#define BT_RFCOMM_DEFAULT_V24_SIG 0x8d
#define BT_RFCOMM_SIG_MIN_MTU 23
#define BT_RFCOMM_SIG_MAX_MTU 32767