bt_sock.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #pragma once
  17. __BEGIN_DECLS
  18. #define BTSOCK_FLAG_ENCRYPT 1
  19. #define BTSOCK_FLAG_AUTH (1 << 1)
  20. #define BTSOCK_FLAG_NO_SDP (1 << 2)
  21. #define BTSOCK_FLAG_AUTH_MITM (1 << 3)
  22. #define BTSOCK_FLAG_AUTH_16_DIGIT (1 << 4)
  23. #define BTSOCK_FLAG_LE_COC (1 << 5)
  24. typedef enum {
  25. BTSOCK_RFCOMM = 1,
  26. BTSOCK_SCO = 2,
  27. BTSOCK_L2CAP = 3,
  28. BTSOCK_L2CAP_LE = 4
  29. } btsock_type_t;
  30. /** Represents the standard BT SOCKET interface. */
  31. typedef struct {
  32. short size;
  33. RawAddress bd_addr;
  34. int channel;
  35. int status;
  36. // The writer must make writes using a buffer of this maximum size
  37. // to avoid loosing data. (L2CAP only)
  38. unsigned short max_tx_packet_size;
  39. // The reader must read using a buffer of at least this size to avoid
  40. // loosing data. (L2CAP only)
  41. unsigned short max_rx_packet_size;
  42. } __attribute__((packed)) sock_connect_signal_t;
  43. typedef struct {
  44. /** set to size of this struct*/
  45. size_t size;
  46. /**
  47. * Listen to a RFCOMM UUID or channel. It returns the socket fd from which
  48. * btsock_connect_signal can be read out when a remote device connected.
  49. * If neither a UUID nor a channel is provided, a channel will be allocated
  50. * and a service record can be created providing the channel number to
  51. * create_sdp_record(...) in bt_sdp.
  52. * The callingUid is the UID of the application which is requesting the
  53. * socket. This is used for traffic accounting purposes.
  54. */
  55. bt_status_t (*listen)(btsock_type_t type, const char* service_name,
  56. const bluetooth::Uuid* service_uuid, int channel,
  57. int* sock_fd, int flags, int callingUid);
  58. /**
  59. * Connect to a RFCOMM UUID channel of remote device, It returns the socket fd
  60. * from which the btsock_connect_signal and a new socket fd to be accepted can
  61. * be read out when connected. The callingUid is the UID of the application
  62. * which is requesting the socket. This is used for traffic accounting
  63. * purposes.
  64. */
  65. bt_status_t (*connect)(const RawAddress* bd_addr, btsock_type_t type,
  66. const bluetooth::Uuid* uuid, int channel, int* sock_fd,
  67. int flags, int callingUid);
  68. /**
  69. * Set the LE Data Length value to this connected peer to the
  70. * maximum supported by this BT controller. This command
  71. * suggests to the BT controller to set its maximum transmission
  72. * packet size.
  73. */
  74. void (*request_max_tx_data_length)(const RawAddress& bd_addr);
  75. } btsock_interface_t;
  76. __END_DECLS