Skip to contentSkip to conversation

sdp seq of raw data

Bluez-devel Collin R. Mulliner 3 participants 10 messages Dec 1, 2005 – Dec 2, 2005 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

Hi Marcel and list,

I'm trying (for hours now) to put a raw binary string into a sdp attribute so that it shows up like this:

---8<----
Data Sequence

      Data : 0B 0X 09 06 a1 01 85 01 05 07 19 e0 29 e7 15 00 25 01 75 01

95 08 81 02 75 08 95 01 81 01 75 01 95 05
05 08 19 01 29 05 91 02 75 03 95 01 91 01 75 08 95 06 15 00 26 ff 00 05 ------>8------

I have tryed two methods, both failed:

SEQ8 method:

unit8_t h_spec[] = { binary_crap };
uint8_t dtd2 = SDP_UNIT8;
uint8_t dtd_data = SDP_SEQ8;
void *dtds[2];
void *values[2];

// this is a other uint8 value which gets placed correctly dtds[0] = &dtd2;
values[0] = &h_spec_leng;

for (i = 0; i < sizeof(h_spec); i++) {
h_spec_data_lst[i] = sdp_data_alloc(dtd2, &h_spec[i]); h_spec_data_dtds[i] = &dtd_data;
}
// sometimes it crashes here... h_spec_data_list = sdp_seq_alloc(h_spec_data_dtds,
(void**)h_spec_data_lst, sizeof(h_spec));

dtds[1] = &dtd_data;
values[1] = h_spec_data_list;
// sometimes it crashes here
h_spec_lst = sdp_seq_alloc(dtds, values, 2);
sdp_attr_add(sdp_record, SRV_ATTR_1, h_spec_lst);

// and sometimes the attributes added after this one don't get displayed, and the binary string is only one byte long

TEXT_STR8 method:

works fine but can't use binary, because of strcpy/strlen in sdp part of libbluetooth

I couldn't find any matching example in all the BlueZ code...

thanks ... Collin

--
Collin R. Mulliner <[email protected]>
BETAVERSiON Systems [www.betaversion.net]
info/pgp: finger [email protected]
It's a hardware problem!

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

maintainer
#1 lore raw

Hi Collin,

Quoted 9 lines

I'm trying (for hours now) to put a raw binary string into a sdp attribute so that it shows up like this:

---8<----
Data Sequence

      Data : 0B 0X 09 06 a1 01 85 01 05 07 19 e0 29 e7 15 00 25 01 75 01

95 08 81 02 75 08 95 01 81 01 75 01 95 05
05 08 19 01 29 05 91 02 75 03 95 01 91 01 75 08 95 06 15 00 26 ff 00 05 ------>8------

this is a known (maybe only by me) problem. I fixed it for the receiving path, but not for the sending path. You need to patch the library.

Regards

Marcel

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#2 lore raw
Quoted 3 lines

this is a known (maybe only by me) problem. I fixed it for the receiving path, but not for the sending path. You need to patch the library.

so patching the TEXT_STR stuff would be the right way?

... Collin

--
Collin R. Mulliner <[email protected]>
BETAVERSiON Systems [www.betaversion.net]
info/pgp: finger [email protected]
Life is hard, but unfair!

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

maintainer
#3 lore raw

Hi Collin,

Quoted 4 lines
Quoted 2 lines

this is a known (maybe only by me) problem. I fixed it for the receiving path, but not for the sending path. You need to patch the library.

so patching the TEXT_STR stuff would be the right way?

it is actually the only way. You must make sure that unitSize is used and that it is used correctly.

Regards

Marcel

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#4 lore raw

Do you accept a patch for this?

Quoted 6 lines

it is actually the only way. You must make sure that unitSize is used and that it is used correctly.

Regards

Marcel

... Collin

--
Collin R. Mulliner <[email protected]>
BETAVERSiON Systems [www.betaversion.net]
info/pgp: finger [email protected]
Life is getting harder all the time - now you even have to choose your own religion. --Carsten Wald

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

maintainer
#5 lore raw

Hi Collin,

Quoted 1 line

Do you accept a patch for this?

yes :)

Regards

Marcel

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#6 lore raw

Hi Marcel,

here are the patches, one for include/sdp_lib.h and one src/for sdp.c. It adds two new functions but stais backward compatible.

... Collin

PS: it's 4am and I need to go to sleep :-(

Quoted 9 lines · Marcel Holtmann

Hi Collin,

Quoted 1 line

Do you accept a patch for this?

yes :)

Regards

Marcel

--
Collin R. Mulliner <[email protected]> BETAVERSiON Systems [www.betaversion.net] info/pgp: finger [email protected] Blessed are the Geeks, for they internet the earth!

