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
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
66
67
68
69
70
81
82
83
84
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
139
140
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
240
241
242
243
244
245
246
247
248
249
250
255
256
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
303
304
305
306
308
313
314
315
316
317
318
319
320
321
322
323
324
325
328
329
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
429
430
431
438
439
440
441
442
443
444
445
446
447
448
458
459
462
463
464
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
489
490
491
497
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
540
541
542
543
544
545
546
549
552
555
558
561
565
566
567
568
569
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
618
619
620
621
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
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
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
844
845
846
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
900
901
902
903
904
907
908
909
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
964
965
966
967
968
969
970
971
972
973
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
/* ... */
/* ... */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "common/bt_target.h"
#include "osi/allocator.h"
#include "stack/l2cdefs.h"
#include "stack/hcidefs.h"
#include "stack/hcimsgs.h"
#include "stack/sdp_api.h"
#include "sdpint.h"
#include "osi/list.h"11 includes
#if (SDP_INCLUDED == TRUE)
#if SDP_SERVER_ENABLED == TRUE
static BOOLEAN find_uuid_in_seq (UINT8 *p , UINT32 seq_len, UINT8 *p_his_uuid,
UINT16 his_len, int nest_level);
/* ... */
tSDP_RECORD *sdp_db_service_search (tSDP_RECORD *p_rec, tSDP_UUID_SEQ *p_seq)
{
UINT16 xx, yy;
tSDP_ATTRIBUTE *p_attr;
list_node_t *p_node = NULL;
if (!p_rec) {
p_node = list_begin(sdp_cb.server_db.p_record_list);
}{...} else {
p_node = list_get_node(sdp_cb.server_db.p_record_list, p_rec);
if (p_node == NULL) {
return NULL;
}{...}
p_node = list_next(p_node);
}{...}
for( ; p_node; p_node = list_next(p_node)) {
p_rec = list_node(p_node);
for (yy = 0; yy < p_seq->num_uids; yy++) {
p_attr = &p_rec->attribute[0];
for (xx = 0; xx < p_rec->num_attributes; xx++, p_attr++) {
if (p_attr->type == UUID_DESC_TYPE) {
if (sdpu_compare_uuid_arrays (p_attr->value_ptr, p_attr->len,
&p_seq->uuid_entry[yy].value[0],
p_seq->uuid_entry[yy].len)) {
break;
}{...}
}{...} else if (p_attr->type == DATA_ELE_SEQ_DESC_TYPE) {
if (find_uuid_in_seq (p_attr->value_ptr, p_attr->len,
&p_seq->uuid_entry[yy].value[0],
p_seq->uuid_entry[yy].len, 0)) {
break;
}{...}
}{...}
}{...}
if (xx == p_rec->num_attributes) {
break;
}{...}
}{...}
if (yy == p_seq->num_uids) {
return (p_rec);
}{...}
}{...}
return (NULL);
}{...}
/* ... */
static BOOLEAN find_uuid_in_seq (UINT8 *p , UINT32 seq_len, UINT8 *p_uuid,
UINT16 uuid_len, int nest_level)
{
UINT8 *p_end = p + seq_len;
UINT8 type;
UINT32 len;
if (nest_level > 3) {
return (FALSE);
}{...}
while (p < p_end) {
type = *p++;
p = sdpu_get_len_from_type (p, type, &len);
type = type >> 3;
if (type == UUID_DESC_TYPE) {
if (sdpu_compare_uuid_arrays (p, len, p_uuid, uuid_len)) {
return (TRUE);
}{...}
}{...} else if (type == DATA_ELE_SEQ_DESC_TYPE) {
if (find_uuid_in_seq (p, len, p_uuid, uuid_len, nest_level + 1)) {
return (TRUE);
}{...}
}{...}
p = p + len;
}{...}
return (FALSE);
}{...}
/* ... */
tSDP_RECORD *sdp_db_find_record (UINT32 handle)
{
tSDP_RECORD *p_rec;
list_node_t *p_node = NULL;
for(p_node = list_begin(sdp_cb.server_db.p_record_list); p_node; p_node = list_next(p_node)) {
p_rec = list_node(p_node);
if (p_rec->record_handle == handle) {
return (p_rec);
}{...}
}{...}
return (NULL);
}{...}
/* ... */
tSDP_ATTRIBUTE *sdp_db_find_attr_in_rec (tSDP_RECORD *p_rec, UINT16 start_attr,
UINT16 end_attr)
{
tSDP_ATTRIBUTE *p_at;
UINT16 xx;
for (xx = 0, p_at = &p_rec->attribute[0]; xx < p_rec->num_attributes;
xx++, p_at++) {
if ((p_at->id >= start_attr) && (p_at->id <= end_attr)) {
return (p_at);
}{...}
}{...}
return (NULL);
}{...}
/* ... */
static int sdp_compose_proto_list( UINT8 *p, UINT16 num_elem,
tSDP_PROTOCOL_ELEM *p_elem_list)
{
UINT16 xx, yy, len;
BOOLEAN is_rfcomm_scn;
UINT8 *p_head = p;
UINT8 *p_len;
/* ... */
for (xx = 0; xx < num_elem; xx++, p_elem_list++) {
len = 3 + (p_elem_list->num_params * 3);
UINT8_TO_BE_STREAM (p, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
p_len = p;
*p++ = (UINT8) len;
UINT8_TO_BE_STREAM (p, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES);
UINT16_TO_BE_STREAM (p, p_elem_list->protocol_uuid);
if (p_elem_list->protocol_uuid == UUID_PROTOCOL_RFCOMM) {
is_rfcomm_scn = TRUE;
}{...} else {
is_rfcomm_scn = FALSE;
}{...}
for (yy = 0; yy < p_elem_list->num_params; yy++) {
if (is_rfcomm_scn) {
UINT8_TO_BE_STREAM (p, (UINT_DESC_TYPE << 3) | SIZE_ONE_BYTE);
UINT8_TO_BE_STREAM (p, p_elem_list->params[yy]);
*p_len -= 1;
}{...} else {
UINT8_TO_BE_STREAM (p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES);
UINT16_TO_BE_STREAM (p, p_elem_list->params[yy]);
}{...}
}{...}
}{...}
return (p - p_head);
}{...}
/* ... */
#endif
/* ... */
UINT32 SDP_CreateRecord (void)
{
#if SDP_SERVER_ENABLED == TRUE
UINT32 handle;
UINT8 buf[4];
tSDP_DB *p_db = &sdp_cb.server_db;
tSDP_RECORD *p_rec = NULL;
tSDP_RECORD *p_rec_prev = NULL;
if (p_db->num_records < SDP_MAX_RECORDS) {
p_rec = (tSDP_RECORD *)osi_malloc(sizeof(tSDP_RECORD));
if (p_rec) {
memset(p_rec, 0, sizeof(tSDP_RECORD));
if (p_db->num_records) {
p_rec_prev = list_back(p_db->p_record_list);
}{...}
list_append(p_db->p_record_list, p_rec);
/* ... */
if (p_db->num_records) {
handle = p_rec_prev->record_handle + 1;
}{...} else {
handle = 0x10000;
}{...}
p_rec->record_handle = handle;
p_db->num_records++;
SDP_TRACE_DEBUG("SDP_CreateRecord ok, num_records:%d\n", p_db->num_records);
UINT32_TO_BE_FIELD (buf, handle);
SDP_AddAttribute (handle, ATTR_ID_SERVICE_RECORD_HDL, UINT_DESC_TYPE,
4, buf);
return (p_rec->record_handle);
}{...}
else {
SDP_TRACE_ERROR("SDP_CreateRecord fail, memory allocation failed\n");
}{...}
}{...}
else {
SDP_TRACE_ERROR("SDP_CreateRecord fail, exceed maximum records:%d\n", SDP_MAX_RECORDS);
}{...}
/* ... */#endif
return (0);
}{...}
/* ... */
BOOLEAN SDP_DeleteRecord (UINT32 handle)
{
#if SDP_SERVER_ENABLED == TRUE
tSDP_RECORD *p_rec = NULL;
list_node_t *p_node = NULL;
if (handle == 0 || sdp_cb.server_db.num_records == 0) {
sdp_cb.server_db.num_records = 0;
for (p_node = list_begin(sdp_cb.server_db.p_record_list); p_node; p_node = list_next(p_node)) {
list_remove(sdp_cb.server_db.p_record_list, p_node);
}{...}
sdp_cb.server_db.di_primary_handle = 0;
return (TRUE);
}{...} else {
for (p_node = list_begin(sdp_cb.server_db.p_record_list); p_node; p_node = list_next(p_node)) {
p_rec = list_node(p_node);
if (p_rec->record_handle == handle) {
list_remove(sdp_cb.server_db.p_record_list, p_rec);
sdp_cb.server_db.num_records--;
SDP_TRACE_DEBUG("SDP_DeleteRecord ok, num_records:%d\n", sdp_cb.server_db.num_records);
if (sdp_cb.server_db.di_primary_handle == handle) {
sdp_cb.server_db.di_primary_handle = 0;
}{...}
return (TRUE);
}{...}
}{...}
}{...}
/* ... */#endif
return (FALSE);
}{...}
/* ... */
BOOLEAN SDP_AddAttribute (UINT32 handle, UINT16 attr_id, UINT8 attr_type,
UINT32 attr_len, UINT8 *p_val)
{
#if SDP_SERVER_ENABLED == TRUE
UINT16 xx, yy;
tSDP_RECORD *p_rec = NULL;
list_node_t *p_node= NULL;
#if (BT_TRACE_VERBOSE == TRUE)
if (sdp_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) {
if ((attr_type == UINT_DESC_TYPE) ||
(attr_type == TWO_COMP_INT_DESC_TYPE) ||
(attr_type == UUID_DESC_TYPE) ||
(attr_type == DATA_ELE_SEQ_DESC_TYPE) ||
(attr_type == DATA_ELE_ALT_DESC_TYPE)) {
UINT8 num_array[400];
UINT32 i;
UINT32 len = (attr_len > 200) ? 200 : attr_len;
num_array[0] = '\0';
for (i = 0; i < len; i++) {
sprintf((char *)&num_array[i * 2], "%02X", (UINT8)(p_val[i]));
}{...}
SDP_TRACE_DEBUG("SDP_AddAttribute: handle:%X, id:%04X, type:%d, len:%d, p_val:%p, *p_val:%s\n",
handle, attr_id, attr_type, attr_len, p_val, num_array);
}{...} else if (attr_type == BOOLEAN_DESC_TYPE) {
SDP_TRACE_DEBUG("SDP_AddAttribute: handle:%X, id:%04X, type:%d, len:%d, p_val:%p, *p_val:%d\n",
handle, attr_id, attr_type, attr_len, p_val, *p_val);
}{...} else {
SDP_TRACE_DEBUG("SDP_AddAttribute: handle:%X, id:%04X, type:%d, len:%d, p_val:%p, *p_val:%s\n",
handle, attr_id, attr_type, attr_len, p_val, p_val);
}{...}
}{...}
/* ... */#endif
for(p_node = list_begin(sdp_cb.server_db.p_record_list); p_node; p_node = list_next(p_node)) {
p_rec= list_node(p_node);
if (p_rec->record_handle == handle) {
tSDP_ATTRIBUTE *p_attr = &p_rec->attribute[0];
for (xx = 0; xx < p_rec->num_attributes; xx++, p_attr++) {
if (p_attr->id == attr_id) {
SDP_DeleteAttribute (handle, attr_id);
break;
}{...}
if (p_attr->id > attr_id) {
break;
}{...}
}{...}
if (p_rec->num_attributes == SDP_MAX_REC_ATTR) {
return (FALSE);
}{...}
if (xx == p_rec->num_attributes) {
p_attr = &p_rec->attribute[p_rec->num_attributes];
}{...} else {
for (yy = p_rec->num_attributes; yy > xx; yy--) {
p_rec->attribute[yy] = p_rec->attribute[yy - 1];
}{...}
}{...}
p_attr->id = attr_id;
p_attr->type = attr_type;
p_attr->len = attr_len;
if (p_rec->free_pad_ptr + attr_len >= SDP_MAX_PAD_LEN) {
if (attr_type == TEXT_STR_DESC_TYPE) {
SDP_TRACE_WARNING("SDP_AddAttribute: attr_len:%d too long. truncate to (%d)\n",
attr_len, SDP_MAX_PAD_LEN - p_rec->free_pad_ptr );
attr_len = SDP_MAX_PAD_LEN - p_rec->free_pad_ptr;
p_val[SDP_MAX_PAD_LEN - p_rec->free_pad_ptr] = '\0';
p_val[SDP_MAX_PAD_LEN - p_rec->free_pad_ptr + 1] = '\0';
}{...} else {
attr_len = 0;
}{...}
}{...}
if ((attr_len > 0) && (p_val != 0)) {
p_attr->len = attr_len;
memcpy (&p_rec->attr_pad[p_rec->free_pad_ptr], p_val, (size_t)attr_len);
p_attr->value_ptr = &p_rec->attr_pad[p_rec->free_pad_ptr];
p_rec->free_pad_ptr += attr_len;
}{...} else if ((attr_len == 0 && p_attr->len != 0) ||
p_val == 0) {
SDP_TRACE_ERROR("SDP_AddAttribute fail, length exceed maximum: ID %d: attr_len:%d \n",
attr_id, attr_len );
p_attr->id = p_attr->type = p_attr->len = 0;
return (FALSE);
}{...}
p_rec->num_attributes++;
return (TRUE);
}{...}
}{...}
/* ... */#endif
return (FALSE);
}{...}
/* ... */
BOOLEAN SDP_AddSequence (UINT32 handle, UINT16 attr_id, UINT16 num_elem,
UINT8 type[], UINT8 len[], UINT8 *p_val[])
{
#if SDP_SERVER_ENABLED == TRUE
UINT16 xx;
UINT8 *p_buff;
UINT8 *p;
UINT8 *p_head;
BOOLEAN result;
if ((p_buff = (UINT8 *) osi_malloc(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL) {
SDP_TRACE_ERROR("SDP_AddSequence cannot get a buffer!\n");
return (FALSE);
}{...}
p = p_buff;
for (xx = 0; xx < num_elem; xx++) {
p_head = p;
switch (len[xx]) {
case 1:
UINT8_TO_BE_STREAM (p, (type[xx] << 3) | SIZE_ONE_BYTE);
break;...
case 2:
UINT8_TO_BE_STREAM (p, (type[xx] << 3) | SIZE_TWO_BYTES);
break;...
case 4:
UINT8_TO_BE_STREAM (p, (type[xx] << 3) | SIZE_FOUR_BYTES);
break;...
case 8:
UINT8_TO_BE_STREAM (p, (type[xx] << 3) | SIZE_EIGHT_BYTES);
break;...
case 16:
UINT8_TO_BE_STREAM (p, (type[xx] << 3) | SIZE_SIXTEEN_BYTES);
break;...
default:
UINT8_TO_BE_STREAM (p, (type[xx] << 3) | SIZE_IN_NEXT_BYTE);
UINT8_TO_BE_STREAM (p, len[xx]);
break;...
}{...}
ARRAY_TO_BE_STREAM (p, p_val[xx], len[xx]);
if (p - p_buff > SDP_MAX_ATTR_LEN) {
p = p_head;
if (p_head == p_buff) {
SDP_TRACE_ERROR ("SDP_AddSequence - too long(attribute is not added)!!\n");
osi_free(p_buff);
return FALSE;
}{...} else {
SDP_TRACE_ERROR ("SDP_AddSequence - too long, add %d elements of %d\n", xx, num_elem);
}{...}
break;
}{...}
}{...}
result = SDP_AddAttribute (handle, attr_id, DATA_ELE_SEQ_DESC_TYPE, (UINT32) (p - p_buff), p_buff);
osi_free(p_buff);
return result;/* ... */
#else
return (FALSE);
#endif
}{...}
/* ... */
BOOLEAN SDP_AddUuidSequence (UINT32 handle, UINT16 attr_id, UINT16 num_uuids,
UINT16 *p_uuids)
{
#if SDP_SERVER_ENABLED == TRUE
UINT16 xx;
UINT8 *p_buff;
UINT8 *p;
INT32 max_len = SDP_MAX_ATTR_LEN - 3;
BOOLEAN result;
if ((p_buff = (UINT8 *) osi_malloc(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL) {
SDP_TRACE_ERROR("SDP_AddUuidSequence cannot get a buffer!\n");
return (FALSE);
}{...}
p = p_buff;
for (xx = 0; xx < num_uuids ; xx++, p_uuids++) {
UINT8_TO_BE_STREAM (p, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES);
UINT16_TO_BE_STREAM (p, *p_uuids);
if ((p - p_buff) > max_len) {
SDP_TRACE_WARNING ("SDP_AddUuidSequence - too long, add %d uuids of %d\n", xx, num_uuids);
break;
}{...}
}{...}
result = SDP_AddAttribute (handle, attr_id, DATA_ELE_SEQ_DESC_TYPE, (UINT32) (p - p_buff), p_buff);
osi_free(p_buff);
return result;/* ... */
#else
return (FALSE);
#endif
}{...}
/* ... */
BOOLEAN SDP_AddProtocolList (UINT32 handle, UINT16 num_elem,
tSDP_PROTOCOL_ELEM *p_elem_list)
{
#if SDP_SERVER_ENABLED == TRUE
UINT8 *p_buff;
int offset;
BOOLEAN result;
if ((p_buff = (UINT8 *) osi_malloc(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL) {
SDP_TRACE_ERROR("SDP_AddProtocolList cannot get a buffer!\n");
return (FALSE);
}{...}
offset = sdp_compose_proto_list(p_buff, num_elem, p_elem_list);
result = SDP_AddAttribute (handle, ATTR_ID_PROTOCOL_DESC_LIST, DATA_ELE_SEQ_DESC_TYPE, (UINT32) offset, p_buff);
osi_free(p_buff);
return result;/* ... */
#else
return (FALSE);
#endif
}{...}
/* ... */
BOOLEAN SDP_AddAdditionProtoLists (UINT32 handle, UINT16 num_elem,
tSDP_PROTO_LIST_ELEM *p_proto_list)
{
#if SDP_SERVER_ENABLED == TRUE
UINT16 xx;
UINT8 *p_buff;
UINT8 *p;
UINT8 *p_len;
int offset;
BOOLEAN result;
if ((p_buff = (UINT8 *) osi_malloc(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL) {
SDP_TRACE_ERROR("SDP_AddAdditionProtoLists cannot get a buffer!\n");
return (FALSE);
}{...}
p = p_buff;
for (xx = 0; xx < num_elem; xx++, p_proto_list++) {
UINT8_TO_BE_STREAM (p, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
p_len = p++;
offset = sdp_compose_proto_list(p, p_proto_list->num_elems,
p_proto_list->list_elem);
p += offset;
*p_len = (UINT8)(p - p_len - 1);
}{...}
result = SDP_AddAttribute (handle, ATTR_ID_ADDITION_PROTO_DESC_LISTS, DATA_ELE_SEQ_DESC_TYPE,
(UINT32) (p - p_buff), p_buff);
osi_free(p_buff);
return result;
/* ... */
#else
return (FALSE);
#endif
}{...}
/* ... */
BOOLEAN SDP_AddProfileDescriptorList (UINT32 handle, UINT16 profile_uuid,
UINT16 version)
{
#if SDP_SERVER_ENABLED == TRUE
UINT8 *p_buff;
UINT8 *p;
BOOLEAN result;
if ((p_buff = (UINT8 *) osi_malloc(sizeof(UINT8) * SDP_MAX_ATTR_LEN)) == NULL) {
SDP_TRACE_ERROR("SDP_AddProfileDescriptorList cannot get a buffer!\n");
return (FALSE);
}{...}
p = p_buff + 2;
UINT8_TO_BE_STREAM (p, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES);
UINT16_TO_BE_STREAM (p, profile_uuid);
UINT8_TO_BE_STREAM (p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES);
UINT16_TO_BE_STREAM (p, version);
*p_buff = (UINT8) ((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
*(p_buff + 1) = (UINT8) (p - (p_buff + 2));
result = SDP_AddAttribute (handle, ATTR_ID_BT_PROFILE_DESC_LIST, DATA_ELE_SEQ_DESC_TYPE, (UINT32) (p - p_buff), p_buff);
osi_free(p_buff);
return result;
/* ... */
#else
return (FALSE);
#endif
}{...}
/* ... */
BOOLEAN SDP_AddLanguageBaseAttrIDList (UINT32 handle, UINT16 lang,
UINT16 char_enc, UINT16 base_id)
{
#if SDP_SERVER_ENABLED == TRUE
UINT8 *p_buff;
UINT8 *p;
BOOLEAN result;
if ((p_buff = (UINT8 *) osi_malloc(sizeof(UINT8) * SDP_MAX_ATTR_LEN)) == NULL) {
SDP_TRACE_ERROR("SDP_AddLanguageBaseAttrIDList cannot get a buffer!\n");
return (FALSE);
}{...}
p = p_buff;
UINT8_TO_BE_STREAM (p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES);
UINT16_TO_BE_STREAM (p, lang);
UINT8_TO_BE_STREAM (p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES);
UINT16_TO_BE_STREAM (p, char_enc);
UINT8_TO_BE_STREAM (p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES);
UINT16_TO_BE_STREAM (p, base_id);
result = SDP_AddAttribute (handle, ATTR_ID_LANGUAGE_BASE_ATTR_ID_LIST, DATA_ELE_SEQ_DESC_TYPE,
(UINT32) (p - p_buff), p_buff);
osi_free(p_buff);
return result;/* ... */
#else
return (FALSE);
#endif
}{...}
/* ... */
BOOLEAN SDP_AddServiceClassIdList (UINT32 handle, UINT16 num_services,
UINT16 *p_service_uuids)
{
#if SDP_SERVER_ENABLED == TRUE
UINT16 xx;
UINT8 *p_buff;
UINT8 *p;
BOOLEAN result;
if ((p_buff = (UINT8 *) osi_malloc(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL) {
SDP_TRACE_ERROR("SDP_AddServiceClassIdList cannot get a buffer!\n");
return (FALSE);
}{...}
p = p_buff;
for (xx = 0; xx < num_services; xx++, p_service_uuids++) {
UINT8_TO_BE_STREAM (p, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES);
UINT16_TO_BE_STREAM (p, *p_service_uuids);
}{...}
result = SDP_AddAttribute (handle, ATTR_ID_SERVICE_CLASS_ID_LIST, DATA_ELE_SEQ_DESC_TYPE,
(UINT32) (p - p_buff), p_buff);
osi_free(p_buff);
return result;/* ... */
#else
return (FALSE);
#endif
}{...}
/* ... */
BOOLEAN SDP_DeleteAttribute (UINT32 handle, UINT16 attr_id)
{
#if SDP_SERVER_ENABLED == TRUE
UINT16 xx, yy;
tSDP_RECORD *p_rec = NULL;
list_node_t *p_node= NULL;
UINT8 *pad_ptr;
UINT32 len;
for(p_node = list_begin(sdp_cb.server_db.p_record_list); p_node; p_node = list_next(p_node)) {
p_rec= list_node(p_node);
if (p_rec->record_handle == handle) {
tSDP_ATTRIBUTE *p_attr = &p_rec->attribute[0];
SDP_TRACE_API("Deleting attr_id 0x%04x for handle 0x%x\n", attr_id, handle);
for (xx = 0; xx < p_rec->num_attributes; xx++, p_attr++) {
if (p_attr->id == attr_id) {
pad_ptr = p_attr->value_ptr;
len = p_attr->len;
if (len) {
for (yy = 0; yy < p_rec->num_attributes; yy++) {
if ( p_rec->attribute[yy].value_ptr > pad_ptr ) {
p_rec->attribute[yy].value_ptr -= len;
}{...}
}{...}
}{...}
p_rec->num_attributes--;
for (yy = xx; yy < p_rec->num_attributes; yy++, p_attr++) {
*p_attr = *(p_attr + 1);
}{...}
if (len) {
xx = (p_rec->free_pad_ptr - ((pad_ptr + len) -
&p_rec->attr_pad[0]));
for ( yy = 0; yy < xx; yy++, pad_ptr++) {
*pad_ptr = *(pad_ptr + len);
}{...}
p_rec->free_pad_ptr -= len;
}{...}
return (TRUE);
}{...}
}{...}
}{...}
}{...}
/* ... */#endif
return (FALSE);
}{...}
/* ... */
#if (SDP_RAW_DATA_INCLUDED == TRUE)
INT32 SDP_ReadRecord(UINT32 handle, UINT8 *p_data, INT32 *p_data_len)
{
INT32 offset = -1;
#if SDP_SERVER_ENABLED == TRUE
INT32 len = 0;
tSDP_RECORD *p_rec;
UINT16 start = 0;
UINT16 end = 0xffff;
tSDP_ATTRIBUTE *p_attr;
UINT16 rem_len;
UINT8 *p_rsp;
p_rec = sdp_db_find_record(handle);
if (p_rec && p_data && p_data_len) {
p_rsp = &p_data[3];
while ( (p_attr = sdp_db_find_attr_in_rec (p_rec, start, end)) != NULL) {
rem_len = *p_data_len - (UINT16) (p_rsp - p_data);
if (p_attr->len > (UINT32)(rem_len - 6)) {
break;
}{...}
p_rsp = sdpu_build_attrib_entry (p_rsp, p_attr);
start = p_attr->id + 1;
}{...}
len = (INT32) (p_rsp - p_data);
if (len > 255) {
offset = 0;
p_data[0] = (UINT8) ((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_WORD);
p_data[1] = (UINT8) ((len - 3) >> 8);
p_data[2] = (UINT8) (len - 3);
}{...} else {
offset = 1;
p_data[1] = (UINT8) ((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
p_data[2] = (UINT8) (len - 3);
len--;
}{...}
*p_data_len = len;
}{...}
/* ... */#endif
return (offset);
}{...}
/* ... */#endif
/* ... */
#endif