Пример #1
0
static int del_service(sdp_session_t *session, uint32_t handle)
{
	sdp_record_t *rec;

	logDebug("Deleting Service Record.\n");

	if (!session) {
		logDebug("Bad local SDP session!\n");
		return -1;
	}

	rec = sdp_record_alloc();

	if (rec == NULL) {
		return -1;
	}

	rec->handle = handle;

	if (sdp_device_record_unregister(session, &loc_addr.rc_bdaddr, rec) != 0) {
		/*
		 If Bluetooth is shut off, the sdp daemon will not be running and it is
		 therefore common that this function will fail in that case. This is fine
		 since the record is removed when the daemon shuts down. We only have
		 to free our record handle here then....
		 */
		//CM_DBG("Failed to unregister service record: %s\n", strerror(errno));
		sdp_record_free(rec);
		return -1;
	}

	logDebug("Service Record deleted.");

	return 0;
}
Пример #2
0
/*
 * 	sdpunregister - Remove SDP entry for HID service on program termination
 * 	Parameters: SDP handle (typically 0x10004 or similar)
 */
void	sdpunregister ( uint32_t handle )
{
        uint32_t	range=0x0000ffff;
	sdp_list_t    *	attr;
	sdp_session_t *	sess;
	sdp_record_t  *	rec;
	// Connect to the local SDP server
	sess = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, 0);
	if ( !sess )	return;
	attr = sdp_list_append(0, &range);
	rec = sdp_service_attr_req(sess, handle, SDP_ATTR_REQ_RANGE, attr);
	sdp_list_free(attr, 0);
	if ( !rec ) {
		sdp_close(sess);
		return;
	}
	sdp_device_record_unregister(sess, BDADDR_ANY, rec);
	sdp_close(sess);
	// We do not care wether unregister fails. If it does, we cannot help it.
	return;
}
Пример #3
0
int unregister_record(){

		uint32_t	  range = 0x0000ffff;
		sdp_list_t    *attribute;
		sdp_session_t *session;
		sdp_record_t  *record;

		// Connect to the local SDP server
		session = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY);

		if ( !session ){

			//	LOGCAT:
			__android_log_print(ANDROID_LOG_DEBUG, TAG, "SDP: Connection to SDP failed.");
			return CODE_SDP_SESSION_FAILED;

		}

		attribute = sdp_list_append(0, &range);

		//	Search withing a range of 0x00 - 0x0000ffff for service record attribute
		//  that has the same value as the ServiceRecordHandle attribute,
		// 	we specified for our service. Once the ServiceRecordHandle is found
		//	give back the record that contains it.
		//  This should be the record we previously added.
		record = sdp_service_attr_req(session, handle, SDP_ATTR_REQ_RANGE, attribute);

		sdp_list_free(attribute, 0);


		if ( !record ) {

			// No such record is found

			//	LOGCAT:
			__android_log_print(ANDROID_LOG_DEBUG, TAG, "SDP: Record request has failed.");

			sdp_close(session);
			return CODE_RECORD_REQUEST_FAILED;
		}


		// The rcord is found, so remove it from the registry
		if (sdp_device_record_unregister(session, BDADDR_ANY, record)) {

			//	LOGCAT:
			__android_log_print(ANDROID_LOG_DEBUG, TAG, "SDP: Record unregistration has failed.");

			sdp_close(session);
			return CODE_RECORD_UNREGISTER_FAILED;

		}

		//	LOGCAT:
		__android_log_print(ANDROID_LOG_DEBUG, TAG, "SDP: Unregistration successful.");

		sdp_close(session);

		return CODE_RECORD_UNREGISTERED;
	
}