src/sdp.c +34 -4
@@ -346,6 +346,11 @@
 
 sdp_data_t *sdp_data_alloc(uint8_t dtd, const void *value)
 {
+	return(sdp_data_alloc_leng(dtd, value, 0));
+}
+
+sdp_data_t *sdp_data_alloc_leng(uint8_t dtd, const void *value, uint32_t leng)
+{
 	sdp_data_t *seq;
 	int len = 0;
 	sdp_data_t *d = (sdp_data_t *) malloc(sizeof(sdp_data_t));
@@ -420,14 +425,15 @@
 		if (!value)
 			goto out_error;
 
-		len = strlen(value);
-		d->unitSize += len;
+		len = leng ? leng : strlen(value);
+		d->unitSize = len - 1;
 		if (len <= USHRT_MAX) {
 			d->val.str = (char *) malloc(len + 1);
 			if (!d->val.str)
 				goto out_error;
 
-			strcpy(d->val.str, value);
+			if (leng) memcpy(d->val.str, value, leng);
+			else strcpy(d->val.str, value);
 			if (len <= UCHAR_MAX) {
 				d->unitSize += sizeof(uint8_t);
 				if (dtd != SDP_URL_STR8 && dtd != SDP_TEXT_STR8) {
@@ -491,6 +497,29 @@
 	return seq;
 }
 
+sdp_data_t *sdp_seq_alloc_leng(void **dtds, void **values, int *leng, int len)
+{
+	sdp_data_t *curr = NULL, *seq = NULL;
+	int i;
+
+	for (i = 0; i < len; i++) {
+		sdp_data_t *data;
+		uint8_t dtd = *(uint8_t *)dtds[i];
+		if (dtd >= SDP_SEQ8 && dtd <= SDP_ALT32)
+			data = (sdp_data_t *)values[i];
+		else
+			data = sdp_data_alloc_leng(dtd, values[i], leng[i]);
+		if (!data)
+			return NULL;
+		if (curr)
+			curr->next = data;
+		else
+			seq = data;
+		curr = data;
+	}
+	return sdp_data_alloc_leng(SDP_SEQ8, seq, leng[i]);
+}
+
 sdp_data_t *sdp_seq_alloc(void **dtds, void **values, int len)
 {
 	sdp_data_t *curr = NULL, *seq = NULL;
@@ -681,7 +710,8 @@
 	case SDP_URL_STR16:
 	case SDP_URL_STR32:
 		src = (unsigned char *)d->val.str;
-		data_size = strlen(d->val.str);
+		//data_size = strlen(d->val.str);
+		data_size = d->unitSize;
 		sdp_set_seq_len(seqp, data_size);
 		break;
 	case SDP_SEQ8:
include/sdp_lib.h +2 -0
@@ -102,10 +102,12 @@
  * Basic sdp data functions
  */
 sdp_data_t *sdp_data_alloc(uint8_t dtd, const void *value);
+sdp_data_t *sdp_data_alloc_leng(uint8_t dtd, const void *value, uint32_t leng);
 void sdp_data_free(sdp_data_t *data);
 sdp_data_t *sdp_data_get(const sdp_record_t *rec, uint16_t attr_id);
 
 sdp_data_t *sdp_seq_alloc(void **dtds, void **values, int len);
+sdp_data_t *sdp_seq_alloc_leng(void **dtds, void **values, int *leng, int len);
 sdp_data_t *sdp_seq_append(sdp_data_t *seq, sdp_data_t *data);
 
 int sdp_attr_add(sdp_record_t *rec, uint16_t attr, sdp_data_t *data);
maintainer
#7 lore raw

Hi Collin,

Quoted 2 lines

here are the patches, one for include/sdp_lib.h and one src/for sdp.c. It adds two new functions but stais backward compatible.

make it one patch and what does leng stands for? We don't use such weird abbreviations.

Regards

Marcel

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#8 lore raw
Quoted 1 line · Marcel Holtmann

... what does leng stands for? ...

The Plateau of Leng appears in the work of H.P. Lovecraft and is inhabited by terrible monsters. Does that help :-)

See http://en.wikipedia.org/wiki/Plateau_of_Leng

- Steven

Signature · 12 lines
This message has been scanned for viruses by BlackSpider MailControl - www.blackspider.com


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
maintainer
#9 lore raw

Hi Steven,

Quoted 4 lines
Quoted 1 line

... what does leng stands for? ...

The Plateau of Leng appears in the work of H.P. Lovecraft and is inhabited by terrible monsters. Does that help :-)

I assume it is short for length, but I like your explanation more :)

Regards

Marcel

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel