xref: /freebsd/usr.sbin/bluetooth/sdpd/irmc.c (revision 42b388439bd3795e09258c57a74ce9eec3651c7b)
11de7b4b8SPedro F. Giffuni /*-
207be7a6cSMaksim Yevmenkin  * irmc.c
307be7a6cSMaksim Yevmenkin  *
4*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
51de7b4b8SPedro F. Giffuni  *
607be7a6cSMaksim Yevmenkin  * Copyright (c) 2004 Maksim Yevmenkin <m_evmenkin@yahoo.com>
707be7a6cSMaksim Yevmenkin  * All rights reserved.
807be7a6cSMaksim Yevmenkin  *
907be7a6cSMaksim Yevmenkin  * Redistribution and use in source and binary forms, with or without
1007be7a6cSMaksim Yevmenkin  * modification, are permitted provided that the following conditions
1107be7a6cSMaksim Yevmenkin  * are met:
1207be7a6cSMaksim Yevmenkin  * 1. Redistributions of source code must retain the above copyright
1307be7a6cSMaksim Yevmenkin  *    notice, this list of conditions and the following disclaimer.
1407be7a6cSMaksim Yevmenkin  * 2. Redistributions in binary form must reproduce the above copyright
1507be7a6cSMaksim Yevmenkin  *    notice, this list of conditions and the following disclaimer in the
1607be7a6cSMaksim Yevmenkin  *    documentation and/or other materials provided with the distribution.
1707be7a6cSMaksim Yevmenkin  *
1807be7a6cSMaksim Yevmenkin  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1907be7a6cSMaksim Yevmenkin  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2007be7a6cSMaksim Yevmenkin  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2107be7a6cSMaksim Yevmenkin  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2207be7a6cSMaksim Yevmenkin  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2307be7a6cSMaksim Yevmenkin  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2407be7a6cSMaksim Yevmenkin  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2507be7a6cSMaksim Yevmenkin  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2607be7a6cSMaksim Yevmenkin  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2707be7a6cSMaksim Yevmenkin  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2807be7a6cSMaksim Yevmenkin  * SUCH DAMAGE.
2907be7a6cSMaksim Yevmenkin  *
3007be7a6cSMaksim Yevmenkin  * $Id: irmc.c,v 1.6 2004/01/13 19:31:54 max Exp $
3107be7a6cSMaksim Yevmenkin  */
3207be7a6cSMaksim Yevmenkin 
3307be7a6cSMaksim Yevmenkin #include <sys/queue.h>
348d6f425dSTakanori Watanabe #define L2CAP_SOCKET_CHECKED
3507be7a6cSMaksim Yevmenkin #include <bluetooth.h>
3607be7a6cSMaksim Yevmenkin #include <sdp.h>
3707be7a6cSMaksim Yevmenkin #include <string.h>
3807be7a6cSMaksim Yevmenkin #include "profile.h"
3907be7a6cSMaksim Yevmenkin #include "provider.h"
4007be7a6cSMaksim Yevmenkin 
4107be7a6cSMaksim Yevmenkin static int32_t
irmc_profile_create_service_class_id_list(uint8_t * buf,uint8_t const * const eob,uint8_t const * data,uint32_t datalen)4207be7a6cSMaksim Yevmenkin irmc_profile_create_service_class_id_list(
4307be7a6cSMaksim Yevmenkin 		uint8_t *buf, uint8_t const * const eob,
4407be7a6cSMaksim Yevmenkin 		uint8_t const *data, uint32_t datalen)
4507be7a6cSMaksim Yevmenkin {
4607be7a6cSMaksim Yevmenkin 	static uint16_t	service_classes[] = {
4707be7a6cSMaksim Yevmenkin 		SDP_SERVICE_CLASS_IR_MC_SYNC
4807be7a6cSMaksim Yevmenkin 	};
4907be7a6cSMaksim Yevmenkin 
5007be7a6cSMaksim Yevmenkin 	return (common_profile_create_service_class_id_list(
5107be7a6cSMaksim Yevmenkin 			buf, eob,
5207be7a6cSMaksim Yevmenkin 			(uint8_t const *) service_classes,
5307be7a6cSMaksim Yevmenkin 			sizeof(service_classes)));
5407be7a6cSMaksim Yevmenkin }
5507be7a6cSMaksim Yevmenkin 
5607be7a6cSMaksim Yevmenkin static int32_t
irmc_profile_create_bluetooth_profile_descriptor_list(uint8_t * buf,uint8_t const * const eob,uint8_t const * data,uint32_t datalen)5707be7a6cSMaksim Yevmenkin irmc_profile_create_bluetooth_profile_descriptor_list(
5807be7a6cSMaksim Yevmenkin 		uint8_t *buf, uint8_t const * const eob,
5907be7a6cSMaksim Yevmenkin 		uint8_t const *data, uint32_t datalen)
6007be7a6cSMaksim Yevmenkin {
6107be7a6cSMaksim Yevmenkin 	static uint16_t	profile_descriptor_list[] = {
6207be7a6cSMaksim Yevmenkin 		SDP_SERVICE_CLASS_IR_MC_SYNC,
6307be7a6cSMaksim Yevmenkin 		0x0100
6407be7a6cSMaksim Yevmenkin 	};
6507be7a6cSMaksim Yevmenkin 
6607be7a6cSMaksim Yevmenkin 	return (common_profile_create_bluetooth_profile_descriptor_list(
6707be7a6cSMaksim Yevmenkin 			buf, eob,
6807be7a6cSMaksim Yevmenkin 			(uint8_t const *) profile_descriptor_list,
6907be7a6cSMaksim Yevmenkin 			sizeof(profile_descriptor_list)));
7007be7a6cSMaksim Yevmenkin }
7107be7a6cSMaksim Yevmenkin 
7207be7a6cSMaksim Yevmenkin static int32_t
irmc_profile_create_service_name(uint8_t * buf,uint8_t const * const eob,uint8_t const * data,uint32_t datalen)7307be7a6cSMaksim Yevmenkin irmc_profile_create_service_name(
7407be7a6cSMaksim Yevmenkin 		uint8_t *buf, uint8_t const * const eob,
7507be7a6cSMaksim Yevmenkin 		uint8_t const *data, uint32_t datalen)
7607be7a6cSMaksim Yevmenkin {
7707be7a6cSMaksim Yevmenkin 	static char	service_name[] = "IrMC Synchronization";
7807be7a6cSMaksim Yevmenkin 
7907be7a6cSMaksim Yevmenkin 	return (common_profile_create_string8(
8007be7a6cSMaksim Yevmenkin 			buf, eob,
8107be7a6cSMaksim Yevmenkin 			(uint8_t const *) service_name, strlen(service_name)));
8207be7a6cSMaksim Yevmenkin }
8307be7a6cSMaksim Yevmenkin 
8407be7a6cSMaksim Yevmenkin static int32_t
irmc_profile_create_protocol_descriptor_list(uint8_t * buf,uint8_t const * const eob,uint8_t const * data,uint32_t datalen)8507be7a6cSMaksim Yevmenkin irmc_profile_create_protocol_descriptor_list(
8607be7a6cSMaksim Yevmenkin 		uint8_t *buf, uint8_t const * const eob,
8707be7a6cSMaksim Yevmenkin 		uint8_t const *data, uint32_t datalen)
8807be7a6cSMaksim Yevmenkin {
8907be7a6cSMaksim Yevmenkin 	provider_p		provider = (provider_p) data;
9007be7a6cSMaksim Yevmenkin 	sdp_irmc_profile_p	irmc = (sdp_irmc_profile_p) provider->data;
9107be7a6cSMaksim Yevmenkin 
9207be7a6cSMaksim Yevmenkin 	return (obex_profile_create_protocol_descriptor_list(
9307be7a6cSMaksim Yevmenkin 			buf, eob,
9407be7a6cSMaksim Yevmenkin 			(uint8_t const *) &irmc->server_channel, 1));
9507be7a6cSMaksim Yevmenkin }
9607be7a6cSMaksim Yevmenkin 
9707be7a6cSMaksim Yevmenkin static int32_t
irmc_profile_create_supported_formats_list(uint8_t * buf,uint8_t const * const eob,uint8_t const * data,uint32_t datalen)9807be7a6cSMaksim Yevmenkin irmc_profile_create_supported_formats_list(
9907be7a6cSMaksim Yevmenkin 		uint8_t *buf, uint8_t const * const eob,
10007be7a6cSMaksim Yevmenkin 		uint8_t const *data, uint32_t datalen)
10107be7a6cSMaksim Yevmenkin {
10207be7a6cSMaksim Yevmenkin 	provider_p		provider = (provider_p) data;
10307be7a6cSMaksim Yevmenkin 	sdp_irmc_profile_p	irmc = (sdp_irmc_profile_p) provider->data;
10407be7a6cSMaksim Yevmenkin 
10507be7a6cSMaksim Yevmenkin 	return (obex_profile_create_supported_formats_list(
10607be7a6cSMaksim Yevmenkin 			buf, eob,
10707be7a6cSMaksim Yevmenkin 			(uint8_t const *) irmc->supported_formats,
10807be7a6cSMaksim Yevmenkin 			irmc->supported_formats_size));
10907be7a6cSMaksim Yevmenkin }
11007be7a6cSMaksim Yevmenkin 
11107be7a6cSMaksim Yevmenkin static attr_t	irmc_profile_attrs[] = {
11207be7a6cSMaksim Yevmenkin 	{ SDP_ATTR_SERVICE_RECORD_HANDLE,
11307be7a6cSMaksim Yevmenkin 	  common_profile_create_service_record_handle },
11407be7a6cSMaksim Yevmenkin 	{ SDP_ATTR_SERVICE_CLASS_ID_LIST,
11507be7a6cSMaksim Yevmenkin 	  irmc_profile_create_service_class_id_list },
11607be7a6cSMaksim Yevmenkin 	{ SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST,
11707be7a6cSMaksim Yevmenkin 	  irmc_profile_create_bluetooth_profile_descriptor_list },
11807be7a6cSMaksim Yevmenkin 	{ SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST,
11907be7a6cSMaksim Yevmenkin 	  common_profile_create_language_base_attribute_id_list },
12007be7a6cSMaksim Yevmenkin 	{ SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET,
12107be7a6cSMaksim Yevmenkin 	  irmc_profile_create_service_name },
12207be7a6cSMaksim Yevmenkin 	{ SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST,
12307be7a6cSMaksim Yevmenkin 	  irmc_profile_create_protocol_descriptor_list },
12407be7a6cSMaksim Yevmenkin 	{ SDP_ATTR_SUPPORTED_FORMATS_LIST,
12507be7a6cSMaksim Yevmenkin 	  irmc_profile_create_supported_formats_list },
12607be7a6cSMaksim Yevmenkin 	{ 0, NULL } /* end entry */
12707be7a6cSMaksim Yevmenkin };
12807be7a6cSMaksim Yevmenkin 
12907be7a6cSMaksim Yevmenkin profile_t	irmc_profile_descriptor = {
13007be7a6cSMaksim Yevmenkin 	SDP_SERVICE_CLASS_IR_MC_SYNC,
13107be7a6cSMaksim Yevmenkin 	sizeof(sdp_irmc_profile_t),
13207be7a6cSMaksim Yevmenkin 	obex_profile_data_valid,
13307be7a6cSMaksim Yevmenkin 	(attr_t const * const) &irmc_profile_attrs
13407be7a6cSMaksim Yevmenkin };
13507be7a6cSMaksim Yevmenkin 
136