1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
24
25
26
27
28
29
30
31
32
33
34
35
36
37
44
45
46
47
48
49
50
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
77
78
79
80
81
82
83
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
110
111
112
113
114
115
116
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
143
144
145
146
147
148
149
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
176
177
178
179
180
181
182
183
186
187
192
193
196
197
198
199
200
201
202
210
211
215
216
217
218
219
220
225
226
227
228
235
236
237
238
239
240
243
244
245
246
247
248
249
250
251
252
253
256
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
282
283
284
285
286
287
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
311
312
313
314
315
316
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
340
341
342
343
344
345
346
347
348
349
350
351
352
355
356
357
358
359
364
365
366
367
368
369
370
371
372
373
374
375
376
380
381
382
383
384
385
386
387
388
395
396
397
398
399
400
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
427
428
429
430
431
432
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
460
461
462
463
464
465
466
469
470
471
472
473
474
475
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
523
524
525
526
527
528
529
530
538
539
544
545
546
547
548
555
556
557
558
559
560
561
562
565
566
567
568
569
570
571
572
573
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
599
600
601
602
603
604
605
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
631
632
633
634
635
636
637
638
642
643
644
648
649
650
651
652
653
654
655
656
663
664
668
669
670
671
672
673
674
675
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
761
762
763
764
765
766
767
768
769
770
771
775
776
781
782
783
784
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
805
806
807
808
809
810
811
812
815
816
817
818
819
820
821
822
827
828
829
830
833
834
835
836
837
838
839
840
843
844
845
846
847
848
849
850
851
852
853
854
855
856
860
861
862
863
870
871
872
873
874
875
876
879
880
881
882
883
884
885
886
887
888
889
890
893
894
895
896
897
898
899
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
927
928
929
930
931
932
933
934
935
939
940
941
942
943
944
945
946
947
948
951
952
953
/* ... */
/* ... */
#include <stddef.h>
#include <string.h>
#include "common/bt_target.h"
#include "stack/rfcdefs.h"
#include "stack/port_api.h"
#include "stack/l2c_api.h"
#include "port_int.h"
#include "rfc_int.h"
#include "osi/mutex.h"
#include "osi/allocator.h"10 includes
#if (defined RFCOMM_INCLUDED && RFCOMM_INCLUDED == TRUE)
/* ... */
void rfc_send_sabme (tRFC_MCB *p_mcb, UINT8 dlci)
{
BT_HDR *p_buf;
UINT8 *p_data;
UINT8 cr = RFCOMM_CR(p_mcb->is_initiator, TRUE);
if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
return;
}{...}
p_buf->offset = L2CAP_MIN_OFFSET;
p_data = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
*p_data++ = RFCOMM_EA | cr | (dlci << RFCOMM_SHIFT_DLCI);
*p_data++ = RFCOMM_SABME | RFCOMM_PF;
*p_data++ = RFCOMM_EA | 0;
*p_data = RFCOMM_SABME_FCS ((UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET, cr, dlci);
p_buf->len = 4;
rfc_check_send_cmd(p_mcb, p_buf);
}{...}
/* ... */
void rfc_send_ua (tRFC_MCB *p_mcb, UINT8 dlci)
{
BT_HDR *p_buf;
UINT8 *p_data;
UINT8 cr = RFCOMM_CR(p_mcb->is_initiator, FALSE);
if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
return;
}{...}
p_buf->offset = L2CAP_MIN_OFFSET;
p_data = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
*p_data++ = RFCOMM_EA | cr | (dlci << RFCOMM_SHIFT_DLCI);
*p_data++ = RFCOMM_UA | RFCOMM_PF;
*p_data++ = RFCOMM_EA | 0;
*p_data = RFCOMM_UA_FCS ((UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET, cr, dlci);
p_buf->len = 4;
rfc_check_send_cmd(p_mcb, p_buf);
}{...}
/* ... */
void rfc_send_dm (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN pf)
{
BT_HDR *p_buf;
UINT8 *p_data;
UINT8 cr = RFCOMM_CR(p_mcb->is_initiator, FALSE);
if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
return;
}{...}
p_buf->offset = L2CAP_MIN_OFFSET;
p_data = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
*p_data++ = RFCOMM_EA | cr | (dlci << RFCOMM_SHIFT_DLCI);
*p_data++ = RFCOMM_DM | ((pf) ? RFCOMM_PF : 0);
*p_data++ = RFCOMM_EA | 0;
*p_data = RFCOMM_DM_FCS ((UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET, cr, dlci);
p_buf->len = 4;
rfc_check_send_cmd(p_mcb, p_buf);
}{...}
/* ... */
void rfc_send_disc (tRFC_MCB *p_mcb, UINT8 dlci)
{
BT_HDR *p_buf;
UINT8 *p_data;
UINT8 cr = RFCOMM_CR(p_mcb->is_initiator, TRUE);
if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
return;
}{...}
p_buf->offset = L2CAP_MIN_OFFSET;
p_data = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
*p_data++ = RFCOMM_EA | cr | (dlci << RFCOMM_SHIFT_DLCI);
*p_data++ = RFCOMM_DISC | RFCOMM_PF;
*p_data++ = RFCOMM_EA | 0;
*p_data = RFCOMM_DISC_FCS ((UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET, cr, dlci);
p_buf->len = 4;
rfc_check_send_cmd(p_mcb, p_buf);
}{...}
/* ... */
void rfc_send_buf_uih (tRFC_MCB *p_mcb, UINT8 dlci, BT_HDR *p_buf)
{
UINT8 *p_data;
UINT8 cr = RFCOMM_CR(p_mcb->is_initiator, TRUE);
UINT8 credits;
p_buf->offset -= RFCOMM_CTRL_FRAME_LEN;
if (p_buf->len > 127) {
p_buf->offset--;
}{...}
if (dlci) {
credits = (UINT8)p_buf->layer_specific;
}{...} else {
credits = 0;
}{...}
if (credits) {
p_buf->offset--;
}{...}
p_data = (UINT8 *)(p_buf + 1) + p_buf->offset;
*p_data++ = RFCOMM_EA | cr | (dlci << RFCOMM_SHIFT_DLCI);
*p_data++ = RFCOMM_UIH | ((credits) ? RFCOMM_PF : 0);
if (p_buf->len <= 127) {
*p_data++ = RFCOMM_EA | (p_buf->len << 1);
p_buf->len += 3;
}{...} else {
*p_data++ = (p_buf->len & 0x7f) << 1;
*p_data++ = p_buf->len >> RFCOMM_SHIFT_LENGTH2;
p_buf->len += 4;
}{...}
if (credits) {
*p_data++ = credits;
p_buf->len++;
}{...}
p_data = (UINT8 *)(p_buf + 1) + p_buf->offset + p_buf->len++;
*p_data = RFCOMM_UIH_FCS ((UINT8 *)(p_buf + 1) + p_buf->offset, dlci);
if (dlci == RFCOMM_MX_DLCI) {
rfc_check_send_cmd(p_mcb, p_buf);
}{...} else {
L2CA_DataWrite (p_mcb->lcid, p_buf);
}{...}
}{...}
/* ... */
void rfc_send_pn (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN is_command, UINT16 mtu, UINT8 cl, UINT8 k)
{
BT_HDR *p_buf;
UINT8 *p_data;
if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
return;
}{...}
p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN;
p_data = (UINT8 *)(p_buf + 1) + p_buf->offset;
*p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_PN;
*p_data++ = RFCOMM_EA | (RFCOMM_MX_PN_LEN << 1);
*p_data++ = dlci;
*p_data++ = RFCOMM_PN_FRAM_TYPE_UIH | cl;
/* ... */
if (is_command) {
*p_data++ = RFCOMM_PN_PRIORITY_0;
}{...} else {
*p_data++ = rfc_cb.rfc.rx_frame.u.pn.priority;
}{...}
*p_data++ = RFCOMM_T1_DSEC;
*p_data++ = mtu & 0xFF;
*p_data++ = mtu >> 8;
*p_data++ = RFCOMM_N2;
*p_data = k;
p_buf->len = RFCOMM_MX_PN_LEN + 2;
rfc_send_buf_uih (p_mcb, RFCOMM_MX_DLCI, p_buf);
}{...}
/* ... */
void rfc_send_fcon (tRFC_MCB *p_mcb, BOOLEAN is_command)
{
BT_HDR *p_buf;
UINT8 *p_data;
if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
return;
}{...}
p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN;
p_data = (UINT8 *)(p_buf + 1) + p_buf->offset;
*p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_FCON;
*p_data++ = RFCOMM_EA | (RFCOMM_MX_FCON_LEN << 1);
p_buf->len = RFCOMM_MX_FCON_LEN + 2;
rfc_send_buf_uih (p_mcb, RFCOMM_MX_DLCI, p_buf);
}{...}
/* ... */
void rfc_send_fcoff (tRFC_MCB *p_mcb, BOOLEAN is_command)
{
BT_HDR *p_buf;
UINT8 *p_data;
if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
return;
}{...}
p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN;
p_data = (UINT8 *)(p_buf + 1) + p_buf->offset;
*p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_FCOFF;
*p_data++ = RFCOMM_EA | (RFCOMM_MX_FCOFF_LEN << 1);
p_buf->len = RFCOMM_MX_FCOFF_LEN + 2;
rfc_send_buf_uih (p_mcb, RFCOMM_MX_DLCI, p_buf);
}{...}
/* ... */
void rfc_send_msc (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN is_command,
tPORT_CTRL *p_pars)
{
BT_HDR *p_buf;
UINT8 *p_data;
UINT8 signals;
UINT8 break_duration;
UINT8 len;
signals = p_pars->modem_signal;
break_duration = p_pars->break_signal;
if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
return;
}{...}
p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN;
p_data = (UINT8 *)(p_buf + 1) + p_buf->offset;
if (break_duration) {
len = RFCOMM_MX_MSC_LEN_WITH_BREAK;
}{...} else {
len = RFCOMM_MX_MSC_LEN_NO_BREAK;
}{...}
*p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_MSC;
*p_data++ = RFCOMM_EA | (len << 1);
*p_data++ = RFCOMM_EA | RFCOMM_CR_MASK | (dlci << RFCOMM_SHIFT_DLCI);
*p_data++ = RFCOMM_EA |
((p_pars->fc) ? RFCOMM_MSC_FC : 0) |
((signals & MODEM_SIGNAL_DTRDSR) ? RFCOMM_MSC_RTC : 0) |
((signals & MODEM_SIGNAL_RTSCTS) ? RFCOMM_MSC_RTR : 0) |
((signals & MODEM_SIGNAL_RI) ? RFCOMM_MSC_IC : 0) |
((signals & MODEM_SIGNAL_DCD) ? RFCOMM_MSC_DV : 0);
if (break_duration) {
*p_data++ = RFCOMM_EA | RFCOMM_MSC_BREAK_PRESENT_MASK |
(break_duration << RFCOMM_MSC_SHIFT_BREAK);
}{...}
p_buf->len = len + 2;
rfc_send_buf_uih (p_mcb, RFCOMM_MX_DLCI, p_buf);
}{...}
/* ... */
void rfc_send_rls (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN is_command, UINT8 status)
{
BT_HDR *p_buf;
UINT8 *p_data;
if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
return;
}{...}
p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN;
p_data = (UINT8 *)(p_buf + 1) + p_buf->offset;
*p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_RLS;
*p_data++ = RFCOMM_EA | (RFCOMM_MX_RLS_LEN << 1);
*p_data++ = RFCOMM_EA | RFCOMM_CR_MASK | (dlci << RFCOMM_SHIFT_DLCI);
*p_data++ = RFCOMM_RLS_ERROR | status;
p_buf->len = RFCOMM_MX_RLS_LEN + 2;
rfc_send_buf_uih (p_mcb, RFCOMM_MX_DLCI, p_buf);
}{...}
/* ... */
void rfc_send_nsc (tRFC_MCB *p_mcb)
{
BT_HDR *p_buf;
UINT8 *p_data;
if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
return;
}{...}
p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN;
p_data = (UINT8 *)(p_buf + 1) + p_buf->offset;
*p_data++ = RFCOMM_EA | RFCOMM_I_CR(FALSE) | RFCOMM_MX_NSC;
*p_data++ = RFCOMM_EA | (RFCOMM_MX_NSC_LEN << 1);
*p_data++ = rfc_cb.rfc.rx_frame.ea |
(rfc_cb.rfc.rx_frame.cr << RFCOMM_SHIFT_CR) |
rfc_cb.rfc.rx_frame.type;
p_buf->len = RFCOMM_MX_NSC_LEN + 2;
rfc_send_buf_uih (p_mcb, RFCOMM_MX_DLCI, p_buf);
}{...}
/* ... */
void rfc_send_rpn (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN is_command,
tPORT_STATE *p_pars, UINT16 mask)
{
BT_HDR *p_buf;
UINT8 *p_data;
if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
return;
}{...}
p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN;
p_data = (UINT8 *)(p_buf + 1) + p_buf->offset;
*p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_RPN;
if (!p_pars) {
*p_data++ = RFCOMM_EA | (RFCOMM_MX_RPN_REQ_LEN << 1);
*p_data++ = RFCOMM_EA | RFCOMM_CR_MASK | (dlci << RFCOMM_SHIFT_DLCI);
p_buf->len = RFCOMM_MX_RPN_REQ_LEN + 2;
}{...} else {
*p_data++ = RFCOMM_EA | (RFCOMM_MX_RPN_LEN << 1);
*p_data++ = RFCOMM_EA | RFCOMM_CR_MASK | (dlci << RFCOMM_SHIFT_DLCI);
*p_data++ = p_pars->baud_rate;
*p_data++ = (p_pars->byte_size << RFCOMM_RPN_BITS_SHIFT)
| (p_pars->stop_bits << RFCOMM_RPN_STOP_BITS_SHIFT)
| (p_pars->parity << RFCOMM_RPN_PARITY_SHIFT)
| (p_pars->parity_type << RFCOMM_RPN_PARITY_TYPE_SHIFT);
*p_data++ = p_pars->fc_type;
*p_data++ = p_pars->xon_char;
*p_data++ = p_pars->xoff_char;
*p_data++ = (mask & 0xFF);
*p_data++ = (mask >> 8);
p_buf->len = RFCOMM_MX_RPN_LEN + 2;
}{...}
rfc_send_buf_uih (p_mcb, RFCOMM_MX_DLCI, p_buf);
}{...}
#if BT_RFCOMM_BQB_INCLUDED
/* ... */
void rfc_bqb_send_msc_cmd(BD_ADDR cert_pts_addr)
{
UINT8 i;
UINT8 dlci;
BOOLEAN get_dlci = FALSE;
tPORT *p_port;
tPORT_CTRL *p_pars;
tRFC_MCB *p_mcb;
if ((p_pars = (tPORT_CTRL *)osi_malloc(sizeof(tPORT_CTRL))) == NULL) {
return;
}{...}
p_pars->modem_signal = 0;
p_pars->break_signal = 0;
p_pars->fc = TRUE;
p_mcb = port_find_mcb (cert_pts_addr);
for (i = 0; i < MAX_RFC_PORTS; i++) {
p_port = &rfc_cb.port.port[i];
if (p_port->in_use && !memcmp (p_port->bd_addr, cert_pts_addr, BD_ADDR_LEN)) {
dlci = p_port->dlci;
get_dlci = TRUE;
break;
}{...}
}{...}
if (get_dlci) {
rfc_send_msc(p_mcb, dlci, TRUE, p_pars);
}{...} else {
RFCOMM_TRACE_ERROR ("Get dlci fail");
}{...}
osi_free(p_pars);
}{...}
/* ... */#endif
/* ... */
void rfc_send_test (tRFC_MCB *p_mcb, BOOLEAN is_command, BT_HDR *p_buf)
{
UINT8 *p_data;
UINT16 xx;
UINT8 *p_src, *p_dest;
BT_HDR *p_buf_new;
if ((p_buf_new = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
return;
}{...}
memcpy(p_buf_new, p_buf, sizeof(BT_HDR) + p_buf->offset + p_buf->len);
osi_free(p_buf);
p_buf = p_buf_new;
if (p_buf->offset < (L2CAP_MIN_OFFSET + RFCOMM_MIN_OFFSET + 2)) {
p_src = (UINT8 *) (p_buf + 1) + p_buf->offset + p_buf->len - 1;
p_dest = (UINT8 *) (p_buf + 1) + L2CAP_MIN_OFFSET + RFCOMM_MIN_OFFSET + 2 + p_buf->len - 1;
for (xx = 0; xx < p_buf->len; xx++) {
*p_dest-- = *p_src--;
}{...}
p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_MIN_OFFSET + 2;
}{...}
p_buf->offset -= 2;
p_data = (UINT8 *)(p_buf + 1) + p_buf->offset;
*p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_TEST;
*p_data++ = RFCOMM_EA | (p_buf->len << 1);
p_buf->len += 2;
rfc_send_buf_uih (p_mcb, RFCOMM_MX_DLCI, p_buf);
}{...}
/* ... */
void rfc_send_credit(tRFC_MCB *p_mcb, UINT8 dlci, UINT8 credit)
{
BT_HDR *p_buf;
UINT8 *p_data;
UINT8 cr = RFCOMM_CR(p_mcb->is_initiator, TRUE);
if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
return;
}{...}
p_buf->offset = L2CAP_MIN_OFFSET;
p_data = (UINT8 *)(p_buf + 1) + p_buf->offset;
*p_data++ = RFCOMM_EA | cr | (dlci << RFCOMM_SHIFT_DLCI);
*p_data++ = RFCOMM_UIH | RFCOMM_PF;
*p_data++ = RFCOMM_EA | 0;
*p_data++ = credit;
*p_data = RFCOMM_UIH_FCS ((UINT8 *)(p_buf + 1) + p_buf->offset, dlci);
p_buf->len = 5;
rfc_check_send_cmd(p_mcb, p_buf);
}{...}
/* ... */
UINT8 rfc_parse_data (tRFC_MCB *p_mcb, MX_FRAME *p_frame, BT_HDR *p_buf)
{
UINT8 ead, eal, fcs;
UINT8 *p_data = (UINT8 *)(p_buf + 1) + p_buf->offset;
UINT8 *p_start = p_data;
UINT16 len;
if (p_buf->len < RFCOMM_CTRL_FRAME_LEN) {
RFCOMM_TRACE_ERROR ("Bad Length1: %d", p_buf->len);
return (RFC_EVENT_BAD_FRAME);
}{...}
RFCOMM_PARSE_CTRL_FIELD (ead, p_frame->cr, p_frame->dlci, p_data);
if ( !ead ) {
RFCOMM_TRACE_ERROR ("Bad Address(EA must be 1)");
return (RFC_EVENT_BAD_FRAME);
}{...}
RFCOMM_PARSE_TYPE_FIELD (p_frame->type, p_frame->pf, p_data);
RFCOMM_PARSE_LEN_FIELD (eal, len, p_data);
p_buf->len -= (3 + !ead + !eal + 1);
p_buf->offset += (3 + !ead + !eal);
if ((p_mcb->flow == PORT_FC_CREDIT) && (p_frame->type == RFCOMM_UIH) &&
(p_frame->dlci != RFCOMM_MX_DLCI) && (p_frame->pf == 1)) {
p_frame->credit = *p_data++;
p_buf->len--;
p_buf->offset++;
}{...} else {
p_frame->credit = 0;
}{...}
if (p_buf->len != len) {
RFCOMM_TRACE_ERROR ("Bad Length2 %d %d", p_buf->len, len);
return (RFC_EVENT_BAD_FRAME);
}{...}
fcs = *(p_data + len);
switch (p_frame->type) {
case RFCOMM_SABME:
if (RFCOMM_FRAME_IS_RSP(p_mcb->is_initiator, p_frame->cr)
|| !p_frame->pf || len || !RFCOMM_VALID_DLCI (p_frame->dlci)
|| !rfc_check_fcs (RFCOMM_CTRL_FRAME_LEN, p_start, fcs)) {
RFCOMM_TRACE_ERROR ("Bad SABME");
return (RFC_EVENT_BAD_FRAME);
}{...} else {
return (RFC_EVENT_SABME);
}{...}
...
case RFCOMM_UA:
if (RFCOMM_FRAME_IS_CMD(p_mcb->is_initiator, p_frame->cr)
|| !p_frame->pf || len || !RFCOMM_VALID_DLCI (p_frame->dlci)
|| !rfc_check_fcs (RFCOMM_CTRL_FRAME_LEN, p_start, fcs)) {
RFCOMM_TRACE_ERROR ("Bad UA");
return (RFC_EVENT_BAD_FRAME);
}{...} else {
return (RFC_EVENT_UA);
}{...}
...
case RFCOMM_DM:
if (RFCOMM_FRAME_IS_CMD(p_mcb->is_initiator, p_frame->cr)
|| len || !RFCOMM_VALID_DLCI(p_frame->dlci)
|| !rfc_check_fcs (RFCOMM_CTRL_FRAME_LEN, p_start, fcs)) {
RFCOMM_TRACE_ERROR ("Bad DM");
return (RFC_EVENT_BAD_FRAME);
}{...} else {
return (RFC_EVENT_DM);
}{...}
...
case RFCOMM_DISC:
if (RFCOMM_FRAME_IS_RSP(p_mcb->is_initiator, p_frame->cr)
|| !p_frame->pf || len || !RFCOMM_VALID_DLCI(p_frame->dlci)
|| !rfc_check_fcs (RFCOMM_CTRL_FRAME_LEN, p_start, fcs)) {
RFCOMM_TRACE_ERROR ("Bad DISC");
return (RFC_EVENT_BAD_FRAME);
}{...} else {
return (RFC_EVENT_DISC);
}{...}
...
case RFCOMM_UIH:
if (!RFCOMM_VALID_DLCI(p_frame->dlci)) {
RFCOMM_TRACE_ERROR ("Bad UIH - invalid DLCI");
return (RFC_EVENT_BAD_FRAME);
}{...} else if (!rfc_check_fcs (2, p_start, fcs)) {
RFCOMM_TRACE_ERROR ("Bad UIH - FCS");
return (RFC_EVENT_BAD_FRAME);
}{...} else if (RFCOMM_FRAME_IS_RSP(p_mcb->is_initiator, p_frame->cr)) {
RFCOMM_TRACE_ERROR ("Bad UIH - response");
return (RFC_EVENT_UIH);
}{...} else {
return (RFC_EVENT_UIH);
}{...}
... }{...}
return (RFC_EVENT_BAD_FRAME);
}{...}
/* ... */
void rfc_process_mx_message (tRFC_MCB *p_mcb, BT_HDR *p_buf)
{
UINT8 *p_data = (UINT8 *)(p_buf + 1) + p_buf->offset;
MX_FRAME *p_rx_frame = &rfc_cb.rfc.rx_frame;
UINT16 length = p_buf->len;
UINT8 ea, cr, mx_len;
BOOLEAN is_command;
p_rx_frame->ea = *p_data & RFCOMM_EA;
p_rx_frame->cr = (*p_data & RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR;
p_rx_frame->type = *p_data++ & ~(RFCOMM_CR_MASK | RFCOMM_EA_MASK);
if (!p_rx_frame->ea || !length) {
RFCOMM_TRACE_ERROR ("Illegal MX Frame ea:%d len:%d", p_rx_frame->ea, length);
osi_free (p_buf);
return;
}{...}
length--;
is_command = p_rx_frame->cr;
ea = *p_data & RFCOMM_EA;
mx_len = *p_data++ >> RFCOMM_SHIFT_LENGTH1;
length--;
if (!ea) {
mx_len += *p_data++ << RFCOMM_SHIFT_LENGTH2;
length --;
}{...}
if (mx_len != length) {
RFCOMM_TRACE_ERROR ("Bad MX frame");
osi_free (p_buf);
return;
}{...}
switch (p_rx_frame->type) {
case RFCOMM_MX_PN:
if (length != RFCOMM_MX_PN_LEN) {
break;
}{...}
p_rx_frame->dlci = *p_data++ & RFCOMM_PN_DLCI_MASK;
p_rx_frame->u.pn.frame_type = *p_data & RFCOMM_PN_FRAME_TYPE_MASK;
p_rx_frame->u.pn.conv_layer = *p_data++ & RFCOMM_PN_CONV_LAYER_MASK;
p_rx_frame->u.pn.priority = *p_data++ & RFCOMM_PN_PRIORITY_MASK;
p_rx_frame->u.pn.t1 = *p_data++;
p_rx_frame->u.pn.mtu = *p_data + (*(p_data + 1) << 8);
p_data += 2;
p_rx_frame->u.pn.n2 = *p_data++;
p_rx_frame->u.pn.k = *p_data++ & RFCOMM_PN_K_MASK;
if (!p_rx_frame->dlci
|| !RFCOMM_VALID_DLCI (p_rx_frame->dlci)
|| (p_rx_frame->u.pn.mtu < RFCOMM_MIN_MTU)
|| (p_rx_frame->u.pn.mtu > RFCOMM_MAX_MTU)) {
RFCOMM_TRACE_ERROR ("Bad PN frame");
break;
}{...}
osi_free (p_buf);
rfc_process_pn (p_mcb, is_command, p_rx_frame);
return;
...
case RFCOMM_MX_TEST:
if (!length) {
break;
}{...}
p_rx_frame->u.test.p_data = p_data;
p_rx_frame->u.test.data_len = length;
p_buf->offset += 2;
p_buf->len -= 2;
if (is_command) {
rfc_send_test (p_mcb, FALSE, p_buf);
}{...} else {
rfc_process_test_rsp (p_mcb, p_buf);
}{...}
return;
...
case RFCOMM_MX_FCON:
if (length != RFCOMM_MX_FCON_LEN) {
break;
}{...}
osi_free (p_buf);
rfc_process_fcon (p_mcb, is_command);
return;
...
case RFCOMM_MX_FCOFF:
if (length != RFCOMM_MX_FCOFF_LEN) {
break;
}{...}
osi_free (p_buf);
rfc_process_fcoff (p_mcb, is_command);
return;
...
case RFCOMM_MX_MSC:
ea = *p_data & RFCOMM_EA;
cr = (*p_data & RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR;
p_rx_frame->dlci = *p_data++ >> RFCOMM_SHIFT_DLCI;
if (!ea || !cr || !p_rx_frame->dlci
|| !RFCOMM_VALID_DLCI (p_rx_frame->dlci)) {
RFCOMM_TRACE_ERROR ("Bad MSC frame");
break;
}{...}
p_rx_frame->u.msc.signals = *p_data++;
if (mx_len == RFCOMM_MX_MSC_LEN_WITH_BREAK) {
p_rx_frame->u.msc.break_present = *p_data & RFCOMM_MSC_BREAK_PRESENT_MASK;
p_rx_frame->u.msc.break_duration = (*p_data & RFCOMM_MSC_BREAK_MASK) >> RFCOMM_MSC_SHIFT_BREAK;
}{...} else {
p_rx_frame->u.msc.break_present = FALSE;
p_rx_frame->u.msc.break_duration = 0;
}{...}
osi_free (p_buf);
rfc_process_msc (p_mcb, is_command, p_rx_frame);
return;
...
case RFCOMM_MX_NSC:
if ((length != RFCOMM_MX_NSC_LEN) || !is_command) {
break;
}{...}
p_rx_frame->u.nsc.ea = *p_data & RFCOMM_EA;
p_rx_frame->u.nsc.cr = (*p_data & RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR;
p_rx_frame->u.nsc.type = *p_data++ >> RFCOMM_SHIFT_DLCI;
osi_free (p_buf);
rfc_process_nsc (p_mcb, p_rx_frame);
return;
...
case RFCOMM_MX_RPN:
if ((length != RFCOMM_MX_RPN_REQ_LEN) && (length != RFCOMM_MX_RPN_LEN)) {
break;
}{...}
ea = *p_data & RFCOMM_EA;
cr = (*p_data & RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR;
p_rx_frame->dlci = *p_data++ >> RFCOMM_SHIFT_DLCI;
if (!ea || !cr || !p_rx_frame->dlci
|| !RFCOMM_VALID_DLCI (p_rx_frame->dlci)) {
RFCOMM_TRACE_ERROR ("Bad RPN frame");
break;
}{...}
p_rx_frame->u.rpn.is_request = (length == RFCOMM_MX_RPN_REQ_LEN);
if (!p_rx_frame->u.rpn.is_request) {
p_rx_frame->u.rpn.baud_rate = *p_data++;
p_rx_frame->u.rpn.byte_size = (*p_data >> RFCOMM_RPN_BITS_SHIFT) & RFCOMM_RPN_BITS_MASK;
p_rx_frame->u.rpn.stop_bits = (*p_data >> RFCOMM_RPN_STOP_BITS_SHIFT) & RFCOMM_RPN_STOP_BITS_MASK;
p_rx_frame->u.rpn.parity = (*p_data >> RFCOMM_RPN_PARITY_SHIFT) & RFCOMM_RPN_PARITY_MASK;
p_rx_frame->u.rpn.parity_type = (*p_data++ >> RFCOMM_RPN_PARITY_TYPE_SHIFT) & RFCOMM_RPN_PARITY_TYPE_MASK;
p_rx_frame->u.rpn.fc_type = *p_data++ & RFCOMM_FC_MASK;
p_rx_frame->u.rpn.xon_char = *p_data++;
p_rx_frame->u.rpn.xoff_char = *p_data++;
p_rx_frame->u.rpn.param_mask = (*p_data + (*(p_data + 1) << 8)) & RFCOMM_RPN_PM_MASK;
}{...}
osi_free (p_buf);
rfc_process_rpn (p_mcb, is_command, p_rx_frame->u.rpn.is_request, p_rx_frame);
return;
...
case RFCOMM_MX_RLS:
if (length != RFCOMM_MX_RLS_LEN) {
break;
}{...}
ea = *p_data & RFCOMM_EA;
cr = (*p_data & RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR;
p_rx_frame->dlci = *p_data++ >> RFCOMM_SHIFT_DLCI;
p_rx_frame->u.rls.line_status = (*p_data & ~0x01);
if (!ea || !cr || !p_rx_frame->dlci
|| !RFCOMM_VALID_DLCI (p_rx_frame->dlci)) {
RFCOMM_TRACE_ERROR ("Bad RPN frame");
break;
}{...}
osi_free (p_buf);
rfc_process_rls (p_mcb, is_command, p_rx_frame);
return;...
}{...}
osi_free (p_buf);
if (is_command) {
rfc_send_nsc (p_mcb);
}{...}
}{...}
/* ... */
#endif