1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
136
137
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
190
191
192
193
194
197
198
199
203
204
205
206
215
216
217
218
223
224
225
230
231
232
237
238
239
240
241
247
248
249
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
271
274
275
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
329
330
331
332
333
336
337
338
339
343
344
345
346
347
348
352
353
354
355
356
359
360
361
365
366
370
371
372
376
377
381
382
383
384
385
386
387
390
391
392
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
420
421
422
423
434
439
440
441
442
443
444
445
446
447
450
451
452
458
459
460
462
465
466
467
468
469
470
471
472
477
478
479
480
481
482
483
484
485
486
487
488
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
571
572
573
574
575
578
579
580
581
585
586
587
588
589
590
591
594
595
596
600
601
605
606
607
611
612
616
617
618
619
620
621
622
623
624
627
628
629
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
659
660
661
662
663
664
665
666
667
668
669
675
676
677
678
690
695
696
697
698
699
700
701
702
703
704
707
708
709
715
716
717
718
719
732
733
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
770
771
772
773
774
775
776
781
782
783
784
785
786
787
788
789
790
791
792
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
825
826
827
828
829
830
831
832
833
834
835
836
837
838
/* ... */
/* ... */
#include <string.h>
#include "stack/bt_types.h"
#include "osi/allocator.h"
#include "stack/btu.h"
#include "common/bt_defs.h"
#include "stack/l2cdefs.h"
#include "stack/hcidefs.h"
#include "stack/hcimsgs.h"
#include "stack/sdp_api.h"
#include "sdpint.h"10 includes
#if SDP_SERVER_ENABLED == TRUE
#define SDP_MAX_SERVICE_RSPHDR_LEN 12
#define SDP_MAX_SERVATTR_RSPHDR_LEN 10
#define SDP_MAX_ATTR_RSPHDR_LEN 10
static void process_service_search (tCONN_CB *p_ccb, UINT16 trans_num,
UINT16 param_len, UINT8 *p_req,
UINT8 *p_req_end);
static void process_service_attr_req (tCONN_CB *p_ccb, UINT16 trans_num,
UINT16 param_len, UINT8 *p_req,
UINT8 *p_req_end);
static void process_service_search_attr_req (tCONN_CB *p_ccb, UINT16 trans_num,
UINT16 param_len, UINT8 *p_req,
UINT8 *p_req_end);
...
...
#ifndef SDP_TEXT_BAD_HEADER
#define SDP_TEXT_BAD_HEADER NULL
#endif
#ifndef SDP_TEXT_BAD_PDU
#define SDP_TEXT_BAD_PDU NULL
#endif
#ifndef SDP_TEXT_BAD_UUID_LIST
#define SDP_TEXT_BAD_UUID_LIST NULL
#endif
#ifndef SDP_TEXT_BAD_HANDLE
#define SDP_TEXT_BAD_HANDLE NULL
#endif
#ifndef SDP_TEXT_BAD_ATTR_LIST
#define SDP_TEXT_BAD_ATTR_LIST NULL
#endif
#ifndef SDP_TEXT_BAD_CONT_LEN
#define SDP_TEXT_BAD_CONT_LEN NULL
#endif
#ifndef SDP_TEXT_BAD_CONT_INX
#define SDP_TEXT_BAD_CONT_INX NULL
#endif
#ifndef SDP_TEXT_BAD_MAX_RECORDS_LIST
#define SDP_TEXT_BAD_MAX_RECORDS_LIST NULL
#endif
/* ... */
void sdp_server_handle_client_req (tCONN_CB *p_ccb, BT_HDR *p_msg)
{
UINT8 *p_req = (UINT8 *) (p_msg + 1) + p_msg->offset;
UINT8 *p_req_end = p_req + p_msg->len;
UINT8 pdu_id;
UINT16 trans_num, param_len;
btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_SDP, SDP_INACT_TIMEOUT);
pdu_id = *p_req++;
BE_STREAM_TO_UINT16 (trans_num, p_req);
BE_STREAM_TO_UINT16 (param_len, p_req);
if ((p_req + param_len) != p_req_end) {
sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_PDU_SIZE, SDP_TEXT_BAD_HEADER);
return;
}{...}
switch (pdu_id) {
case SDP_PDU_SERVICE_SEARCH_REQ:
process_service_search (p_ccb, trans_num, param_len, p_req, p_req_end);
break;
...
case SDP_PDU_SERVICE_ATTR_REQ:
process_service_attr_req (p_ccb, trans_num, param_len, p_req, p_req_end);
break;
...
case SDP_PDU_SERVICE_SEARCH_ATTR_REQ:
process_service_search_attr_req (p_ccb, trans_num, param_len, p_req, p_req_end);
break;
...
default:
sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_REQ_SYNTAX, SDP_TEXT_BAD_PDU);
SDP_TRACE_WARNING ("SDP - server got unknown PDU: 0x%x\n", pdu_id);
break;...
}{...}
}{...}
/* ... */
static void process_service_search (tCONN_CB *p_ccb, UINT16 trans_num,
UINT16 param_len, UINT8 *p_req,
UINT8 *p_req_end)
{
UINT16 max_replies, cur_handles, rem_handles, cont_offset;
tSDP_UUID_SEQ uid_seq;
UINT8 *p_rsp, *p_rsp_start, *p_rsp_param_len;
UINT16 rsp_param_len, num_rsp_handles, xx;
UINT32 rsp_handles[SDP_MAX_RECORDS] = {0};
tSDP_RECORD *p_rec = NULL;
BT_HDR *p_buf;
BOOLEAN is_cont = FALSE;
UNUSED(p_req_end);
p_req = sdpu_extract_uid_seq (p_req, param_len, &uid_seq);
if ((!p_req) || (!uid_seq.num_uids)) {
sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_REQ_SYNTAX, SDP_TEXT_BAD_UUID_LIST);
return;
}{...}
BE_STREAM_TO_UINT16 (max_replies, p_req);
if (max_replies > SDP_MAX_RECORDS) {
max_replies = SDP_MAX_RECORDS;
}{...}
if ((!p_req) || (p_req > p_req_end)) {
sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_REQ_SYNTAX, SDP_TEXT_BAD_MAX_RECORDS_LIST);
return;
}{...}
for (num_rsp_handles = 0; num_rsp_handles < max_replies; ) {
p_rec = sdp_db_service_search (p_rec, &uid_seq);
if (p_rec) {
rsp_handles[num_rsp_handles++] = p_rec->record_handle;
}{...} else {
break;
}{...}
}{...}
if (*p_req) {
if (*p_req++ != SDP_CONTINUATION_LEN || (p_req >= p_req_end)) {
sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_CONT_STATE,
SDP_TEXT_BAD_CONT_LEN);
return;
}{...}
BE_STREAM_TO_UINT16 (cont_offset, p_req);
if (cont_offset != p_ccb->cont_offset || num_rsp_handles < cont_offset) {
sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_CONT_STATE,
SDP_TEXT_BAD_CONT_INX);
return;
}{...}
rem_handles = num_rsp_handles - cont_offset;
}{...} else {
rem_handles = num_rsp_handles;
cont_offset = 0;
p_ccb->cont_offset = 0;
}{...}
cur_handles = (UINT16)((p_ccb->rem_mtu_size - SDP_MAX_SERVICE_RSPHDR_LEN) / 4);
if (rem_handles <= cur_handles) {
cur_handles = rem_handles;
}{...} else {
p_ccb->cont_offset += cur_handles;
is_cont = TRUE;
}{...}
if ((p_buf = (BT_HDR *)osi_malloc(SDP_DATA_BUF_SIZE)) == NULL) {
SDP_TRACE_ERROR ("SDP - no buf for search rsp\n");
return;
}{...}
p_buf->offset = L2CAP_MIN_OFFSET;
p_rsp = p_rsp_start = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
UINT8_TO_BE_STREAM (p_rsp, SDP_PDU_SERVICE_SEARCH_RSP);
UINT16_TO_BE_STREAM (p_rsp, trans_num);
p_rsp_param_len = p_rsp;
p_rsp += 2;
UINT16_TO_BE_STREAM (p_rsp, num_rsp_handles);
UINT16_TO_BE_STREAM (p_rsp, cur_handles);
/* ... */
for (xx = cont_offset; xx < cont_offset + cur_handles; xx++) {
UINT32_TO_BE_STREAM (p_rsp, rsp_handles[xx]);
}{...}
if (is_cont) {
UINT8_TO_BE_STREAM (p_rsp, SDP_CONTINUATION_LEN);
UINT16_TO_BE_STREAM (p_rsp, p_ccb->cont_offset);
}{...} else {
UINT8_TO_BE_STREAM (p_rsp, 0);
}{...}
rsp_param_len = p_rsp - p_rsp_param_len - 2;
UINT16_TO_BE_STREAM (p_rsp_param_len, rsp_param_len);
p_buf->len = p_rsp - p_rsp_start;
L2CA_DataWrite (p_ccb->connection_id, p_buf);
}{...}
/* ... */
static void process_service_attr_req (tCONN_CB *p_ccb, UINT16 trans_num,
UINT16 param_len, UINT8 *p_req,
UINT8 *p_req_end)
{
UINT16 max_list_len, len_to_send, cont_offset;
INT16 rem_len;
tSDP_ATTR_SEQ attr_seq, attr_seq_sav;
UINT8 *p_rsp, *p_rsp_start, *p_rsp_param_len;
UINT16 rsp_param_len, xx;
UINT32 rec_handle;
tSDP_RECORD *p_rec;
tSDP_ATTRIBUTE *p_attr;
BT_HDR *p_buf;
BOOLEAN is_cont = FALSE;
UINT16 attr_len;
BE_STREAM_TO_UINT32 (rec_handle, p_req);
if (p_req > p_req_end) {
sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_SERV_REC_HDL, SDP_TEXT_BAD_HANDLE);
return;
}{...}
BE_STREAM_TO_UINT16 (max_list_len, p_req);
if (max_list_len > (p_ccb->rem_mtu_size - SDP_MAX_ATTR_RSPHDR_LEN)) {
max_list_len = p_ccb->rem_mtu_size - SDP_MAX_ATTR_RSPHDR_LEN;
}{...}
p_req = sdpu_extract_attr_seq (p_req, param_len, &attr_seq);
if ((!p_req) || (!attr_seq.num_attr) || (p_req > p_req_end)) {
sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_REQ_SYNTAX, SDP_TEXT_BAD_ATTR_LIST);
return;
}{...}
memcpy(&attr_seq_sav, &attr_seq, sizeof(tSDP_ATTR_SEQ)) ;
p_rec = sdp_db_find_record (rec_handle);
if (!p_rec) {
sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_SERV_REC_HDL, SDP_TEXT_BAD_HANDLE);
return;
}{...}
if (*p_req) {
if (p_ccb->rsp_list) {
osi_free(p_ccb->rsp_list);
}{...}
p_ccb->rsp_list = (UINT8 *)osi_malloc(max_list_len);
if (p_ccb->rsp_list == NULL) {
SDP_TRACE_ERROR("%s No scratch buf for attr rsp\n", __func__);
return;
}{...}
if (*p_req++ != SDP_CONTINUATION_LEN) {
sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_CONT_STATE, SDP_TEXT_BAD_CONT_LEN);
return;
}{...}
BE_STREAM_TO_UINT16 (cont_offset, p_req);
if (cont_offset != p_ccb->cont_offset) {
sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_CONT_STATE, SDP_TEXT_BAD_CONT_INX);
return;
}{...}
if (!p_ccb->rsp_list) {
sdpu_build_n_send_error (p_ccb, trans_num, SDP_NO_RESOURCES, NULL);
return;
}{...}
is_cont = TRUE;
p_rsp = &p_ccb->rsp_list[0];
attr_seq.attr_entry[p_ccb->cont_info.next_attr_index].start = p_ccb->cont_info.next_attr_start_id;
}{...} else {
if (p_ccb->rsp_list) {
osi_free (p_ccb->rsp_list);
}{...}
p_ccb->rsp_list = (UINT8 *)osi_malloc (max_list_len);
if (p_ccb->rsp_list == NULL) {
SDP_TRACE_ERROR ("SDP - no scratch buf for search rsp\n");
return;
}{...}
p_ccb->cont_offset = 0;
p_rsp = &p_ccb->rsp_list[3];
p_ccb->cont_info.prev_sdp_rec = NULL;
p_ccb->cont_info.next_attr_index = 0;
p_ccb->cont_info.attr_offset = 0;
}{...}
for (xx = p_ccb->cont_info.next_attr_index; xx < attr_seq.num_attr; xx++) {
p_attr = sdp_db_find_attr_in_rec (p_rec, attr_seq.attr_entry[xx].start, attr_seq.attr_entry[xx].end);
if (p_attr) {
rem_len = max_list_len - (INT16) (p_rsp - &p_ccb->rsp_list[0]);
if (rem_len <= 0) {
p_ccb->cont_info.next_attr_index = xx;
p_ccb->cont_info.next_attr_start_id = p_attr->id;
break;
}{...}
attr_len = sdpu_get_attrib_entry_len(p_attr);
if (p_ccb->cont_info.attr_offset) {
p_rsp = sdpu_build_partial_attrib_entry (p_rsp, p_attr, rem_len,
&p_ccb->cont_info.attr_offset);
if (p_ccb->cont_info.attr_offset != attr_len) {
break;
}{...} else {
p_ccb->cont_info.attr_offset = 0;
}{...}
}{...} else if (rem_len < attr_len) {
if (attr_len >= SDP_MAX_ATTR_LEN) {
SDP_TRACE_ERROR("SDP attr too big: max_list_len=%d,attr_len=%d\n", max_list_len, attr_len);
sdpu_build_n_send_error (p_ccb, trans_num, SDP_NO_RESOURCES, NULL);
return;
}{...}
p_rsp = sdpu_build_partial_attrib_entry (p_rsp, p_attr, (UINT16)rem_len,
&p_ccb->cont_info.attr_offset);
p_ccb->cont_info.next_attr_index = xx;
p_ccb->cont_info.next_attr_start_id = p_attr->id;
break;
}{...} else {
p_rsp = sdpu_build_attrib_entry (p_rsp, p_attr);
}{...}
if (attr_seq.attr_entry[xx].start != attr_seq.attr_entry[xx].end) {
attr_seq.attr_entry[xx].start = p_attr->id + 1;
xx--;
}{...}
}{...}
}{...}
/* ... */
if (xx == attr_seq.num_attr) {
p_ccb->cont_info.next_attr_index = 0;
}{...}
len_to_send = (UINT16) (p_rsp - &p_ccb->rsp_list[0]);
cont_offset = 0;
if (!is_cont) {
p_ccb->list_len = sdpu_get_attrib_seq_len(p_rec, &attr_seq_sav) + 3;
if (p_ccb->list_len > 255) {
p_ccb->rsp_list[0] = (UINT8) ((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_WORD);
p_ccb->rsp_list[1] = (UINT8) ((p_ccb->list_len - 3) >> 8);
p_ccb->rsp_list[2] = (UINT8) (p_ccb->list_len - 3);
}{...} else {
cont_offset = 1;
p_ccb->rsp_list[1] = (UINT8) ((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
p_ccb->rsp_list[2] = (UINT8) (p_ccb->list_len - 3);
p_ccb->list_len--;
len_to_send--;
}{...}
}{...}
if ((p_buf = (BT_HDR *)osi_malloc(SDP_DATA_BUF_SIZE)) == NULL) {
SDP_TRACE_ERROR ("SDP - no buf for search rsp\n");
return;
}{...}
p_buf->offset = L2CAP_MIN_OFFSET;
p_rsp = p_rsp_start = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
UINT8_TO_BE_STREAM (p_rsp, SDP_PDU_SERVICE_ATTR_RSP);
UINT16_TO_BE_STREAM (p_rsp, trans_num);
p_rsp_param_len = p_rsp;
p_rsp += 2;
UINT16_TO_BE_STREAM (p_rsp, len_to_send);
memcpy (p_rsp, &p_ccb->rsp_list[cont_offset], len_to_send);
p_rsp += len_to_send;
p_ccb->cont_offset += len_to_send;
if (p_ccb->cont_offset < p_ccb->list_len) {
is_cont = TRUE;
UINT8_TO_BE_STREAM (p_rsp, SDP_CONTINUATION_LEN);
UINT16_TO_BE_STREAM (p_rsp, p_ccb->cont_offset);
}{...} else {
UINT8_TO_BE_STREAM (p_rsp, 0);
}{...}
rsp_param_len = p_rsp - p_rsp_param_len - 2;
UINT16_TO_BE_STREAM (p_rsp_param_len, rsp_param_len);
p_buf->len = p_rsp - p_rsp_start;
L2CA_DataWrite (p_ccb->connection_id, p_buf);
}{...}
/* ... */
static void process_service_search_attr_req (tCONN_CB *p_ccb, UINT16 trans_num,
UINT16 param_len, UINT8 *p_req,
UINT8 *p_req_end)
{
UINT16 max_list_len;
INT16 rem_len;
UINT16 len_to_send, cont_offset;
tSDP_UUID_SEQ uid_seq;
UINT8 *p_rsp, *p_rsp_start, *p_rsp_param_len;
UINT16 rsp_param_len, xx;
tSDP_RECORD *p_rec;
tSDP_ATTR_SEQ attr_seq, attr_seq_sav;
tSDP_ATTRIBUTE *p_attr;
BT_HDR *p_buf;
BOOLEAN maxxed_out = FALSE, is_cont = FALSE;
UINT8 *p_seq_start;
UINT16 seq_len, attr_len;
UNUSED(p_req_end);
p_req = sdpu_extract_uid_seq (p_req, param_len, &uid_seq);
if ((!p_req) || (!uid_seq.num_uids)) {
sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_REQ_SYNTAX, SDP_TEXT_BAD_UUID_LIST);
return;
}{...}
BE_STREAM_TO_UINT16 (max_list_len, p_req);
if (max_list_len > (p_ccb->rem_mtu_size - SDP_MAX_SERVATTR_RSPHDR_LEN)) {
max_list_len = p_ccb->rem_mtu_size - SDP_MAX_SERVATTR_RSPHDR_LEN;
}{...}
p_req = sdpu_extract_attr_seq (p_req, param_len, &attr_seq);
if ((!p_req) || (!attr_seq.num_attr)) {
sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_REQ_SYNTAX, SDP_TEXT_BAD_ATTR_LIST);
return;
}{...}
memcpy(&attr_seq_sav, &attr_seq, sizeof(tSDP_ATTR_SEQ)) ;
if (*p_req) {
if (p_ccb->rsp_list) {
osi_free (p_ccb->rsp_list);
}{...}
p_ccb->rsp_list = (UINT8 *)osi_malloc (max_list_len);
if (p_ccb->rsp_list == NULL) {
SDP_TRACE_ERROR ("SDP - no scratch buf for search rsp\n");
return;
}{...}
if (*p_req++ != SDP_CONTINUATION_LEN) {
sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_CONT_STATE, SDP_TEXT_BAD_CONT_LEN);
return;
}{...}
BE_STREAM_TO_UINT16 (cont_offset, p_req);
if (cont_offset != p_ccb->cont_offset) {
sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_CONT_STATE, SDP_TEXT_BAD_CONT_INX);
return;
}{...}
if (!p_ccb->rsp_list) {
sdpu_build_n_send_error (p_ccb, trans_num, SDP_NO_RESOURCES, NULL);
return;
}{...}
is_cont = TRUE;
p_rsp = &p_ccb->rsp_list[0];
attr_seq.attr_entry[p_ccb->cont_info.next_attr_index].start = p_ccb->cont_info.next_attr_start_id;
}{...} else {
if (p_ccb->rsp_list) {
osi_free (p_ccb->rsp_list);
}{...}
p_ccb->rsp_list = (UINT8 *)osi_malloc (max_list_len);
if (p_ccb->rsp_list == NULL) {
SDP_TRACE_ERROR ("SDP - no scratch buf for search rsp\n");
return;
}{...}
p_ccb->cont_offset = 0;
p_rsp = &p_ccb->rsp_list[3];
p_ccb->cont_info.prev_sdp_rec = NULL;
p_ccb->cont_info.next_attr_index = 0;
p_ccb->cont_info.last_attr_seq_desc_sent = FALSE;
p_ccb->cont_info.attr_offset = 0;
}{...}
for (p_rec = sdp_db_service_search (p_ccb->cont_info.prev_sdp_rec, &uid_seq); p_rec; p_rec = sdp_db_service_search (p_rec, &uid_seq)) {
p_seq_start = p_rsp;
if (p_ccb->cont_info.last_attr_seq_desc_sent == FALSE) {
rem_len = max_list_len - (INT16) (p_rsp - &p_ccb->rsp_list[0]);
if (rem_len < 3) {
p_ccb->cont_info.next_attr_index = 0;
p_ccb->cont_info.next_attr_start_id = attr_seq.attr_entry[0].start;
break;
}{...}
p_rsp += 3;
}{...}
for (xx = p_ccb->cont_info.next_attr_index; xx < attr_seq.num_attr; xx++) {
p_attr = sdp_db_find_attr_in_rec (p_rec, attr_seq.attr_entry[xx].start, attr_seq.attr_entry[xx].end);
if (p_attr) {
rem_len = max_list_len - (INT16) (p_rsp - &p_ccb->rsp_list[0]);
if (rem_len <= 0) {
p_ccb->cont_info.next_attr_index = xx;
p_ccb->cont_info.next_attr_start_id = p_attr->id;
maxxed_out = TRUE;
break;
}{...}
attr_len = sdpu_get_attrib_entry_len(p_attr);
if (p_ccb->cont_info.attr_offset) {
p_rsp = sdpu_build_partial_attrib_entry (p_rsp, p_attr, rem_len,
&p_ccb->cont_info.attr_offset);
if (p_ccb->cont_info.attr_offset != attr_len) {
maxxed_out = TRUE;
break;
}{...} else {
p_ccb->cont_info.attr_offset = 0;
}{...}
}{...} else if (rem_len < attr_len) {
if (attr_len >= SDP_MAX_ATTR_LEN) {
SDP_TRACE_ERROR("SDP attr too big: max_list_len=%d,attr_len=%d\n", max_list_len, attr_len);
sdpu_build_n_send_error (p_ccb, trans_num, SDP_NO_RESOURCES, NULL);
return;
}{...}
p_rsp = sdpu_build_partial_attrib_entry (p_rsp, p_attr, (UINT16)rem_len,
&p_ccb->cont_info.attr_offset);
p_ccb->cont_info.next_attr_index = xx;
p_ccb->cont_info.next_attr_start_id = p_attr->id;
maxxed_out = TRUE;
break;
}{...} else {
p_rsp = sdpu_build_attrib_entry (p_rsp, p_attr);
}{...}
if (attr_seq.attr_entry[xx].start != attr_seq.attr_entry[xx].end) {
attr_seq.attr_entry[xx].start = p_attr->id + 1;
xx--;
}{...}
}{...}
}{...}
if (p_ccb->cont_info.last_attr_seq_desc_sent == FALSE) {
seq_len = sdpu_get_attrib_seq_len(p_rec, &attr_seq_sav);
if (seq_len != 0) {
UINT8_TO_BE_STREAM (p_seq_start, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_WORD);
UINT16_TO_BE_STREAM (p_seq_start, seq_len);
if (maxxed_out) {
p_ccb->cont_info.last_attr_seq_desc_sent = TRUE;
}{...}
}{...} else {
p_rsp = p_seq_start;
}{...}
}{...}
if (maxxed_out) {
break;
}{...}
memcpy(&attr_seq, &attr_seq_sav, sizeof(tSDP_ATTR_SEQ)) ;
p_ccb->cont_info.next_attr_index = 0;
p_ccb->cont_info.prev_sdp_rec = p_rec;
p_ccb->cont_info.last_attr_seq_desc_sent = FALSE;
}{...}
len_to_send = (UINT16) (p_rsp - &p_ccb->rsp_list[0]);
cont_offset = 0;
if (is_cont && len_to_send == 0) {
sdpu_build_n_send_error(p_ccb, trans_num, SDP_INVALID_CONT_STATE, NULL);
return;
}{...}
if (!is_cont) {
p_ccb->list_len = sdpu_get_list_len(&uid_seq, &attr_seq_sav) + 3;
if (p_ccb->list_len > 255) {
p_ccb->rsp_list[0] = (UINT8) ((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_WORD);
p_ccb->rsp_list[1] = (UINT8) ((p_ccb->list_len - 3) >> 8);
p_ccb->rsp_list[2] = (UINT8) (p_ccb->list_len - 3);
}{...} else {
cont_offset = 1;
p_ccb->rsp_list[1] = (UINT8) ((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
p_ccb->rsp_list[2] = (UINT8) (p_ccb->list_len - 3);
p_ccb->list_len--;
len_to_send--;
}{...}
}{...}
if ((p_buf = (BT_HDR *)osi_malloc(SDP_DATA_BUF_SIZE)) == NULL) {
SDP_TRACE_ERROR ("SDP - no buf for search rsp\n");
return;
}{...}
p_buf->offset = L2CAP_MIN_OFFSET;
p_rsp = p_rsp_start = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
UINT8_TO_BE_STREAM (p_rsp, SDP_PDU_SERVICE_SEARCH_ATTR_RSP);
UINT16_TO_BE_STREAM (p_rsp, trans_num);
p_rsp_param_len = p_rsp;
p_rsp += 2;
UINT16_TO_BE_STREAM (p_rsp, len_to_send);
memcpy (p_rsp, &p_ccb->rsp_list[cont_offset], len_to_send);
p_rsp += len_to_send;
p_ccb->cont_offset += len_to_send;
if (p_ccb->cont_offset < p_ccb->list_len) {
is_cont = TRUE;
UINT8_TO_BE_STREAM (p_rsp, SDP_CONTINUATION_LEN);
UINT16_TO_BE_STREAM (p_rsp, p_ccb->cont_offset);
}{...} else {
UINT8_TO_BE_STREAM (p_rsp, 0);
}{...}
rsp_param_len = p_rsp - p_rsp_param_len - 2;
UINT16_TO_BE_STREAM (p_rsp_param_len, rsp_param_len);
p_buf->len = p_rsp - p_rsp_start;
L2CA_DataWrite (p_ccb->connection_id, p_buf);
}{...}
...
/* ... */#endif