1 /******************************************************************************
3 * Copyright (C) 1999-2012 Broadcom Corporation
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 ******************************************************************************/
19 /******************************************************************************
21 * This file contains functions to send TS 07.10 frames
23 ******************************************************************************/
26 #include "bt_target.h"
27 #include "bt_common.h"
34 /*******************************************************************************
36 ** Function rfc_send_sabme
38 ** Description This function sends SABME frame.
40 *******************************************************************************/
41 void rfc_send_sabme (tRFC_MCB *p_mcb, UINT8 dlci)
44 UINT8 cr = RFCOMM_CR(p_mcb->is_initiator, TRUE);
45 BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE);
47 p_buf->offset = L2CAP_MIN_OFFSET;
48 p_data = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
50 /* SABME frame, command, PF = 1, dlci */
51 *p_data++ = RFCOMM_EA | cr | (dlci << RFCOMM_SHIFT_DLCI);
52 *p_data++ = RFCOMM_SABME | RFCOMM_PF;
53 *p_data++ = RFCOMM_EA | 0;
55 *p_data = RFCOMM_SABME_FCS ((UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET, cr, dlci);
59 rfc_check_send_cmd(p_mcb, p_buf);
63 /*******************************************************************************
65 ** Function rfc_send_ua
67 ** Description This function sends UA frame.
69 *******************************************************************************/
70 void rfc_send_ua (tRFC_MCB *p_mcb, UINT8 dlci)
73 UINT8 cr = RFCOMM_CR(p_mcb->is_initiator, FALSE);
74 BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE);
76 p_buf->offset = L2CAP_MIN_OFFSET;
77 p_data = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
79 /* ua frame, response, PF = 1, dlci */
80 *p_data++ = RFCOMM_EA | cr | (dlci << RFCOMM_SHIFT_DLCI);
81 *p_data++ = RFCOMM_UA | RFCOMM_PF;
82 *p_data++ = RFCOMM_EA | 0;
84 *p_data = RFCOMM_UA_FCS ((UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET, cr, dlci);
88 rfc_check_send_cmd(p_mcb, p_buf);
92 /*******************************************************************************
94 ** Function rfc_send_dm
96 ** Description This function sends DM frame.
98 *******************************************************************************/
99 void rfc_send_dm (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN pf)
102 UINT8 cr = RFCOMM_CR(p_mcb->is_initiator, FALSE);
103 BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE);
105 p_buf->offset = L2CAP_MIN_OFFSET;
106 p_data = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
108 /* DM frame, response, PF = 1, dlci */
109 *p_data++ = RFCOMM_EA | cr | (dlci << RFCOMM_SHIFT_DLCI);
110 *p_data++ = RFCOMM_DM | ((pf) ? RFCOMM_PF : 0);
111 *p_data++ = RFCOMM_EA | 0;
113 *p_data = RFCOMM_DM_FCS ((UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET, cr, dlci);
117 rfc_check_send_cmd(p_mcb, p_buf);
121 /*******************************************************************************
123 ** Function rfc_send_disc
125 ** Description This function sends DISC frame.
127 *******************************************************************************/
128 void rfc_send_disc (tRFC_MCB *p_mcb, UINT8 dlci)
131 UINT8 cr = RFCOMM_CR(p_mcb->is_initiator, TRUE);
132 BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE);
134 p_buf->offset = L2CAP_MIN_OFFSET;
135 p_data = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
137 /* DISC frame, command, PF = 1, dlci */
138 *p_data++ = RFCOMM_EA | cr | (dlci << RFCOMM_SHIFT_DLCI);
139 *p_data++ = RFCOMM_DISC | RFCOMM_PF;
140 *p_data++ = RFCOMM_EA | 0;
142 *p_data = RFCOMM_DISC_FCS ((UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET, cr, dlci);
146 rfc_check_send_cmd(p_mcb, p_buf);
150 /*******************************************************************************
152 ** Function rfc_send_buf_uih
154 ** Description This function sends UIH frame.
156 *******************************************************************************/
157 void rfc_send_buf_uih (tRFC_MCB *p_mcb, UINT8 dlci, BT_HDR *p_buf)
160 UINT8 cr = RFCOMM_CR(p_mcb->is_initiator, TRUE);
163 p_buf->offset -= RFCOMM_CTRL_FRAME_LEN;
164 if (p_buf->len > 127)
168 credits = (UINT8)p_buf->layer_specific;
175 p_data = (UINT8 *)(p_buf + 1) + p_buf->offset;
177 /* UIH frame, command, PF = 0, dlci */
178 *p_data++ = RFCOMM_EA | cr | (dlci << RFCOMM_SHIFT_DLCI);
179 *p_data++ = RFCOMM_UIH | ((credits) ? RFCOMM_PF : 0);
180 if (p_buf->len <= 127)
182 *p_data++ = RFCOMM_EA | (p_buf->len << 1);
187 *p_data++ = (p_buf->len & 0x7f) << 1;
188 *p_data++ = p_buf->len >> RFCOMM_SHIFT_LENGTH2;
198 p_data = (UINT8 *)(p_buf + 1) + p_buf->offset + p_buf->len++;
200 *p_data = RFCOMM_UIH_FCS ((UINT8 *)(p_buf + 1) + p_buf->offset, dlci);
202 if (dlci == RFCOMM_MX_DLCI)
204 rfc_check_send_cmd(p_mcb, p_buf);
208 L2CA_DataWrite (p_mcb->lcid, p_buf);
213 /*******************************************************************************
215 ** Function rfc_send_pn
217 ** Description This function sends DLC Parameters Negotiation Frame.
219 *******************************************************************************/
220 void rfc_send_pn (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN is_command, UINT16 mtu, UINT8 cl, UINT8 k)
223 BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE);
225 p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN;
226 p_data = (UINT8 *)(p_buf + 1) + p_buf->offset;
228 *p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_PN;
229 *p_data++ = RFCOMM_EA | (RFCOMM_MX_PN_LEN << 1);
232 *p_data++ = RFCOMM_PN_FRAM_TYPE_UIH | cl;
234 /* It appeared that we need to reply with the same priority bits as we received.
235 ** We will use the fact that we reply in the same context so rx_frame can still be used.
238 *p_data++ = RFCOMM_PN_PRIORITY_0;
240 *p_data++ = rfc_cb.rfc.rx_frame.u.pn.priority;
242 *p_data++ = RFCOMM_T1_DSEC;
243 *p_data++ = mtu & 0xFF;
244 *p_data++ = mtu >> 8;
245 *p_data++ = RFCOMM_N2;
248 /* Total length is sizeof PN data + mx header 2 */
249 p_buf->len = RFCOMM_MX_PN_LEN + 2;
251 rfc_send_buf_uih (p_mcb, RFCOMM_MX_DLCI, p_buf);
255 /*******************************************************************************
257 ** Function rfc_send_fcon
259 ** Description This function sends Flow Control On Command.
261 *******************************************************************************/
262 void rfc_send_fcon (tRFC_MCB *p_mcb, BOOLEAN is_command)
265 BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE);
267 p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN;
268 p_data = (UINT8 *)(p_buf + 1) + p_buf->offset;
270 *p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_FCON;
271 *p_data++ = RFCOMM_EA | (RFCOMM_MX_FCON_LEN << 1);
273 /* Total length is sizeof FCON data + mx header 2 */
274 p_buf->len = RFCOMM_MX_FCON_LEN + 2;
276 rfc_send_buf_uih (p_mcb, RFCOMM_MX_DLCI, p_buf);
280 /*******************************************************************************
282 ** Function rfc_send_fcoff
284 ** Description This function sends Flow Control Off Command.
286 *******************************************************************************/
287 void rfc_send_fcoff (tRFC_MCB *p_mcb, BOOLEAN is_command)
290 BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE);
292 p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN;
293 p_data = (UINT8 *)(p_buf + 1) + p_buf->offset;
295 *p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_FCOFF;
296 *p_data++ = RFCOMM_EA | (RFCOMM_MX_FCOFF_LEN << 1);
298 /* Total length is sizeof FCOFF data + mx header 2 */
299 p_buf->len = RFCOMM_MX_FCOFF_LEN + 2;
301 rfc_send_buf_uih (p_mcb, RFCOMM_MX_DLCI, p_buf);
305 /*******************************************************************************
307 ** Function rfc_send_msc
309 ** Description This function sends Modem Status Command Frame.
311 *******************************************************************************/
312 void rfc_send_msc (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN is_command,
317 UINT8 break_duration;
319 BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE);
321 signals = p_pars->modem_signal;
322 break_duration = p_pars->break_signal;
324 p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN;
325 p_data = (UINT8 *)(p_buf + 1) + p_buf->offset;
328 len = RFCOMM_MX_MSC_LEN_WITH_BREAK;
330 len = RFCOMM_MX_MSC_LEN_NO_BREAK;
332 *p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_MSC;
333 *p_data++ = RFCOMM_EA | (len << 1);
335 *p_data++ = RFCOMM_EA | RFCOMM_CR_MASK | (dlci << RFCOMM_SHIFT_DLCI);
336 *p_data++ = RFCOMM_EA |
337 ((p_pars->fc) ? RFCOMM_MSC_FC : 0) |
338 ((signals & MODEM_SIGNAL_DTRDSR) ? RFCOMM_MSC_RTC : 0) |
339 ((signals & MODEM_SIGNAL_RTSCTS) ? RFCOMM_MSC_RTR : 0) |
340 ((signals & MODEM_SIGNAL_RI) ? RFCOMM_MSC_IC : 0) |
341 ((signals & MODEM_SIGNAL_DCD) ? RFCOMM_MSC_DV : 0);
345 *p_data++ = RFCOMM_EA | RFCOMM_MSC_BREAK_PRESENT_MASK |
346 (break_duration << RFCOMM_MSC_SHIFT_BREAK);
349 /* Total length is sizeof MSC data + mx header 2 */
350 p_buf->len = len + 2;
352 rfc_send_buf_uih (p_mcb, RFCOMM_MX_DLCI, p_buf);
356 /*******************************************************************************
358 ** Function rfc_send_rls
360 ** Description This function sends Remote Line Status Command Frame.
362 *******************************************************************************/
363 void rfc_send_rls (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN is_command, UINT8 status)
366 BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE);
368 p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN;
369 p_data = (UINT8 *)(p_buf + 1) + p_buf->offset;
371 *p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_RLS;
372 *p_data++ = RFCOMM_EA | (RFCOMM_MX_RLS_LEN << 1);
374 *p_data++ = RFCOMM_EA | RFCOMM_CR_MASK | (dlci << RFCOMM_SHIFT_DLCI);
375 *p_data++ = RFCOMM_RLS_ERROR | status;
377 /* Total length is sizeof RLS data + mx header 2 */
378 p_buf->len = RFCOMM_MX_RLS_LEN + 2;
380 rfc_send_buf_uih (p_mcb, RFCOMM_MX_DLCI, p_buf);
384 /*******************************************************************************
386 ** Function rfc_send_nsc
388 ** Description This function sends Non Supported Command Response.
390 *******************************************************************************/
391 void rfc_send_nsc (tRFC_MCB *p_mcb)
394 BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE);
396 p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN;
397 p_data = (UINT8 *)(p_buf + 1) + p_buf->offset;
399 *p_data++ = RFCOMM_EA | RFCOMM_I_CR(FALSE) | RFCOMM_MX_NSC;
400 *p_data++ = RFCOMM_EA | (RFCOMM_MX_NSC_LEN << 1);
402 *p_data++ = rfc_cb.rfc.rx_frame.ea |
403 (rfc_cb.rfc.rx_frame.cr << RFCOMM_SHIFT_CR) |
404 rfc_cb.rfc.rx_frame.type;
406 /* Total length is sizeof NSC data + mx header 2 */
407 p_buf->len = RFCOMM_MX_NSC_LEN + 2;
409 rfc_send_buf_uih (p_mcb, RFCOMM_MX_DLCI, p_buf);
413 /*******************************************************************************
415 ** Function rfc_send_rpn
417 ** Description This function sends Remote Port Negotiation Command
419 *******************************************************************************/
420 void rfc_send_rpn (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN is_command,
421 tPORT_STATE *p_pars, UINT16 mask)
424 BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE);
426 p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN;
427 p_data = (UINT8 *)(p_buf + 1) + p_buf->offset;
429 *p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_RPN;
433 *p_data++ = RFCOMM_EA | (RFCOMM_MX_RPN_REQ_LEN << 1);
435 *p_data++ = RFCOMM_EA | RFCOMM_CR_MASK | (dlci << RFCOMM_SHIFT_DLCI);
437 p_buf->len = RFCOMM_MX_RPN_REQ_LEN + 2;
441 *p_data++ = RFCOMM_EA | (RFCOMM_MX_RPN_LEN << 1);
443 *p_data++ = RFCOMM_EA | RFCOMM_CR_MASK | (dlci << RFCOMM_SHIFT_DLCI);
444 *p_data++ = p_pars->baud_rate;
445 *p_data++ = (p_pars->byte_size << RFCOMM_RPN_BITS_SHIFT)
446 | (p_pars->stop_bits << RFCOMM_RPN_STOP_BITS_SHIFT)
447 | (p_pars->parity << RFCOMM_RPN_PARITY_SHIFT)
448 | (p_pars->parity_type << RFCOMM_RPN_PARITY_TYPE_SHIFT);
449 *p_data++ = p_pars->fc_type;
450 *p_data++ = p_pars->xon_char;
451 *p_data++ = p_pars->xoff_char;
452 *p_data++ = (mask & 0xFF);
453 *p_data++ = (mask >> 8);
455 /* Total length is sizeof RPN data + mx header 2 */
456 p_buf->len = RFCOMM_MX_RPN_LEN + 2;
459 rfc_send_buf_uih (p_mcb, RFCOMM_MX_DLCI, p_buf);
463 /*******************************************************************************
465 ** Function rfc_send_test
467 ** Description This function sends Test frame.
469 *******************************************************************************/
470 void rfc_send_test (tRFC_MCB *p_mcb, BOOLEAN is_command, BT_HDR *p_buf)
472 /* Shift buffer to give space for header */
473 if (p_buf->offset < (L2CAP_MIN_OFFSET + RFCOMM_MIN_OFFSET + 2))
475 UINT8 *p_src = (UINT8 *) (p_buf + 1) + p_buf->offset + p_buf->len - 1;
476 BT_HDR *p_new_buf = (BT_HDR *) osi_malloc(p_buf->len + (L2CAP_MIN_OFFSET +
477 RFCOMM_MIN_OFFSET + 2 + sizeof(BT_HDR) + 1));
479 p_new_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_MIN_OFFSET + 2;
480 p_new_buf->len = p_buf->len;
482 UINT8 *p_dest = (UINT8 *) (p_new_buf + 1) + p_new_buf->offset + p_new_buf->len - 1;
484 for (UINT16 xx = 0; xx < p_buf->len; xx++)
485 *p_dest-- = *p_src--;
491 /* Adjust offset by number of bytes we are going to fill */
493 UINT8 *p_data = (UINT8 *)(p_buf + 1) + p_buf->offset;
495 *p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_TEST;
496 *p_data++ = RFCOMM_EA | (p_buf->len << 1);
500 rfc_send_buf_uih (p_mcb, RFCOMM_MX_DLCI, p_buf);
503 /*******************************************************************************
505 ** Function rfc_send_credit
507 ** Description This function sends a flow control credit in UIH frame.
509 *******************************************************************************/
510 void rfc_send_credit(tRFC_MCB *p_mcb, UINT8 dlci, UINT8 credit)
513 UINT8 cr = RFCOMM_CR(p_mcb->is_initiator, TRUE);
514 BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE);
516 p_buf->offset = L2CAP_MIN_OFFSET;
517 p_data = (UINT8 *)(p_buf + 1) + p_buf->offset;
519 *p_data++ = RFCOMM_EA | cr | (dlci << RFCOMM_SHIFT_DLCI);
520 *p_data++ = RFCOMM_UIH | RFCOMM_PF;
521 *p_data++ = RFCOMM_EA | 0;
523 *p_data = RFCOMM_UIH_FCS ((UINT8 *)(p_buf + 1) + p_buf->offset, dlci);
527 rfc_check_send_cmd(p_mcb, p_buf);
531 /*******************************************************************************
533 ** Function rfc_parse_data
535 ** Description This function processes data packet received from L2CAP
537 *******************************************************************************/
538 UINT8 rfc_parse_data (tRFC_MCB *p_mcb, MX_FRAME *p_frame, BT_HDR *p_buf)
541 UINT8 *p_data = (UINT8 *)(p_buf + 1) + p_buf->offset;
542 UINT8 *p_start = p_data;
545 if (p_buf->len < RFCOMM_CTRL_FRAME_LEN)
547 RFCOMM_TRACE_ERROR ("Bad Length1: %d", p_buf->len);
548 return (RFC_EVENT_BAD_FRAME);
551 RFCOMM_PARSE_CTRL_FIELD (ead, p_frame->cr, p_frame->dlci, p_data);
554 RFCOMM_TRACE_ERROR ("Bad Address(EA must be 1)");
555 return (RFC_EVENT_BAD_FRAME);
557 RFCOMM_PARSE_TYPE_FIELD (p_frame->type, p_frame->pf, p_data);
558 RFCOMM_PARSE_LEN_FIELD (eal, len, p_data);
560 p_buf->len -= (3 + !ead + !eal + 1); /* Additional 1 for FCS */
561 p_buf->offset += (3 + !ead + !eal);
563 /* handle credit if credit based flow control */
564 if ((p_mcb->flow == PORT_FC_CREDIT) && (p_frame->type == RFCOMM_UIH) &&
565 (p_frame->dlci != RFCOMM_MX_DLCI) && (p_frame->pf == 1))
567 p_frame->credit = *p_data++;
574 if (p_buf->len != len)
576 RFCOMM_TRACE_ERROR ("Bad Length2 %d %d", p_buf->len, len);
577 return (RFC_EVENT_BAD_FRAME);
580 fcs = *(p_data + len);
582 /* All control frames that we are sending are sent with P=1, expect */
584 /* According to TS 07.10 spec ivalid frames are discarded without */
585 /* notification to the sender */
586 switch (p_frame->type)
589 if (RFCOMM_FRAME_IS_RSP(p_mcb->is_initiator, p_frame->cr)
590 || !p_frame->pf || len || !RFCOMM_VALID_DLCI (p_frame->dlci)
591 || !rfc_check_fcs (RFCOMM_CTRL_FRAME_LEN, p_start, fcs))
593 RFCOMM_TRACE_ERROR ("Bad SABME");
594 return (RFC_EVENT_BAD_FRAME);
597 return (RFC_EVENT_SABME);
600 if (RFCOMM_FRAME_IS_CMD(p_mcb->is_initiator, p_frame->cr)
601 || !p_frame->pf || len || !RFCOMM_VALID_DLCI (p_frame->dlci)
602 || !rfc_check_fcs (RFCOMM_CTRL_FRAME_LEN, p_start, fcs))
604 RFCOMM_TRACE_ERROR ("Bad UA");
605 return (RFC_EVENT_BAD_FRAME);
608 return (RFC_EVENT_UA);
611 if (RFCOMM_FRAME_IS_CMD(p_mcb->is_initiator, p_frame->cr)
612 || len || !RFCOMM_VALID_DLCI(p_frame->dlci)
613 || !rfc_check_fcs (RFCOMM_CTRL_FRAME_LEN, p_start, fcs))
615 RFCOMM_TRACE_ERROR ("Bad DM");
616 return (RFC_EVENT_BAD_FRAME);
619 return (RFC_EVENT_DM);
622 if (RFCOMM_FRAME_IS_RSP(p_mcb->is_initiator, p_frame->cr)
623 || !p_frame->pf || len || !RFCOMM_VALID_DLCI(p_frame->dlci)
624 || !rfc_check_fcs (RFCOMM_CTRL_FRAME_LEN, p_start, fcs))
626 RFCOMM_TRACE_ERROR ("Bad DISC");
627 return (RFC_EVENT_BAD_FRAME);
630 return (RFC_EVENT_DISC);
633 if (!RFCOMM_VALID_DLCI(p_frame->dlci))
635 RFCOMM_TRACE_ERROR ("Bad UIH - invalid DLCI");
636 return (RFC_EVENT_BAD_FRAME);
638 else if (!rfc_check_fcs (2, p_start, fcs))
640 RFCOMM_TRACE_ERROR ("Bad UIH - FCS");
641 return (RFC_EVENT_BAD_FRAME);
643 else if (RFCOMM_FRAME_IS_RSP(p_mcb->is_initiator, p_frame->cr))
645 /* we assume that this is ok to allow bad implementations to work */
646 RFCOMM_TRACE_ERROR ("Bad UIH - response");
647 return (RFC_EVENT_UIH);
650 return (RFC_EVENT_UIH);
653 return (RFC_EVENT_BAD_FRAME);
657 /*******************************************************************************
659 ** Function rfc_process_mx_message
661 ** Description This function processes UIH frames received on the
662 ** multiplexer control channel.
664 *******************************************************************************/
665 void rfc_process_mx_message (tRFC_MCB *p_mcb, BT_HDR *p_buf)
667 UINT8 *p_data = (UINT8 *)(p_buf + 1) + p_buf->offset;
668 MX_FRAME *p_rx_frame = &rfc_cb.rfc.rx_frame;
669 UINT16 length = p_buf->len;
670 UINT8 ea, cr, mx_len;
673 p_rx_frame->ea = *p_data & RFCOMM_EA;
674 p_rx_frame->cr = (*p_data & RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR;
675 p_rx_frame->type = *p_data++ & ~(RFCOMM_CR_MASK | RFCOMM_EA_MASK);
677 if (!p_rx_frame->ea || !length)
679 RFCOMM_TRACE_ERROR ("Illegal MX Frame ea:%d len:%d", p_rx_frame->ea, length);
686 is_command = p_rx_frame->cr;
688 ea = *p_data & RFCOMM_EA;
690 mx_len = *p_data++ >> RFCOMM_SHIFT_LENGTH1;
695 mx_len += *p_data++ << RFCOMM_SHIFT_LENGTH2;
699 if (mx_len != length)
701 RFCOMM_TRACE_ERROR ("Bad MX frame");
706 switch (p_rx_frame->type)
709 if (length != RFCOMM_MX_PN_LEN)
712 p_rx_frame->dlci = *p_data++ & RFCOMM_PN_DLCI_MASK;
713 p_rx_frame->u.pn.frame_type = *p_data & RFCOMM_PN_FRAME_TYPE_MASK;
714 p_rx_frame->u.pn.conv_layer = *p_data++ & RFCOMM_PN_CONV_LAYER_MASK;
715 p_rx_frame->u.pn.priority = *p_data++ & RFCOMM_PN_PRIORITY_MASK;
716 p_rx_frame->u.pn.t1 = *p_data++;
717 p_rx_frame->u.pn.mtu = *p_data + (*(p_data + 1) << 8);
719 p_rx_frame->u.pn.n2 = *p_data++;
720 p_rx_frame->u.pn.k = *p_data++ & RFCOMM_PN_K_MASK;
722 if (!p_rx_frame->dlci
723 || !RFCOMM_VALID_DLCI (p_rx_frame->dlci)
724 || (p_rx_frame->u.pn.mtu < RFCOMM_MIN_MTU)
725 || (p_rx_frame->u.pn.mtu > RFCOMM_MAX_MTU))
727 RFCOMM_TRACE_ERROR ("Bad PN frame");
733 rfc_process_pn (p_mcb, is_command, p_rx_frame);
740 p_rx_frame->u.test.p_data = p_data;
741 p_rx_frame->u.test.data_len = length;
747 rfc_send_test (p_mcb, FALSE, p_buf);
749 rfc_process_test_rsp (p_mcb, p_buf);
753 if (length != RFCOMM_MX_FCON_LEN)
758 rfc_process_fcon (p_mcb, is_command);
761 case RFCOMM_MX_FCOFF:
762 if (length != RFCOMM_MX_FCOFF_LEN)
767 rfc_process_fcoff (p_mcb, is_command);
772 ea = *p_data & RFCOMM_EA;
773 cr = (*p_data & RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR;
774 p_rx_frame->dlci = *p_data++ >> RFCOMM_SHIFT_DLCI;
776 if (!ea || !cr || !p_rx_frame->dlci
777 || !RFCOMM_VALID_DLCI (p_rx_frame->dlci))
779 RFCOMM_TRACE_ERROR ("Bad MSC frame");
783 p_rx_frame->u.msc.signals = *p_data++;
785 if (mx_len == RFCOMM_MX_MSC_LEN_WITH_BREAK)
787 p_rx_frame->u.msc.break_present = *p_data & RFCOMM_MSC_BREAK_PRESENT_MASK;
788 p_rx_frame->u.msc.break_duration = (*p_data & RFCOMM_MSC_BREAK_MASK) >> RFCOMM_MSC_SHIFT_BREAK;
792 p_rx_frame->u.msc.break_present = FALSE;
793 p_rx_frame->u.msc.break_duration = 0;
797 rfc_process_msc (p_mcb, is_command, p_rx_frame);
801 if ((length != RFCOMM_MX_NSC_LEN) || !is_command)
804 p_rx_frame->u.nsc.ea = *p_data & RFCOMM_EA;
805 p_rx_frame->u.nsc.cr = (*p_data & RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR;
806 p_rx_frame->u.nsc.type = *p_data++ >> RFCOMM_SHIFT_DLCI;
810 rfc_process_nsc (p_mcb, p_rx_frame);
814 if ((length != RFCOMM_MX_RPN_REQ_LEN) && (length != RFCOMM_MX_RPN_LEN))
817 ea = *p_data & RFCOMM_EA;
818 cr = (*p_data & RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR;
819 p_rx_frame->dlci = *p_data++ >> RFCOMM_SHIFT_DLCI;
821 if (!ea || !cr || !p_rx_frame->dlci
822 || !RFCOMM_VALID_DLCI (p_rx_frame->dlci))
824 RFCOMM_TRACE_ERROR ("Bad RPN frame");
828 p_rx_frame->u.rpn.is_request = (length == RFCOMM_MX_RPN_REQ_LEN);
830 if (!p_rx_frame->u.rpn.is_request)
832 p_rx_frame->u.rpn.baud_rate = *p_data++;
833 p_rx_frame->u.rpn.byte_size = (*p_data >> RFCOMM_RPN_BITS_SHIFT) & RFCOMM_RPN_BITS_MASK;
834 p_rx_frame->u.rpn.stop_bits = (*p_data >> RFCOMM_RPN_STOP_BITS_SHIFT) & RFCOMM_RPN_STOP_BITS_MASK;
835 p_rx_frame->u.rpn.parity = (*p_data >> RFCOMM_RPN_PARITY_SHIFT) & RFCOMM_RPN_PARITY_MASK;
836 p_rx_frame->u.rpn.parity_type = (*p_data++ >> RFCOMM_RPN_PARITY_TYPE_SHIFT) & RFCOMM_RPN_PARITY_TYPE_MASK;
838 p_rx_frame->u.rpn.fc_type = *p_data++ & RFCOMM_FC_MASK;
839 p_rx_frame->u.rpn.xon_char = *p_data++;
840 p_rx_frame->u.rpn.xoff_char = *p_data++;
841 p_rx_frame->u.rpn.param_mask = (*p_data + (*(p_data + 1) << 8)) & RFCOMM_RPN_PM_MASK;
845 rfc_process_rpn (p_mcb, is_command, p_rx_frame->u.rpn.is_request, p_rx_frame);
849 if (length != RFCOMM_MX_RLS_LEN)
852 ea = *p_data & RFCOMM_EA;
853 cr = (*p_data & RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR;
855 p_rx_frame->dlci = *p_data++ >> RFCOMM_SHIFT_DLCI;
856 p_rx_frame->u.rls.line_status = (*p_data & ~0x01);
858 if (!ea || !cr || !p_rx_frame->dlci
859 || !RFCOMM_VALID_DLCI (p_rx_frame->dlci))
861 RFCOMM_TRACE_ERROR ("Bad RPN frame");
867 rfc_process_rls (p_mcb, is_command, p_rx_frame);
874 rfc_send_nsc (p_mcb);