diff options
| -rw-r--r-- | src/sdpd-database.c | 12 | ||||
| -rw-r--r-- | src/sdpd-request.c | 94 | ||||
| -rw-r--r-- | src/sdpd-service.c | 40 | ||||
| -rw-r--r-- | src/sdpd.h | 6 | 
4 files changed, 79 insertions, 73 deletions
| diff --git a/src/sdpd-database.c b/src/sdpd-database.c index 3642ae18..543f0d15 100644 --- a/src/sdpd-database.c +++ b/src/sdpd-database.c @@ -170,8 +170,8 @@ void sdp_record_add(const bdaddr_t *device, sdp_record_t *rec)  {  	sdp_access_t *dev; -	debug("Adding rec : 0x%lx", (long) rec); -	debug("with handle : 0x%x", rec->handle); +	SDPDBG("Adding rec : 0x%lx", (long) rec); +	SDPDBG("with handle : 0x%x", rec->handle);  	service_db = sdp_list_insert_sorted(service_db, rec, record_sort); @@ -196,7 +196,7 @@ static sdp_list_t *record_locate(uint32_t handle)  		return p;  	} -	debug("Could not find svcRec for : 0x%x", handle); +	SDPDBG("Could not find svcRec for : 0x%x", handle);  	return NULL;  } @@ -211,7 +211,7 @@ static sdp_list_t *access_locate(uint32_t handle)  		return p;  	} -	debug("Could not find access data for : 0x%x", handle); +	SDPDBG("Could not find access data for : 0x%x", handle);  	return NULL;  } @@ -222,8 +222,8 @@ sdp_record_t *sdp_record_find(uint32_t handle)  {  	sdp_list_t *p = record_locate(handle); -        if (!p) { -		debug("Couldn't find record for : 0x%x", handle); +	if (!p) { +		SDPDBG("Couldn't find record for : 0x%x", handle);  		return 0;  	} diff --git a/src/sdpd-request.c b/src/sdpd-request.c index 3ddf25ce..3d82d51d 100644 --- a/src/sdpd-request.c +++ b/src/sdpd-request.c @@ -108,7 +108,7 @@ static int extract_des(uint8_t *buf, int len, sdp_list_t **svcReqSeq, uint8_t *p  	scanned = sdp_extract_seqtype(buf, len, &seqType, &data_size); -	debug("Seq type : %d", seqType); +	SDPDBG("Seq type : %d", seqType);  	if (!scanned || (seqType != SDP_SEQ8 && seqType != SDP_SEQ16)) {  		error("Unknown seq type");  		return -1; @@ -116,27 +116,27 @@ static int extract_des(uint8_t *buf, int len, sdp_list_t **svcReqSeq, uint8_t *p  	p = buf + scanned;  	bufsize = len - scanned; -	debug("Data size : %d", data_size); +	SDPDBG("Data size : %d", data_size);  	for (;;) {  		char *pElem = NULL;  		int localSeqLength = 0;  		if (bufsize < sizeof(uint8_t)) { -			debug("->Unexpected end of buffer"); +			SDPDBG("->Unexpected end of buffer");  			return -1;  		}  		dataType = *(uint8_t *)p; -		debug("Data type: 0x%02x", dataType); +		SDPDBG("Data type: 0x%02x", dataType);  		if (expectedType == SDP_TYPE_UUID) {  			if (dataType != SDP_UUID16 && dataType != SDP_UUID32 && dataType != SDP_UUID128) { -				debug("->Unexpected Data type (expected UUID_ANY)"); +				SDPDBG("->Unexpected Data type (expected UUID_ANY)");  				return -1;  			}  		} else if (expectedType != SDP_TYPE_ANY && dataType != expectedType) { -			debug("->Unexpected Data type (expected 0x%02x)", expectedType); +			SDPDBG("->Unexpected Data type (expected 0x%02x)", expectedType);  			return -1;  		} @@ -146,7 +146,7 @@ static int extract_des(uint8_t *buf, int len, sdp_list_t **svcReqSeq, uint8_t *p  			seqlen += sizeof(uint8_t);  			bufsize -= sizeof(uint8_t);  			if (bufsize < sizeof(uint16_t)) { -				debug("->Unexpected end of buffer"); +				SDPDBG("->Unexpected end of buffer");  				return -1;  			} @@ -161,7 +161,7 @@ static int extract_des(uint8_t *buf, int len, sdp_list_t **svcReqSeq, uint8_t *p  			seqlen += sizeof(uint8_t);  			bufsize -= sizeof(uint8_t);  			if (bufsize < (int)sizeof(uint32_t)) { -				debug("->Unexpected end of buffer"); +				SDPDBG("->Unexpected end of buffer");  				return -1;  			} @@ -188,7 +188,7 @@ static int extract_des(uint8_t *buf, int len, sdp_list_t **svcReqSeq, uint8_t *p  		if (status == 0) {  			pSeq = sdp_list_append(pSeq, pElem);  			numberOfElements++; -			debug("No of elements : %d", numberOfElements); +			SDPDBG("No of elements : %d", numberOfElements);  			if (seqlen == data_size)  				break; @@ -209,7 +209,7 @@ static int sdp_set_cstate_pdu(sdp_buf_t *buf, sdp_cont_state_t *cstate)  	int length = 0;  	if (cstate) { -		debug("Non null sdp_cstate_t id : 0x%lx", cstate->timestamp); +		SDPDBG("Non null sdp_cstate_t id : 0x%lx", cstate->timestamp);  		*(uint8_t *)pdata = sizeof(sdp_cont_state_t);  		pdata += sizeof(uint8_t);  		length += sizeof(uint8_t); @@ -234,7 +234,7 @@ static sdp_cont_state_t *sdp_cstate_get(uint8_t *buffer)  	 * Check if continuation state exists, if yes attempt  	 * to get response remainder from cache, else send error  	 */ -	debug("Continuation State size : %d", cStateSize); +	SDPDBG("Continuation State size : %d", cStateSize);  	pdata += sizeof(uint8_t);  	if (cStateSize != 0) { @@ -242,8 +242,8 @@ static sdp_cont_state_t *sdp_cstate_get(uint8_t *buffer)  		if (!cstate)  			return NULL;  		memcpy(cstate, (sdp_cont_state_t *)pdata, sizeof(sdp_cont_state_t)); -		debug("Cstate TS : 0x%lx", cstate->timestamp); -		debug("Bytes sent : %d", cstate->cStateValue.maxBytesSent); +		SDPDBG("Cstate TS : 0x%lx", cstate->timestamp); +		SDPDBG("Bytes sent : %d", cstate->cStateValue.maxBytesSent);  		return cstate;  	}  	return NULL; @@ -325,8 +325,8 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)  	expected = ntohs(bt_get_unaligned((uint16_t *)pdata)); -	debug("Expected count: %d", expected); -	debug("Bytes scanned : %d", scanned); +	SDPDBG("Expected count: %d", expected); +	SDPDBG("Bytes scanned : %d", scanned);  	pdata += sizeof(uint16_t); @@ -362,7 +362,7 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)  		for (; list && rsp_count < expected; list = list->next) {  			sdp_record_t *rec = (sdp_record_t *) list->data; -			debug("Checking svcRec : 0x%x", rec->handle); +			SDPDBG("Checking svcRec : 0x%x", rec->handle);  			if (sdp_match_uuid(pattern, rec->pattern) > 0 &&  					sdp_check_access(rec->handle, &req->device)) { @@ -373,7 +373,7 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)  			}  		} -		debug("Match count: %d", rsp_count); +		SDPDBG("Match count: %d", rsp_count);  		buf->data_size += handleSize;  		bt_put_unaligned(htons(rsp_count), (uint16_t *)pTotalRecordCount); @@ -455,7 +455,7 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)  			 */  			sdp_cont_state_t newState; -			debug("Setting non-NULL sdp_cstate_t"); +			SDPDBG("Setting non-NULL sdp_cstate_t");  			if (cstate)  				memcpy((char *)&newState, cstate, sizeof(sdp_cont_state_t)); @@ -490,14 +490,14 @@ static int extract_attrs(sdp_record_t *rec, sdp_list_t *seq, uint8_t dtd, sdp_bu  		return SDP_INVALID_RECORD_HANDLE;  	if (seq) -		debug("Entries in attr seq : %d", sdp_list_len(seq)); +		SDPDBG("Entries in attr seq : %d", sdp_list_len(seq));  	else -		debug("NULL attribute descriptor"); +		SDPDBG("NULL attribute descriptor"); -	debug("AttrDataType : %d", dtd); +	SDPDBG("AttrDataType : %d", dtd);  	if (seq == NULL) { -		debug("Attribute sequence is NULL"); +		SDPDBG("Attribute sequence is NULL");  		return 0;  	}  	if (dtd == SDP_UINT16) @@ -517,9 +517,9 @@ static int extract_attrs(sdp_record_t *rec, sdp_list_t *seq, uint8_t dtd, sdp_bu  			uint16_t high = 0x0000ffff & range;  			sdp_data_t *data; -			debug("attr range : 0x%x", range); -			debug("Low id : 0x%x", low); -			debug("High id : 0x%x", high); +			SDPDBG("attr range : 0x%x", range); +			SDPDBG("Low id : 0x%x", low); +			SDPDBG("High id : 0x%x", high);  			if (low == 0x0000 && high == 0xffff && pdu.data_size <= buf->buf_size) {  				/* copy it */ @@ -592,8 +592,8 @@ static int service_attr_req(sdp_req_t *req, sdp_buf_t *buf)  	 */  	cstate = sdp_cstate_get(pdata); -	debug("SvcRecHandle : 0x%x", handle); -	debug("max_rsp_size : %d", max_rsp_size); +	SDPDBG("SvcRecHandle : 0x%x", handle); +	SDPDBG("max_rsp_size : %d", max_rsp_size);  	/*   	 * Calculate Attribute size acording to MTU @@ -609,7 +609,7 @@ static int service_attr_req(sdp_req_t *req, sdp_buf_t *buf)  	if (cstate) {  		sdp_buf_t *pCache = sdp_get_cached_rsp(cstate); -		debug("Obtained cached rsp : %p", pCache); +		SDPDBG("Obtained cached rsp : %p", pCache);  		if (pCache) {  			short sent = MIN(max_rsp_size, pCache->data_size - cstate->cStateValue.maxBytesSent); @@ -618,7 +618,7 @@ static int service_attr_req(sdp_req_t *req, sdp_buf_t *buf)  			buf->data_size += sent;  			cstate->cStateValue.maxBytesSent += sent; -			debug("Response size : %d sending now : %d bytes sent so far : %d", +			SDPDBG("Response size : %d sending now : %d bytes sent so far : %d",  				pCache->data_size, sent, cstate->cStateValue.maxBytesSent);  			if (cstate->cStateValue.maxBytesSent == pCache->data_size)  				cstate_size = sdp_set_cstate_pdu(buf, NULL); @@ -640,7 +640,7 @@ static int service_attr_req(sdp_req_t *req, sdp_buf_t *buf)  			 * Reset the buffer size to the maximum expected and  			 * set the sdp_cont_state_t  			 */ -			debug("Creating continuation state of size : %d", buf->data_size); +			SDPDBG("Creating continuation state of size : %d", buf->data_size);  			buf->data_size = max_rsp_size;  			newState.cStateValue.maxBytesSent = max_rsp_size;  			cstate_size = sdp_set_cstate_pdu(buf, &newState); @@ -659,7 +659,7 @@ done:  	if (cstate)  		free(cstate);  	if (seq) -                sdp_list_free(seq, free); +		sdp_list_free(seq, free);  	if (status)  		return status; @@ -688,18 +688,18 @@ static int service_search_attr_req(sdp_req_t *req, sdp_buf_t *buf)  	scanned = extract_des(pdata, req->len - sizeof(sdp_pdu_hdr_t),  					&pattern, &dtd, SDP_TYPE_UUID);  	if (scanned == -1) { -        	status = SDP_INVALID_SYNTAX; +		status = SDP_INVALID_SYNTAX;  		goto done;  	}  	totscanned = scanned; -	debug("Bytes scanned: %d", scanned); +	SDPDBG("Bytes scanned: %d", scanned);  	pdata += scanned;  	max = ntohs(bt_get_unaligned((uint16_t *)pdata));  	pdata += sizeof(uint16_t); -	debug("Max Attr expected: %d", max); +	SDPDBG("Max Attr expected: %d", max);  	/* extract the attribute list */  	scanned = extract_des(pdata, req->len - sizeof(sdp_pdu_hdr_t), @@ -750,10 +750,10 @@ static int service_search_attr_req(sdp_req_t *req, sdp_buf_t *buf)  				rsp_count++;  				status = extract_attrs(rec, seq, dtd, &tmpbuf); -				debug("Response count : %d", rsp_count); -				debug("Local PDU size : %d", tmpbuf.data_size); +				SDPDBG("Response count : %d", rsp_count); +				SDPDBG("Local PDU size : %d", tmpbuf.data_size);  				if (status) { -					debug("Extract attr from record returns err"); +					SDPDBG("Extract attr from record returns err");  					break;  				}  				if (buf->data_size + tmpbuf.data_size < buf->buf_size) { @@ -765,7 +765,7 @@ static int service_search_attr_req(sdp_req_t *req, sdp_buf_t *buf)  					error("Relocation needed");  					break;  				} -				debug("Net PDU size : %d", buf->data_size); +				SDPDBG("Net PDU size : %d", buf->data_size);  			}  		}  		if (buf->data_size > max) { @@ -797,7 +797,7 @@ static int service_search_attr_req(sdp_req_t *req, sdp_buf_t *buf)  				cstate_size = sdp_set_cstate_pdu(buf, cstate);  		} else {  			status = SDP_INVALID_CSTATE; -			debug("Non-null continuation state, but null cache buffer"); +			SDPDBG("Non-null continuation state, but null cache buffer");  		}  	} @@ -856,37 +856,37 @@ static void process_request(sdp_req_t *req)  	}  	switch (reqhdr->pdu_id) {  	case SDP_SVC_SEARCH_REQ: -		debug("Got a svc srch req"); +		SDPDBG("Got a svc srch req");  		status = service_search_req(req, &rsp);  		rsphdr->pdu_id = SDP_SVC_SEARCH_RSP;  		break;  	case SDP_SVC_ATTR_REQ: -		debug("Got a svc attr req"); +		SDPDBG("Got a svc attr req");  		status = service_attr_req(req, &rsp);  		rsphdr->pdu_id = SDP_SVC_ATTR_RSP;  		break;  	case SDP_SVC_SEARCH_ATTR_REQ: -		debug("Got a svc srch attr req"); +		SDPDBG("Got a svc srch attr req");  		status = service_search_attr_req(req, &rsp);  		rsphdr->pdu_id = SDP_SVC_SEARCH_ATTR_RSP;  		break;  	/* Following requests are allowed only for local connections */  	case SDP_SVC_REGISTER_REQ: -		debug("Service register request"); +		SDPDBG("Service register request");  		if (req->local) {  			status = service_register_req(req, &rsp);  			rsphdr->pdu_id = SDP_SVC_REGISTER_RSP;  		}  		break;  	case SDP_SVC_UPDATE_REQ: -		debug("Service update request"); +		SDPDBG("Service update request");  		if (req->local) {  			status = service_update_req(req, &rsp);  			rsphdr->pdu_id = SDP_SVC_UPDATE_RSP;  		}  		break;  	case SDP_SVC_REMOVE_REQ: -		debug("Service removal request"); +		SDPDBG("Service removal request");  		if (req->local) {  			status = service_remove_req(req, &rsp);  			rsphdr->pdu_id = SDP_SVC_REMOVE_RSP; @@ -905,7 +905,7 @@ send_rsp:  		rsp.data_size = sizeof(uint16_t);  	} -	debug("Sending rsp. status %d", status); +	SDPDBG("Sending rsp. status %d", status);  	rsphdr->tid  = reqhdr->tid;  	rsphdr->plen = htons(rsp.data_size); @@ -917,7 +917,7 @@ send_rsp:  	/* stream the rsp PDU */  	sent = send(req->sock, rsp.data, rsp.data_size, 0); -	debug("Bytes Sent : %d", sent); +	SDPDBG("Bytes Sent : %d", sent);  	free(rsp.data);  	free(req->buf); diff --git a/src/sdpd-service.c b/src/sdpd-service.c index 713e12ef..30aad325 100644 --- a/src/sdpd-service.c +++ b/src/sdpd-service.c @@ -143,7 +143,7 @@ static void update_svclass_list(void)  		}  	} -	debug("Service classes 0x%02x", val); +	SDPDBG("Service classes 0x%02x", val);  	service_classes = val; @@ -445,23 +445,23 @@ static sdp_record_t *extract_pdu_server(bdaddr_t *device, uint8_t *p, int bufsiz  	bufsize -= *scanned;  	if (bufsize < sizeof(uint8_t) + sizeof(uint8_t)) { -		debug("Unexpected end of packet"); +		SDPDBG("Unexpected end of packet");  		return NULL;  	}  	lookAheadAttrId = ntohs(bt_get_unaligned((uint16_t *) (p + sizeof(uint8_t)))); -	debug("Look ahead attr id : %d", lookAheadAttrId); +	SDPDBG("Look ahead attr id : %d", lookAheadAttrId);  	if (lookAheadAttrId == SDP_ATTR_RECORD_HANDLE) {  		if (bufsize < (sizeof(uint8_t) * 2) + sizeof(uint16_t) + sizeof(uint32_t)) { -			debug("Unexpected end of packet"); +			SDPDBG("Unexpected end of packet");  			return NULL;  		}  		handle = ntohl(bt_get_unaligned((uint32_t *) (p +  				sizeof(uint8_t) + sizeof(uint16_t) +  				sizeof(uint8_t)))); -		debug("SvcRecHandle : 0x%x", handle); +		SDPDBG("SvcRecHandle : 0x%x", handle);  		rec = sdp_record_find(handle);  	} else if (handleExpected != 0xffffffff)  		rec = sdp_record_find(handleExpected); @@ -486,26 +486,26 @@ static sdp_record_t *extract_pdu_server(bdaddr_t *device, uint8_t *p, int bufsiz  		int attrValueLength = 0;  		if (bufsize < attrSize + sizeof(uint16_t)) { -			debug("Unexpected end of packet: Terminating extraction of attributes"); +			SDPDBG("Unexpected end of packet: Terminating extraction of attributes");  			break;  		} -		debug("Extract PDU, sequenceLength: %d localExtractedLength: %d", seqlen, localExtractedLength); +		SDPDBG("Extract PDU, sequenceLength: %d localExtractedLength: %d", seqlen, localExtractedLength);  		dtd = *(uint8_t *) p;  		attrId = ntohs(bt_get_unaligned((uint16_t *) (p + attrSize)));  		attrSize += sizeof(uint16_t); -		debug("DTD of attrId : %d Attr id : 0x%x", dtd, attrId); +		SDPDBG("DTD of attrId : %d Attr id : 0x%x", dtd, attrId);  		pAttr = sdp_extract_attr(p + attrSize, bufsize - attrSize,  							&attrValueLength, rec); -		debug("Attr id : 0x%x attrValueLength : %d", attrId, attrValueLength); +		SDPDBG("Attr id : 0x%x attrValueLength : %d", attrId, attrValueLength);  		attrSize += attrValueLength;  		if (pAttr == NULL) { -			debug("Terminating extraction of attributes"); +			SDPDBG("Terminating extraction of attributes");  			break;  		}  		localExtractedLength += attrSize; @@ -513,12 +513,12 @@ static sdp_record_t *extract_pdu_server(bdaddr_t *device, uint8_t *p, int bufsiz  		bufsize -= attrSize;  		sdp_attr_replace(rec, attrId, pAttr);  		extractStatus = 0; -		debug("Extract PDU, seqLength: %d localExtractedLength: %d", +		SDPDBG("Extract PDU, seqLength: %d localExtractedLength: %d",  					seqlen, localExtractedLength);  	}  	if (extractStatus == 0) { -		debug("Successful extracting of Svc Rec attributes"); +		SDPDBG("Successful extracting of Svc Rec attributes");  #ifdef SDP_DEBUG  		sdp_print_service_attr(rec->attrlist);  #endif @@ -608,14 +608,14 @@ int service_update_req(sdp_req_t *req, sdp_buf_t *rsp)  	int bufsize = req->len - sizeof(sdp_pdu_hdr_t);  	uint32_t handle = ntohl(bt_get_unaligned((uint32_t *) p)); -	debug("Svc Rec Handle: 0x%x", handle); +	SDPDBG("Svc Rec Handle: 0x%x", handle);  	p += sizeof(uint32_t);  	bufsize -= sizeof(uint32_t);  	orec = sdp_record_find(handle); -	debug("SvcRecOld: %p", orec); +	SDPDBG("SvcRecOld: %p", orec);  	if (orec) {  		sdp_record_t *nrec = extract_pdu_server(BDADDR_ANY, p, bufsize, handle, &scanned); @@ -623,11 +623,11 @@ int service_update_req(sdp_req_t *req, sdp_buf_t *rsp)  			update_db_timestamp();  			update_svclass_list();  		} else { -			debug("SvcRecHandle : 0x%x", handle); -			debug("SvcRecHandleNew : 0x%x", nrec->handle); -			debug("SvcRecNew : %p", nrec); -			debug("SvcRecOld : %p", orec); -			debug("Failure to update, restore old value"); +			SDPDBG("SvcRecHandle : 0x%x", handle); +			SDPDBG("SvcRecHandleNew : 0x%x", nrec->handle); +			SDPDBG("SvcRecNew : %p", nrec); +			SDPDBG("SvcRecOld : %p", orec); +			SDPDBG("Failure to update, restore old value");  			if (nrec)  				sdp_record_free(nrec); @@ -666,7 +666,7 @@ int service_remove_req(sdp_req_t *req, sdp_buf_t *rsp)  		}  	} else {  		status = SDP_INVALID_RECORD_HANDLE; -		debug("Could not find record : 0x%x", handle); +		SDPDBG("Could not find record : 0x%x", handle);  	}  	p = rsp->data; @@ -27,6 +27,12 @@  #include <bluetooth/bluetooth.h>  #include <bluetooth/sdp.h> +#ifdef SDP_DEBUG +#define SDPDBG(fmt, arg...) syslog(LOG_DEBUG, "%s: " fmt "\n", __func__ , ## arg) +#else +#define SDPDBG(fmt...) +#endif +  typedef struct request {  	bdaddr_t device;  	bdaddr_t bdaddr; | 
