1124758Semax/* 2124758Semax * lan.c 3124758Semax * 4124758Semax * Copyright (c) 2004 Maksim Yevmenkin <m_evmenkin@yahoo.com> 5124758Semax * All rights reserved. 6124758Semax * 7124758Semax * Redistribution and use in source and binary forms, with or without 8124758Semax * modification, are permitted provided that the following conditions 9124758Semax * are met: 10124758Semax * 1. Redistributions of source code must retain the above copyright 11124758Semax * notice, this list of conditions and the following disclaimer. 12124758Semax * 2. Redistributions in binary form must reproduce the above copyright 13124758Semax * notice, this list of conditions and the following disclaimer in the 14124758Semax * documentation and/or other materials provided with the distribution. 15124758Semax * 16124758Semax * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17124758Semax * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18124758Semax * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19124758Semax * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20124758Semax * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21124758Semax * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22124758Semax * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23124758Semax * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24124758Semax * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25124758Semax * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26124758Semax * SUCH DAMAGE. 27124758Semax * 28124758Semax * $Id: lan.c,v 1.5 2004/01/13 01:54:39 max Exp $ 29124758Semax * $FreeBSD$ 30124758Semax */ 31124758Semax 32124758Semax#include <arpa/inet.h> 33124758Semax#include <sys/queue.h> 34124758Semax#include <bluetooth.h> 35124758Semax#include <sdp.h> 36124758Semax#include <stdio.h> 37124758Semax#include <string.h> 38124758Semax#include "profile.h" 39124758Semax#include "provider.h" 40124758Semax 41124758Semaxstatic int32_t 42124758Semaxlan_profile_create_service_class_id_list( 43124758Semax uint8_t *buf, uint8_t const * const eob, 44124758Semax uint8_t const *data, uint32_t datalen) 45124758Semax{ 46124758Semax static uint16_t service_classes[] = { 47124758Semax SDP_SERVICE_CLASS_LAN_ACCESS_USING_PPP 48124758Semax }; 49124758Semax 50124758Semax return (common_profile_create_service_class_id_list( 51124758Semax buf, eob, 52124758Semax (uint8_t const *) service_classes, 53124758Semax sizeof(service_classes))); 54124758Semax} 55124758Semax 56124758Semaxstatic int32_t 57124758Semaxlan_profile_create_bluetooth_profile_descriptor_list( 58124758Semax uint8_t *buf, uint8_t const * const eob, 59124758Semax uint8_t const *data, uint32_t datalen) 60124758Semax{ 61124758Semax static uint16_t profile_descriptor_list[] = { 62124758Semax SDP_SERVICE_CLASS_LAN_ACCESS_USING_PPP, 63124758Semax 0x0100 64124758Semax }; 65124758Semax 66124758Semax return (common_profile_create_bluetooth_profile_descriptor_list( 67124758Semax buf, eob, 68124758Semax (uint8_t const *) profile_descriptor_list, 69124758Semax sizeof(profile_descriptor_list))); 70124758Semax} 71124758Semax 72124758Semaxstatic int32_t 73124758Semaxlan_profile_create_service_name( 74124758Semax uint8_t *buf, uint8_t const * const eob, 75124758Semax uint8_t const *data, uint32_t datalen) 76124758Semax{ 77124758Semax static char service_name[] = "LAN Access using PPP"; 78124758Semax 79124758Semax return (common_profile_create_string8( 80124758Semax buf, eob, 81124758Semax (uint8_t const *) service_name, strlen(service_name))); 82124758Semax} 83124758Semax 84124758Semaxstatic int32_t 85124758Semaxlan_profile_create_protocol_descriptor_list( 86124758Semax uint8_t *buf, uint8_t const * const eob, 87124758Semax uint8_t const *data, uint32_t datalen) 88124758Semax{ 89124758Semax provider_p provider = (provider_p) data; 90124758Semax sdp_lan_profile_p lan = (sdp_lan_profile_p) provider->data; 91124758Semax 92124758Semax return (rfcomm_profile_create_protocol_descriptor_list( 93124758Semax buf, eob, 94124758Semax (uint8_t const *) &lan->server_channel, 1)); 95124758Semax} 96124758Semax 97124758Semaxstatic int32_t 98124758Semaxlan_profile_create_service_availability( 99124758Semax uint8_t *buf, uint8_t const * const eob, 100124758Semax uint8_t const *data, uint32_t datalen) 101124758Semax{ 102124758Semax provider_p provider = (provider_p) data; 103124758Semax sdp_lan_profile_p lan = (sdp_lan_profile_p) provider->data; 104124758Semax 105177358Semax return (common_profile_create_service_availability(buf, eob, 106177358Semax &lan->load_factor, 1)); 107124758Semax} 108124758Semax 109124758Semaxstatic int32_t 110124758Semaxlan_profile_create_ip_subnet( 111124758Semax uint8_t *buf, uint8_t const * const eob, 112124758Semax uint8_t const *data, uint32_t datalen) 113124758Semax{ 114124758Semax provider_p provider = (provider_p) data; 115124758Semax sdp_lan_profile_p lan = (sdp_lan_profile_p) provider->data; 116124758Semax char net[32]; 117124758Semax int32_t len; 118124758Semax 119124758Semax len = snprintf(net, sizeof(net), "%s/%d", 120124758Semax inet_ntoa(* (struct in_addr *) &lan->ip_subnet), 121124758Semax lan->ip_subnet_radius); 122124758Semax 123124758Semax if (len < 0 || buf + 2 + len > eob) 124124758Semax return (-1); 125124758Semax 126124758Semax SDP_PUT8(SDP_DATA_STR8, buf); 127124758Semax SDP_PUT8(len, buf); 128124758Semax memcpy(buf, net, len); 129124758Semax 130124758Semax return (2 + len); 131124758Semax} 132124758Semax 133124758Semaxstatic int32_t 134124758Semaxlan_profile_data_valid(uint8_t const *data, uint32_t datalen) 135124758Semax{ 136124758Semax sdp_lan_profile_p lan = (sdp_lan_profile_p) data; 137124758Semax 138124758Semax if (lan->server_channel < 1 || 139124758Semax lan->server_channel > 30 || 140124758Semax lan->ip_subnet_radius > 32) 141124758Semax return (0); 142124758Semax 143124758Semax return (1); 144124758Semax} 145124758Semax 146124758Semaxstatic attr_t lan_profile_attrs[] = { 147124758Semax { SDP_ATTR_SERVICE_RECORD_HANDLE, 148124758Semax common_profile_create_service_record_handle }, 149124758Semax { SDP_ATTR_SERVICE_CLASS_ID_LIST, 150124758Semax lan_profile_create_service_class_id_list }, 151124758Semax { SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST, 152124758Semax lan_profile_create_bluetooth_profile_descriptor_list }, 153124758Semax { SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST, 154124758Semax common_profile_create_language_base_attribute_id_list }, 155124758Semax { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET, 156124758Semax lan_profile_create_service_name }, 157124758Semax { SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST, 158124758Semax lan_profile_create_protocol_descriptor_list }, 159124758Semax { SDP_ATTR_SERVICE_AVAILABILITY, 160124758Semax lan_profile_create_service_availability }, 161124758Semax { SDP_ATTR_IP_SUBNET, 162124758Semax lan_profile_create_ip_subnet }, 163124758Semax { 0, NULL } /* end entry */ 164124758Semax}; 165124758Semax 166124758Semaxprofile_t lan_profile_descriptor = { 167124758Semax SDP_SERVICE_CLASS_LAN_ACCESS_USING_PPP, 168124758Semax sizeof(sdp_lan_profile_t), 169124758Semax lan_profile_data_valid, 170124758Semax (attr_t const * const) &lan_profile_attrs 171124758Semax}; 172124758Semax 173