1 /* 2 * 3 * MCAP for BlueZ - Bluetooth protocol stack for Linux 4 * 5 * Copyright (C) 2010 GSyC/LibreSoft, Universidad Rey Juan Carlos. 6 * 7 * Authors: 8 * Santiago Carot-Nemesio <sancane at gmail.com> 9 * Jose Antonio Santos-Cadenas <santoscadenas at gmail.com> 10 * 11 * This program is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation; either version 2 of the License, or 14 * (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with this program; if not, write to the Free Software 23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 * 25 */ 26 27 #ifndef __MCAP_INTERNAL_H 28 #define __MCAP_INTERNAL_H 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 typedef enum { 35 MCL_CONNECTED, 36 MCL_PENDING, 37 MCL_ACTIVE, 38 MCL_IDLE 39 } MCLState; 40 41 typedef enum { 42 MCL_ACCEPTOR, 43 MCL_INITIATOR 44 } MCLRole; 45 46 typedef enum { 47 MCL_AVAILABLE, 48 MCL_WAITING_RSP 49 } MCAPCtrl; 50 51 typedef enum { 52 MDL_WAITING, 53 MDL_CONNECTED, 54 MDL_DELETING, 55 MDL_CLOSED 56 } MDLState; 57 58 struct mcap_mdl_cb { 59 mcap_mdl_event_cb mdl_connected; /* Remote device has created a MDL */ 60 mcap_mdl_event_cb mdl_closed; /* Remote device has closed a MDL */ 61 mcap_mdl_event_cb mdl_deleted; /* Remote device requested deleting a MDL */ 62 mcap_mdl_event_cb mdl_aborted; /* Remote device aborted the mdl creation */ 63 mcap_remote_mdl_conn_req_cb mdl_conn_req; /* Remote device requested creating a MDL */ 64 mcap_remote_mdl_reconn_req_cb mdl_reconn_req; /* Remote device requested reconnecting a MDL */ 65 gpointer user_data; /* User data */ 66 }; 67 68 struct mcap_instance { 69 bdaddr_t src; /* Source address */ 70 GIOChannel *ccio; /* Control Channel IO */ 71 GIOChannel *dcio; /* Data Channel IO */ 72 GSList *mcls; /* MCAP instance list */ 73 GSList *cached; /* List with all cached MCLs (MAX_CACHED macro) */ 74 BtIOSecLevel sec; /* Security level */ 75 mcap_mcl_event_cb mcl_connected_cb; /* New MCL connected */ 76 mcap_mcl_event_cb mcl_reconnected_cb; /* Old MCL has been reconnected */ 77 mcap_mcl_event_cb mcl_disconnected_cb; /* MCL disconnected */ 78 mcap_mcl_event_cb mcl_uncached_cb; /* MCL has been removed from MCAP cache */ 79 mcap_info_ind_event_cb mcl_sync_infoind_cb; /* (CSP Master) Received info indication */ 80 gpointer user_data; /* Data to be provided in callbacks */ 81 gint ref; /* Reference counter */ 82 83 gboolean csp_enabled; /* CSP: functionality enabled */ 84 }; 85 86 struct mcap_csp; 87 struct mcap_mdl_op_cb; 88 89 struct mcap_mcl { 90 struct mcap_instance *mi; /* MCAP instance where this MCL belongs */ 91 bdaddr_t addr; /* Device address */ 92 GIOChannel *cc; /* MCAP Control Channel IO */ 93 guint wid; /* MCL Watcher id */ 94 GSList *mdls; /* List of Data Channels shorted by mdlid */ 95 MCLState state; /* Current MCL State */ 96 MCLRole role; /* Initiator or acceptor of this MCL */ 97 MCAPCtrl req; /* Request control flag */ 98 struct mcap_mdl_op_cb *priv_data; /* Temporal data to manage responses */ 99 struct mcap_mdl_cb *cb; /* MDL callbacks */ 100 guint tid; /* Timer id for waiting for a response */ 101 uint8_t *lcmd; /* Last command sent */ 102 gint ref; /* References counter */ 103 uint8_t ctrl; /* MCL control flag */ 104 uint16_t next_mdl; /* id used to create next MDL */ 105 struct mcap_csp *csp; /* CSP control structure */ 106 }; 107 108 #define MCAP_CTRL_CACHED 0x01 /* MCL is cached */ 109 #define MCAP_CTRL_STD_OP 0x02 /* Support for standard op codes */ 110 #define MCAP_CTRL_SYNC_OP 0x04 /* Support for synchronization commands */ 111 #define MCAP_CTRL_CONN 0x08 /* MCL is in connecting process */ 112 #define MCAP_CTRL_FREE 0x10 /* MCL is marked as releasable */ 113 #define MCAP_CTRL_NOCACHE 0x20 /* MCL is marked as not cacheable */ 114 115 struct mcap_mdl { 116 struct mcap_mcl *mcl; /* MCL where this MDL belongs */ 117 GIOChannel *dc; /* MCAP Data Channel IO */ 118 guint wid; /* MDL Watcher id */ 119 uint16_t mdlid; /* MDL id */ 120 uint8_t mdep_id; /* MCAP Data End Point */ 121 MDLState state; /* MDL state */ 122 gint ref; /* References counter */ 123 }; 124 125 struct sync_info_ind_data { 126 uint32_t btclock; 127 uint64_t timestamp; 128 uint16_t accuracy; 129 }; 130 131 int mcap_send_data(int sock, const void *buf, uint32_t size); 132 133 void proc_sync_cmd(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len); 134 void mcap_sync_init(struct mcap_mcl *mcl); 135 void mcap_sync_stop(struct mcap_mcl *mcl); 136 137 #ifdef __cplusplus 138 } 139 #endif 140 141 #endif /* __MCAP_INTERNAL_H */ 142