Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
kschulz | 9a92a7b | 2015-03-06 09:15:43 +0100 | [diff] [blame] | 17 | #pragma once |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 18 | |
| 19 | __BEGIN_DECLS |
| 20 | |
| 21 | #define BTSOCK_FLAG_ENCRYPT 1 |
| 22 | #define BTSOCK_FLAG_AUTH (1 << 1) |
kschulz | 9a92a7b | 2015-03-06 09:15:43 +0100 | [diff] [blame] | 23 | #define BTSOCK_FLAG_NO_SDP (1 << 2) |
Casper Bonde | 3e4c2dc | 2015-04-21 13:15:50 +0200 | [diff] [blame] | 24 | #define BTSOCK_FLAG_AUTH_MITM (1 << 3) |
Casper Bonde | 5ccdc51 | 2015-05-08 14:33:58 +0200 | [diff] [blame] | 25 | #define BTSOCK_FLAG_AUTH_16_DIGIT (1 << 4) |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 26 | |
| 27 | typedef enum { |
| 28 | BTSOCK_RFCOMM = 1, |
| 29 | BTSOCK_SCO = 2, |
| 30 | BTSOCK_L2CAP = 3 |
| 31 | } btsock_type_t; |
| 32 | |
Srinu Jella | 27026c2 | 2013-09-12 17:59:45 +0530 | [diff] [blame] | 33 | typedef enum { |
| 34 | BTSOCK_OPT_GET_MODEM_BITS = 1, |
| 35 | BTSOCK_OPT_SET_MODEM_BITS = 2, |
| 36 | BTSOCK_OPT_CLR_MODEM_BITS = 3, |
| 37 | } btsock_option_type_t; |
| 38 | |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 39 | /** Represents the standard BT SOCKET interface. */ |
| 40 | typedef struct { |
| 41 | short size; |
| 42 | bt_bdaddr_t bd_addr; |
| 43 | int channel; |
| 44 | int status; |
Casper Bonde | 3e4c2dc | 2015-04-21 13:15:50 +0200 | [diff] [blame] | 45 | |
kschulz | 9a92a7b | 2015-03-06 09:15:43 +0100 | [diff] [blame] | 46 | // The writer must make writes using a buffer of this maximum size |
| 47 | // to avoid loosing data. (L2CAP only) |
| 48 | unsigned short max_tx_packet_size; |
Casper Bonde | 3e4c2dc | 2015-04-21 13:15:50 +0200 | [diff] [blame] | 49 | |
kschulz | 9a92a7b | 2015-03-06 09:15:43 +0100 | [diff] [blame] | 50 | // The reader must read using a buffer of at least this size to avoid |
| 51 | // loosing data. (L2CAP only) |
| 52 | unsigned short max_rx_packet_size; |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 53 | } __attribute__((packed)) sock_connect_signal_t; |
| 54 | |
| 55 | typedef struct { |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 56 | /** set to size of this struct*/ |
| 57 | size_t size; |
kschulz | 9a92a7b | 2015-03-06 09:15:43 +0100 | [diff] [blame] | 58 | |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 59 | /** |
kschulz | 9a92a7b | 2015-03-06 09:15:43 +0100 | [diff] [blame] | 60 | * Listen to a RFCOMM UUID or channel. It returns the socket fd from which |
| 61 | * btsock_connect_signal can be read out when a remote device connected. |
| 62 | * If neither a UUID nor a channel is provided, a channel will be allocated |
| 63 | * and a service record can be created providing the channel number to |
| 64 | * create_sdp_record(...) in bt_sdp. |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 65 | */ |
kschulz | 9a92a7b | 2015-03-06 09:15:43 +0100 | [diff] [blame] | 66 | bt_status_t (*listen)(btsock_type_t type, const char* service_name, |
| 67 | const uint8_t* service_uuid, int channel, int* sock_fd, int flags); |
| 68 | |
| 69 | /** |
| 70 | * Connect to a RFCOMM UUID channel of remote device, It returns the socket fd from which |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 71 | * the btsock_connect_signal and a new socket fd to be accepted can be read out when connected |
| 72 | */ |
kschulz | 9a92a7b | 2015-03-06 09:15:43 +0100 | [diff] [blame] | 73 | bt_status_t (*connect)(const bt_bdaddr_t *bd_addr, btsock_type_t type, const uint8_t* uuid, |
| 74 | int channel, int* sock_fd, int flags); |
Srinu Jella | 27026c2 | 2013-09-12 17:59:45 +0530 | [diff] [blame] | 75 | |
| 76 | /* |
| 77 | * get socket option of rfcomm channel socket. |
| 78 | */ |
| 79 | bt_status_t (*get_sock_opt)(btsock_type_t type, int channel, btsock_option_type_t option_name, |
| 80 | void *option_value, int *option_len); |
| 81 | /* |
| 82 | |
| 83 | * set socket option of rfcomm channel socket. |
| 84 | */ |
| 85 | bt_status_t (*set_sock_opt)(btsock_type_t type, int channel, btsock_option_type_t option_name, |
| 86 | void *option_value, int option_len); |
| 87 | |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 88 | } btsock_interface_t; |
| 89 | |
| 90 | __END_DECLS |
| 91 | |