File: btsrv-sdp.c

package info (click to toggle)
affix 2.1.1-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,908 kB
  • ctags: 1,247
  • sloc: ansic: 13,807; sh: 7,119; yacc: 232; makefile: 152; lex: 126; python: 56
file content (172 lines) | stat: -rw-r--r-- 4,041 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* 
   Affix - Bluetooth Protocol Stack for Linux
   Copyright (C) 2001, 2002 Nokia Corporation
   Author: Dmitry Kasatkin <dmitry.kasatkin@nokia.com>
   
   Original Author: Imre Deak <ext-imre.deak@nokia.com>

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2 of the License, or (at your
   option) any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License along
   with this program; if not, write to the Free Software Foundation, Inc.,
   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   */

/* 
   $Id: btsrv-sdp.c,v 1.5 2003/10/06 10:51:24 kds Exp $

   Registering SDP records with the local SDP server.  

   Fixes:
   		Imre Deak <ext-imre.deak@nokia.com>
		Dmitry Kasatkin <dmitry.kasatkin@nokia.com>
*/

#include <affix/config.h>

#include <stdlib.h>
#include <string.h>

#include <affix/btcore.h>

#include <affix/sdp.h>
#include <affix/sdpclt.h>
#include <affix/sdpsrv.h>

#include "btsrv.h"

static int	srvHandle = -1;

int sdpreg_init(void)
{
	// initialize the SDP internal data structures

	if (sdp_init(SDP_SVC_PROVIDER) != 0)
		return -1;
	srvHandle = sdp_connect_local();
	if (srvHandle < 0)
		return srvHandle;
	return 0;
}

void sdpreg_cleanup(void)
{
	sdp_close(srvHandle);
	sdp_cleanup();
}

int sdpreg_register(service_t *svc)
{
	if (svc->info->reg_func && svc->info->reg_func(svc) < 0) {
		BTERROR("Unable to register SDP record for service %s", svc->name);
		return -1;
	}
	return 0;
}

int sdpreg_unregister(service_t *svc)
{
	int		status;
	sdpsvc_t	*svcRec = svc->svcRec;

	if (!svcRec)
		return 0;
	status = sdp_delete_service(srvHandle, svcRec);
	switch (status) {
		case 0:
			BTINFO("service %s deleted", svc->name);
			break;
		case SDP_ERR_INVALID_ARG:
			BTERROR("Error: You cannot delete service %s", svc->name);
			break;
		default:
			BTERROR("Something went wrong. sdp_delete_service() returned: %d\n", status);
			break;
	}
	sdp_free_svc(svcRec);
	svc->svcRec = NULL;
	return 0;
}

int sdpreg_rfcomm(service_t *svc)
{
	int		status = -1;
	sdpsvc_t	*svcRec;

	svcRec = sdp_create_rfcomm_svc(svc->info->svc_class, svc->info->generic_class, svc->info->profile,
			svc->name, svc->prov, svc->desc, svc->port);
	if (!svcRec) {
		BTERROR("sdp_create_svc failed");
		return -1;
	}
	status = sdp_register_service(srvHandle, svcRec);
	if (status != 0) {
		BTERROR("sdp_register_service failed");
		sdp_free_svc(svcRec);
		return -1;
	}
	svc->svcRec = svcRec;
	return 0;
}

int sdpreg_pan(service_t *svc)
{
	int		status = -1;
	sdpsvc_t	*svcRec;
	sdpdata_t	*attr;
	slist_t		*ptype = NULL;

	/*
	 ** First create a service record handle
	 */
	s_list_append_uint(&ptype, 0x800); 
	s_list_append_uint(&ptype, 0x806);
	svcRec = sdp_create_pan_svc(svc->info->svc_class, ptype, 0x0000, 0x0005, 0x100);
	s_list_free(&ptype);
	if (svcRec == NULL)
		return -1;
	/* add language attribute */
	attr = sdp_set_lang_attr(svcRec);
	if (attr == NULL) {
		BTERROR("setLanguageBase failed");
		sdp_free_svc(svcRec);
		return -1;
	}
	status = sdp_add_lang(attr, 0, 0, 0);
	if (status) {
		sdp_free_svc(svcRec);
		return -1;
	}
	/* set informational attibutes */		
	status = sdp_set_info_attr(svcRec, svc->name, svc->prov, svc->desc);
	if (status != 0) {
		sdp_free_svc(svcRec);
		return -1;
	}
	status = sdp_register_service(srvHandle, svcRec);
	if (status != 0) {
		BTERROR("sdp_register_service failed");
		sdp_free_svc(svcRec);
		return -1;
	}
	svc->svcRec = svcRec;
	return 0;
}

/*
	  ipSubnetValuePtr[0] = (char *)malloc(32);
	  sprintf(ipSubnetValuePtr[0], "192.168.0");
	  ipSubnetValuePtr[1] = (char *)malloc(32);
	  sprintf(ipSubnetValuePtr[1], "192.168.1");

	  SDP_ATTR_IP_SUBNET
*/