Home | History | Annotate | Download | only in rfcomm
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 1999-2012 Broadcom Corporation
      4  *
      5  *  Licensed under the Apache License, Version 2.0 (the "License");
      6  *  you may not use this file except in compliance with the License.
      7  *  You may obtain a copy of the License at:
      8  *
      9  *  http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  *
     17  ******************************************************************************/
     18 
     19 /*****************************************************************************
     20  *
     21  *  This file contains definitions internal to the PORT unit
     22  *
     23  *****************************************************************************/
     24 
     25 #ifndef PORT_INT_H
     26 #define PORT_INT_H
     27 
     28 #include "bt_target.h"
     29 #include "gki.h"
     30 #include "rfcdefs.h"
     31 #include "port_api.h"
     32 
     33 /* Local events passed when application event is sent from the api to PORT */
     34 /* ???*/
     35 #define PORT_EVENT_OPEN         (1  | BT_EVT_TO_BTU_SP_EVT)
     36 #define PORT_EVENT_CONTROL      (2  | BT_EVT_TO_BTU_SP_EVT)
     37 #define PORT_EVENT_SET_STATE    (3  | BT_EVT_TO_BTU_SP_EVT)
     38 #define PORT_EVENT_SET_CALLBACK (5  | BT_EVT_TO_BTU_SP_EVT)
     39 #define PORT_EVENT_WRITE        (6  | BT_EVT_TO_BTU_SP_EVT)
     40 #define PORT_EVENT_PURGE        (7  | BT_EVT_TO_BTU_SP_EVT)
     41 #define PORT_EVENT_SEND_ERROR   (8  | BT_EVT_TO_BTU_SP_EVT)
     42 #define PORT_EVENT_FLOW_CONTROL (9  | BT_EVT_TO_BTU_SP_EVT)
     43 
     44 /*
     45 ** Flow control configuration values for the mux
     46 */
     47 #define PORT_FC_UNDEFINED       0   /* mux flow control mechanism not defined yet */
     48 #define PORT_FC_TS710           1   /* use TS 07.10 flow control  */
     49 #define PORT_FC_CREDIT          2   /* use RFCOMM credit based flow control */
     50 
     51 /*
     52 ** Define Port Data Transfere control block
     53 */
     54 typedef struct
     55 {
     56     BUFFER_Q queue;         /* Queue of buffers waiting to be sent */
     57     BOOLEAN  peer_fc;       /* TRUE if flow control is set based on peer's request */
     58     BOOLEAN  user_fc;       /* TRUE if flow control is set based on user's request  */
     59     UINT32   queue_size;    /* Number of data bytes in the queue */
     60     tPORT_CALLBACK *p_callback;  /* Address of the callback function */
     61 } tPORT_DATA;
     62 
     63 /*
     64 ** Port control structure used to pass modem info
     65 */
     66 typedef struct
     67 {
     68 #define MODEM_SIGNAL_DTRDSR        0x01
     69 #define MODEM_SIGNAL_RTSCTS        0x02
     70 #define MODEM_SIGNAL_RI            0x04
     71 #define MODEM_SIGNAL_DCD           0x08
     72 
     73     UINT8   modem_signal;       /* [DTR/DSR | RTS/CTS | RI | DCD ] */
     74 
     75     UINT8   break_signal;       /* 0-3 s in steps of 200 ms */
     76 
     77     UINT8   discard_buffers;    /* 0 - do not discard, 1 - discard */
     78 
     79 #define RFCOMM_CTRL_BREAK_ASAP      0
     80 #define RFCOMM_CTRL_BREAK_IN_SEQ    1
     81 
     82     UINT8   break_signal_seq;   /* as soon as possible | in sequence (default) */
     83 
     84     BOOLEAN fc;                 /* TRUE when the device is unable to accept frames */
     85 } tPORT_CTRL;
     86 
     87 
     88 /*
     89 ** RFCOMM multiplexer Control Block
     90 */
     91 typedef struct
     92 {
     93     TIMER_LIST_ENT tle;       /* Timer list entry */
     94     BUFFER_Q  cmd_q;          /* Queue for command messages on this mux */
     95     UINT8     port_inx[RFCOMM_MAX_DLCI + 1];  /* Array for quick access to  */
     96                                               /* tPORT based on dlci        */
     97     BD_ADDR   bd_addr;        /* BD ADDR of the peer if initiator */
     98     UINT16    lcid;           /* Local cid used for this channel */
     99     UINT16    peer_l2cap_mtu; /* Max frame that can be sent to peer L2CAP */
    100     UINT8     state;          /* Current multiplexer channel state */
    101     UINT8     is_initiator;   /* TRUE if this side sends SABME (dlci=0) */
    102     BOOLEAN   local_cfg_sent;
    103     BOOLEAN   peer_cfg_rcvd;
    104     BOOLEAN   restart_required; /* TRUE if has to restart channel after disc */
    105     BOOLEAN   peer_ready;      /* True if other side can accept frames */
    106     UINT8     flow;            /* flow control mechanism for this mux */
    107     BOOLEAN   l2cap_congested; /* TRUE if L2CAP is congested */
    108     BOOLEAN   is_disc_initiator; /* TRUE if initiated disc of port */
    109     UINT16    pending_lcid;    /* store LCID for incoming connection while connecting */
    110     UINT8     pending_id;      /* store l2cap ID for incoming connection while connecting */
    111 } tRFC_MCB;
    112 
    113 
    114 /*
    115 ** RFCOMM Port Connection Control Block
    116 */
    117 struct t_rfc_port
    118 {
    119 #define RFC_PORT_STATE_IDLE          0
    120 #define RFC_PORT_STATE_WAIT_START    1
    121 #define RFC_PORT_STATE_OPENING       2
    122 #define RFC_PORT_STATE_OPENED        3
    123 #define RFC_PORT_STATE_CLOSING       4
    124 
    125     UINT8     state;          /* Current state of the connection */
    126 
    127 #define RFC_RSP_PN                  0x01
    128 #define RFC_RSP_RPN_REPLY           0x02
    129 #define RFC_RSP_RPN                 0x04
    130 #define RFC_RSP_MSC                 0x08
    131 #define RFC_RSP_RLS                 0x10
    132 
    133     UINT8    expected_rsp;
    134 
    135     tRFC_MCB *p_mcb;
    136 
    137     TIMER_LIST_ENT tle;       /* Timer list entry */
    138 };
    139 typedef struct t_rfc_port tRFC_PORT;
    140 
    141 
    142 /*
    143 ** Define control block containing information about PORT connection
    144 */
    145 struct t_port_info
    146 {
    147     UINT8   inx;            /* Index of this control block in the port_info array */
    148     BOOLEAN in_use;         /* True when structure is allocated */
    149 
    150 #define PORT_STATE_CLOSED   0
    151 #define PORT_STATE_OPENING  1
    152 #define PORT_STATE_OPENED   2
    153 #define PORT_STATE_CLOSING  3
    154 
    155     UINT8   state;          /* State of the application */
    156 
    157     UINT8   scn;            /* Service channel number */
    158     UINT16  uuid;           /* Service UUID */
    159 
    160     BD_ADDR bd_addr;        /* BD ADDR of the device for the multiplexer channel */
    161     BOOLEAN is_server;      /* TRUE if the server application */
    162     UINT8   dlci;           /* DLCI of the connection */
    163 
    164     UINT8   error;          /* Last error detected */
    165 
    166     UINT8   line_status;    /* Line status as reported by peer */
    167 
    168     UINT8   default_signal_state; /* Initial signal state depending on uuid */
    169 
    170     UINT16  mtu;            /* Max MTU that port can receive */
    171     UINT16  peer_mtu;       /* Max MTU that port can send */
    172 
    173     tPORT_DATA tx;          /* Control block for data from app to peer */
    174     tPORT_DATA rx;          /* Control block for data from peer to app */
    175 
    176     tPORT_STATE user_port_pars;  /* Port parameters for user connection */
    177     tPORT_STATE peer_port_pars;  /* Port parameters for user connection */
    178 
    179     tPORT_CTRL  local_ctrl;
    180     tPORT_CTRL  peer_ctrl;
    181 
    182 #define PORT_CTRL_REQ_SENT          0x01
    183 #define PORT_CTRL_REQ_CONFIRMED     0x02
    184 #define PORT_CTRL_IND_RECEIVED      0x04
    185 #define PORT_CTRL_IND_RESPONDED     0x08
    186 
    187     UINT8       port_ctrl;                  /* Modem Status Command  */
    188 
    189     BOOLEAN     rx_flag_ev_pending;         /* RXFLAG Character is received */
    190 
    191     tRFC_PORT   rfc;                        /* RFCOMM port control block */
    192 
    193     UINT32      ev_mask;                    /* Event mask for the callback */
    194     tPORT_CALLBACK      *p_callback;        /* Pointer to users callback function */
    195     tPORT_CALLBACK      *p_mgmt_callback;   /* Callback function to receive connection up/down */
    196     tPORT_DATA_CALLBACK *p_data_callback;   /* Callback function to receive data indications */
    197     tPORT_DATA_CO_CALLBACK *p_data_co_callback;   /* Callback function with callouts and flowctrl */
    198     UINT16      credit_tx;                  /* Flow control credits for tx path */
    199     UINT16      credit_rx;                  /* Flow control credits for rx path, this is */
    200                                             /* number of buffers peer is allowed to sent */
    201     UINT16      credit_rx_max;              /* Max number of credits we will allow this guy to sent */
    202     UINT16      credit_rx_low;              /* Number of credits when we send credit update */
    203     UINT16      rx_buf_critical;            /* port receive queue critical watermark level */
    204     BOOLEAN     keep_port_handle;           /* TRUE if port is not deallocated when closing */
    205                                             /* it is set to TRUE for server when allocating port */
    206     UINT16      keep_mtu;                   /* Max MTU that port can receive by server */
    207 };
    208 typedef struct t_port_info tPORT;
    209 
    210 
    211 /* Define the PORT/RFCOMM control structure
    212 */
    213 typedef struct
    214 {
    215     tPORT        port[MAX_RFC_PORTS];            /* Port info pool */
    216     tRFC_MCB     rfc_mcb[MAX_BD_CONNECTIONS];    /* RFCOMM bd_connections pool */
    217 } tPORT_CB;
    218 
    219 #ifdef __cplusplus
    220 extern "C" {
    221 #endif
    222 
    223 /*
    224 ** Functions provided by the port_utils.c
    225 */
    226 extern tPORT    *port_allocate_port (UINT8 dlci, BD_ADDR bd_addr);
    227 extern void     port_set_defaults (tPORT *p_port);
    228 extern void     port_select_mtu (tPORT *p_port);
    229 extern void     port_release_port (tPORT *p_port);
    230 extern tPORT    *port_find_mcb_dlci_port (tRFC_MCB *p_mcb, UINT8 dlci);
    231 extern tRFC_MCB *port_find_mcb (BD_ADDR bd_addr);
    232 extern tPORT    *port_find_dlci_port (UINT8 dlci);
    233 extern tPORT    *port_find_port (UINT8 dlci, BD_ADDR bd_addr);
    234 extern UINT32   port_get_signal_changes (tPORT *p_port, UINT8 old_signals, UINT8 signal);
    235 extern UINT32   port_flow_control_user (tPORT *p_port);
    236 extern void     port_flow_control_peer(tPORT *p_port, BOOLEAN enable, UINT16 count);
    237 
    238 /*
    239 ** Functions provided by the port_rfc.c
    240 */
    241 extern int  port_open_continue (tPORT *p_port);
    242 extern void port_start_port_open (tPORT *p_port);
    243 extern void port_start_par_neg (tPORT *p_port);
    244 extern void port_start_control (tPORT *p_port);
    245 extern void port_start_close (tPORT *p_port);
    246 extern void port_rfc_closed (tPORT *p_port, UINT8 res);
    247 
    248 #ifdef __cplusplus
    249 }
    250 #endif
    251 
    252 #endif
    253