12531c97eSMatthias Ringwald /* 22531c97eSMatthias Ringwald * Copyright (C) 2014 BlueKitchen GmbH 32531c97eSMatthias Ringwald * 42531c97eSMatthias Ringwald * Redistribution and use in source and binary forms, with or without 52531c97eSMatthias Ringwald * modification, are permitted provided that the following conditions 62531c97eSMatthias Ringwald * are met: 72531c97eSMatthias Ringwald * 82531c97eSMatthias Ringwald * 1. Redistributions of source code must retain the above copyright 92531c97eSMatthias Ringwald * notice, this list of conditions and the following disclaimer. 102531c97eSMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright 112531c97eSMatthias Ringwald * notice, this list of conditions and the following disclaimer in the 122531c97eSMatthias Ringwald * documentation and/or other materials provided with the distribution. 132531c97eSMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of 142531c97eSMatthias Ringwald * contributors may be used to endorse or promote products derived 152531c97eSMatthias Ringwald * from this software without specific prior written permission. 162531c97eSMatthias Ringwald * 4. Any redistribution, use, or modification is done solely for 172531c97eSMatthias Ringwald * personal benefit and not for any commercial purpose or for 182531c97eSMatthias Ringwald * monetary gain. 192531c97eSMatthias Ringwald * 202531c97eSMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 212531c97eSMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 222531c97eSMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23*2fca4dadSMilanka Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN 24*2fca4dadSMilanka Ringwald * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 252531c97eSMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 262531c97eSMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 272531c97eSMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 282531c97eSMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 292531c97eSMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 302531c97eSMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 312531c97eSMatthias Ringwald * SUCH DAMAGE. 322531c97eSMatthias Ringwald * 332531c97eSMatthias Ringwald * Please inquire about commercial licensing options at 342531c97eSMatthias Ringwald * [email protected] 352531c97eSMatthias Ringwald * 362531c97eSMatthias Ringwald */ 372531c97eSMatthias Ringwald 382531c97eSMatthias Ringwald 392531c97eSMatthias Ringwald /* 402531c97eSMatthias Ringwald * socket_connection.h 412531c97eSMatthias Ringwald * 422531c97eSMatthias Ringwald * Created by Matthias Ringwald on 6/6/09. 432531c97eSMatthias Ringwald */ 442531c97eSMatthias Ringwald 4580e33422SMatthias Ringwald #ifndef SOCKET_CONNECTION_H 4680e33422SMatthias Ringwald #define SOCKET_CONNECTION_H 472531c97eSMatthias Ringwald 482531c97eSMatthias Ringwald #include "btstack_run_loop.h" 492531c97eSMatthias Ringwald 502531c97eSMatthias Ringwald #include <stdint.h> 512531c97eSMatthias Ringwald 522531c97eSMatthias Ringwald #if defined __cplusplus 532531c97eSMatthias Ringwald extern "C" { 542531c97eSMatthias Ringwald #endif 552531c97eSMatthias Ringwald 562531c97eSMatthias Ringwald /** opaque connection type */ 572531c97eSMatthias Ringwald typedef struct connection connection_t; 582531c97eSMatthias Ringwald 592531c97eSMatthias Ringwald /** 60e32b1c03SMatthias Ringwald * Init socket connection module 61e32b1c03SMatthias Ringwald */ 62e32b1c03SMatthias Ringwald void socket_connection_init(void); 63e32b1c03SMatthias Ringwald 64e32b1c03SMatthias Ringwald /** 652531c97eSMatthias Ringwald * create socket data_source for socket specified by launchd configuration 662531c97eSMatthias Ringwald */ 672531c97eSMatthias Ringwald int socket_connection_create_launchd(void); 682531c97eSMatthias Ringwald 692531c97eSMatthias Ringwald /** 702531c97eSMatthias Ringwald * create socket for incoming tcp connections 712531c97eSMatthias Ringwald */ 722531c97eSMatthias Ringwald int socket_connection_create_tcp(int port); 732531c97eSMatthias Ringwald 742531c97eSMatthias Ringwald /** 752531c97eSMatthias Ringwald * create socket for incoming unix domain connections 762531c97eSMatthias Ringwald */ 772531c97eSMatthias Ringwald int socket_connection_create_unix(char *path); 782531c97eSMatthias Ringwald 792531c97eSMatthias Ringwald /** 802531c97eSMatthias Ringwald * close socket connection to BTdaemon 812531c97eSMatthias Ringwald */ 822531c97eSMatthias Ringwald int socket_connection_close_tcp(connection_t *connection); 832531c97eSMatthias Ringwald 842531c97eSMatthias Ringwald /** 852531c97eSMatthias Ringwald * create TCP socket connection to BTdaemon 862531c97eSMatthias Ringwald */ 872531c97eSMatthias Ringwald connection_t * socket_connection_open_tcp(const char *address, uint16_t port); 882531c97eSMatthias Ringwald 892531c97eSMatthias Ringwald /** 902531c97eSMatthias Ringwald * close TCP socket connection to BTdaemon 912531c97eSMatthias Ringwald */ 922531c97eSMatthias Ringwald int socket_connection_close_tcp(connection_t *connection); 932531c97eSMatthias Ringwald 942531c97eSMatthias Ringwald /** 952531c97eSMatthias Ringwald * create unix socket connection to BTdaemon 962531c97eSMatthias Ringwald */ 972531c97eSMatthias Ringwald connection_t * socket_connection_open_unix(void); 982531c97eSMatthias Ringwald 992531c97eSMatthias Ringwald /** 1002531c97eSMatthias Ringwald * close unix connection to BTdaemon 1012531c97eSMatthias Ringwald */ 1022531c97eSMatthias Ringwald int socket_connection_close_unix(connection_t *connection); 1032531c97eSMatthias Ringwald 1042531c97eSMatthias Ringwald /** 1052531c97eSMatthias Ringwald * set packet handler for all auto-accepted connections 1062531c97eSMatthias Ringwald * -- packet_callback @return: 0 == OK/NO ERROR 1072531c97eSMatthias Ringwald */ 1082531c97eSMatthias Ringwald void socket_connection_register_packet_callback( int (*packet_callback)(connection_t *connection, uint16_t packet_type, uint16_t channel, uint8_t *data, uint16_t length) ); 1092531c97eSMatthias Ringwald 1102531c97eSMatthias Ringwald /** 1112531c97eSMatthias Ringwald * send HCI packet to single connection 1122531c97eSMatthias Ringwald */ 1132531c97eSMatthias Ringwald void socket_connection_send_packet(connection_t *connection, uint16_t packet_type, uint16_t channel, uint8_t *data, uint16_t size); 1142531c97eSMatthias Ringwald 1152531c97eSMatthias Ringwald /** 1162531c97eSMatthias Ringwald * send event data to all clients 1172531c97eSMatthias Ringwald */ 1182531c97eSMatthias Ringwald void socket_connection_send_packet_all(uint16_t type, uint16_t channel, uint8_t *packet, uint16_t size); 1192531c97eSMatthias Ringwald 1202531c97eSMatthias Ringwald /** 1212531c97eSMatthias Ringwald * try to dispatch packet for all "parked" connections. 1222531c97eSMatthias Ringwald * if dispatch is successful, a connection is added again to run loop 1232531c97eSMatthias Ringwald */ 1242531c97eSMatthias Ringwald void socket_connection_retry_parked(void); 1252531c97eSMatthias Ringwald 1262531c97eSMatthias Ringwald 1272531c97eSMatthias Ringwald /** 1282531c97eSMatthias Ringwald * query if at least one connection had to be parked 1292531c97eSMatthias Ringwald */ 1302531c97eSMatthias Ringwald int socket_connection_has_parked_connections(void); 1312531c97eSMatthias Ringwald 1322531c97eSMatthias Ringwald #if defined __cplusplus 1332531c97eSMatthias Ringwald } 1342531c97eSMatthias Ringwald #endif 1352531c97eSMatthias Ringwald 13680e33422SMatthias Ringwald #endif // SOCKET_CONNECTION_H 137