blob: 69775e06614037136a6be0ec8bd4c0294a439a6f [file] [log] [blame]
Andre Eisenbach05f49542012-09-18 12:15:26 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
kschulz9a92a7b2015-03-06 09:15:43 +010017#pragma once
Andre Eisenbach05f49542012-09-18 12:15:26 -070018
19__BEGIN_DECLS
20
21#define BTSOCK_FLAG_ENCRYPT 1
22#define BTSOCK_FLAG_AUTH (1 << 1)
kschulz9a92a7b2015-03-06 09:15:43 +010023#define BTSOCK_FLAG_NO_SDP (1 << 2)
Casper Bonde3e4c2dc2015-04-21 13:15:50 +020024#define BTSOCK_FLAG_AUTH_MITM (1 << 3)
Andre Eisenbach05f49542012-09-18 12:15:26 -070025
26typedef enum {
27 BTSOCK_RFCOMM = 1,
28 BTSOCK_SCO = 2,
29 BTSOCK_L2CAP = 3
30} btsock_type_t;
31
32/** Represents the standard BT SOCKET interface. */
33typedef struct {
34 short size;
35 bt_bdaddr_t bd_addr;
36 int channel;
37 int status;
Casper Bonde3e4c2dc2015-04-21 13:15:50 +020038
kschulz9a92a7b2015-03-06 09:15:43 +010039 // The writer must make writes using a buffer of this maximum size
40 // to avoid loosing data. (L2CAP only)
41 unsigned short max_tx_packet_size;
Casper Bonde3e4c2dc2015-04-21 13:15:50 +020042
kschulz9a92a7b2015-03-06 09:15:43 +010043 // The reader must read using a buffer of at least this size to avoid
44 // loosing data. (L2CAP only)
45 unsigned short max_rx_packet_size;
Andre Eisenbach05f49542012-09-18 12:15:26 -070046} __attribute__((packed)) sock_connect_signal_t;
47
48typedef struct {
Andre Eisenbach05f49542012-09-18 12:15:26 -070049 /** set to size of this struct*/
50 size_t size;
kschulz9a92a7b2015-03-06 09:15:43 +010051
Andre Eisenbach05f49542012-09-18 12:15:26 -070052 /**
kschulz9a92a7b2015-03-06 09:15:43 +010053 * Listen to a RFCOMM UUID or channel. It returns the socket fd from which
54 * btsock_connect_signal can be read out when a remote device connected.
55 * If neither a UUID nor a channel is provided, a channel will be allocated
56 * and a service record can be created providing the channel number to
57 * create_sdp_record(...) in bt_sdp.
Andre Eisenbach05f49542012-09-18 12:15:26 -070058 */
kschulz9a92a7b2015-03-06 09:15:43 +010059 bt_status_t (*listen)(btsock_type_t type, const char* service_name,
60 const uint8_t* service_uuid, int channel, int* sock_fd, int flags);
61
62 /**
63 * Connect to a RFCOMM UUID channel of remote device, It returns the socket fd from which
Andre Eisenbach05f49542012-09-18 12:15:26 -070064 * the btsock_connect_signal and a new socket fd to be accepted can be read out when connected
65 */
kschulz9a92a7b2015-03-06 09:15:43 +010066 bt_status_t (*connect)(const bt_bdaddr_t *bd_addr, btsock_type_t type, const uint8_t* uuid,
67 int channel, int* sock_fd, int flags);
Andre Eisenbach05f49542012-09-18 12:15:26 -070068} btsock_interface_t;
69
70__END_DECLS
71