handle RLS CMD, fix len in Test CMD/RSP

This commit is contained in:
matthias.ringwald@gmail.com 2014-01-11 18:35:55 +00:00
parent 8712d7baf6
commit c0164e1c7c
2 changed files with 47 additions and 5 deletions

View File

@ -524,7 +524,7 @@ static int rfcomm_send_dm_pf(rfcomm_multiplexer_t *multiplexer, uint8_t dlci){
// uint8_t payload[3+len];
// uint8_t pos = 0;
// payload[pos++] = BT_RFCOMM_TEST_CMD;
// payload[pos++] = len << 1 | 1; // len
// payload[pos++] = (len + 1) << 1 | 1; // len
// payload[pos++] = (1 << 0) | (1 << 1) | (dlci << 2); // CMD => C/R = 1
// memcpy(&payload[pos], data, len);
// pos += len;
@ -537,7 +537,7 @@ static int rfcomm_send_uih_test_rsp(rfcomm_multiplexer_t *multiplexer, uint8_t *
uint8_t payload[3+len];
uint8_t pos = 0;
payload[pos++] = BT_RFCOMM_TEST_RSP;
payload[pos++] = len << 1 | 1; // len
payload[pos++] = (len + 1) << 1 | 1; // len
payload[pos++] = (1 << 0) | (1 << 1) | (dlci << 2); // CMD => C/R = 1
memcpy(&payload[pos], data, len);
pos += len;
@ -602,6 +602,17 @@ static int rfcomm_send_uih_pn_response(rfcomm_multiplexer_t *multiplexer, uint8_
return rfcomm_send_packet_for_multiplexer(multiplexer, address, BT_RFCOMM_UIH, 0, (uint8_t *) payload, pos);
}
static int rfcomm_send_uih_rls_rsp(rfcomm_multiplexer_t *multiplexer, uint8_t dlci, uint8_t line_status) {
uint8_t address = (1 << 0) | (multiplexer->outgoing << 1);
uint8_t payload[4];
uint8_t pos = 0;
payload[pos++] = BT_RFCOMM_RLS_RSP;
payload[pos++] = 2 << 1 | 1; // len
payload[pos++] = (1 << 0) | (1 << 1) | (dlci << 2); // CMD => C/R = 1
payload[pos++] = line_status;
return rfcomm_send_packet_for_multiplexer(multiplexer, address, BT_RFCOMM_UIH, 0, (uint8_t *) payload, pos);
}
static int rfcomm_send_uih_rpn_rsp(rfcomm_multiplexer_t *multiplexer, uint8_t dlci, rfcomm_rpn_data_t *rpn_data) {
uint8_t payload[10];
uint8_t address = (1 << 0) | (multiplexer->outgoing << 1);
@ -1324,9 +1335,15 @@ void rfcomm_channel_packet_handler(rfcomm_multiplexer_t * multiplexer, uint8_t
}
break;
case BT_RFCOMM_RLS_CMD:
log_info("Received test command");
case BT_RFCOMM_RLS_CMD: {
log_info("Received RLS command");
message_dlci = packet[payload_offset+2] >> 2;
rfcomm_channel_event_rls_t event_rls;
event_rls.super.type = CH_EVT_RCVD_RLS_CMD;
event_rls.line_status = packet[payload_offset+3];
rfcomm_channel_state_machine_2(multiplexer, message_dlci, (rfcomm_channel_event_t*) &event_rls);
break;
}
default:
log_error("Received unknown UIH packet - 0x%02x\n", packet[payload_offset]);
@ -1660,13 +1677,25 @@ static void rfcomm_channel_state_machine(rfcomm_channel_t *channel, rfcomm_chann
rfcomm_channel_send_credits(channel, new_credits);
break;
}
if (channel->rls_line_status != RFCOMM_RLS_STATUS_INVALID){
uint8_t line_status = channel->rls_line_status;
channel->rls_line_status = RFCOMM_RLS_STATUS_INVALID;
rfcomm_send_uih_rls_rsp(multiplexer, channel->dlci, line_status);
break;
}
break;
case CH_EVT_RCVD_CREDITS: {
// notify daemon -> might trigger re-try of parked connections
uint8_t event[1] = { DAEMON_EVENT_NEW_RFCOMM_CREDITS };
(*app_packet_handler)(channel->connection, DAEMON_EVENT_PACKET, channel->rfcomm_cid, event, sizeof(event));
break;
}
}
case CH_EVT_RCVD_RLS_CMD: {
rfcomm_channel_event_rls_t * event_rls = (rfcomm_channel_event_rls_t*) event;
channel->rls_line_status = event_rls->line_status & 0x0f;
rfcomm_emit_remote_line_status(channel, event_rls->line_status);
break;
}
default:
break;
}

View File

@ -53,6 +53,9 @@ extern "C" {
#define RFCOMM_TEST_DATA_MAX_LEN 4
#define RFCOMM_RLS_STATUS_INVALID 0xff
// private structs
typedef enum {
RFCOMM_MULTIPLEXER_CLOSED = 1,
@ -118,6 +121,8 @@ typedef enum {
CH_EVT_RCVD_DM,
CH_EVT_RCVD_MSC_CMD,
CH_EVT_RCVD_MSC_RSP,
CH_EVT_RCVD_RLS_CMD,
CH_EVT_RCVD_RLS_RSP,
CH_EVT_RCVD_RPN_CMD,
CH_EVT_RCVD_RPN_REQ,
CH_EVT_RCVD_CREDITS,
@ -151,6 +156,11 @@ typedef struct rfcomm_channel_event_rpn {
rfcomm_rpn_data_t data;
} rfcomm_channel_event_rpn_t;
typedef struct rfcomm_channel_event_rls {
rfcomm_channel_event_t super;
uint8_t line_status;
} rfcomm_channel_event_rls_t;
// info regarding potential connections
typedef struct {
// linked list - assert: first field
@ -249,6 +259,9 @@ typedef struct {
// rpn data
rfcomm_rpn_data_t rpn_data;
// rls line status. RFCOMM_RLS_STATUS_INVALID if not set
uint8_t rls_line_status;
// server channel (see rfcomm_service_t) - NULL => outgoing channel
rfcomm_service_t * service;