~ubuntu-branches/ubuntu/wily/bluez/wily

« back to all changes in this revision

Viewing changes to cups/sdp.c

  • Committer: Bazaar Package Importer
  • Author(s): Mario Limonciello
  • Date: 2008-10-07 12:10:29 UTC
  • Revision ID: james.westby@ubuntu.com-20081007121029-4gup4fmmh2vfo5nh
Tags: upstream-4.12
ImportĀ upstreamĀ versionĀ 4.12

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 *  BlueZ - Bluetooth protocol stack for Linux
 
4
 *
 
5
 *  Copyright (C) 2003-2008  Marcel Holtmann <marcel@holtmann.org>
 
6
 *
 
7
 *
 
8
 *  This program is free software; you can redistribute it and/or modify
 
9
 *  it under the terms of the GNU General Public License as published by
 
10
 *  the Free Software Foundation; either version 2 of the License, or
 
11
 *  (at your option) any later version.
 
12
 *
 
13
 *  This program is distributed in the hope that it will be useful,
 
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 *  GNU General Public License for more details.
 
17
 *
 
18
 *  You should have received a copy of the GNU General Public License
 
19
 *  along with this program; if not, write to the Free Software
 
20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
21
 *
 
22
 */
 
23
 
 
24
#ifdef HAVE_CONFIG_H
 
25
#include <config.h>
 
26
#endif
 
27
 
 
28
#include <stdio.h>
 
29
#include <errno.h>
 
30
#include <unistd.h>
 
31
#include <signal.h>
 
32
#include <sys/socket.h>
 
33
 
 
34
#include <bluetooth/bluetooth.h>
 
35
#include <bluetooth/sdp.h>
 
36
#include <bluetooth/sdp_lib.h>
 
37
 
 
38
int sdp_search_hcrp(sdp_session_t *sdp, unsigned short *ctrl_psm, unsigned short *data_psm)
 
39
{
 
40
        sdp_list_t *srch, *attrs, *rsp;
 
41
        uuid_t svclass;
 
42
        uint16_t attr1, attr2;
 
43
        int err;
 
44
 
 
45
        if (!sdp)
 
46
                return -1;
 
47
 
 
48
        sdp_uuid16_create(&svclass, HCR_PRINT_SVCLASS_ID);
 
49
        srch = sdp_list_append(NULL, &svclass);
 
50
 
 
51
        attr1 = SDP_ATTR_PROTO_DESC_LIST;
 
52
        attrs = sdp_list_append(NULL, &attr1);
 
53
        attr2 = SDP_ATTR_ADD_PROTO_DESC_LIST;
 
54
        attrs = sdp_list_append(attrs, &attr2);
 
55
 
 
56
        err = sdp_service_search_attr_req(sdp, srch, SDP_ATTR_REQ_INDIVIDUAL, attrs, &rsp);
 
57
        if (err)
 
58
                return -1;
 
59
 
 
60
        for (; rsp; rsp = rsp->next) {
 
61
                sdp_record_t *rec = (sdp_record_t *) rsp->data;
 
62
                sdp_list_t *protos;
 
63
 
 
64
                if (!sdp_get_access_protos(rec, &protos)) {
 
65
                        unsigned short psm = sdp_get_proto_port(protos, L2CAP_UUID);
 
66
                        if (psm > 0) {
 
67
                                *ctrl_psm = psm;
 
68
                        }
 
69
                }
 
70
 
 
71
                if (!sdp_get_add_access_protos(rec, &protos)) {
 
72
                        unsigned short psm = sdp_get_proto_port(protos, L2CAP_UUID);
 
73
                        if (psm > 0 && *ctrl_psm > 0) {
 
74
                                *data_psm = psm;
 
75
                                return 0;
 
76
                        }
 
77
                }
 
78
        }
 
79
 
 
80
        return -1;
 
81
}
 
82
 
 
83
int sdp_search_spp(sdp_session_t *sdp, uint8_t *channel)
 
84
{
 
85
        sdp_list_t *srch, *attrs, *rsp;
 
86
        uuid_t svclass;
 
87
        uint16_t attr;
 
88
        int err;
 
89
 
 
90
        if (!sdp)
 
91
                return -1;
 
92
 
 
93
        sdp_uuid16_create(&svclass, SERIAL_PORT_SVCLASS_ID);
 
94
        srch = sdp_list_append(NULL, &svclass);
 
95
 
 
96
        attr = SDP_ATTR_PROTO_DESC_LIST;
 
97
        attrs = sdp_list_append(NULL, &attr);
 
98
 
 
99
        err = sdp_service_search_attr_req(sdp, srch, SDP_ATTR_REQ_INDIVIDUAL, attrs, &rsp);
 
100
        if (err)
 
101
                return -1;
 
102
 
 
103
        for (; rsp; rsp = rsp->next) {
 
104
                sdp_record_t *rec = (sdp_record_t *) rsp->data;
 
105
                sdp_list_t *protos;
 
106
 
 
107
                if (!sdp_get_access_protos(rec, &protos)) {
 
108
                        uint8_t ch = sdp_get_proto_port(protos, RFCOMM_UUID);
 
109
                        if (ch > 0) {
 
110
                                *channel = ch;
 
111
                                return 0;
 
112
                        }
 
113
                }
 
114
        }
 
115
 
 
116
        return -1;
 
117
}