うおーるぼっとをWiiリモコンでコントロールする新しいプログラムです。 以前のものより、Wiiリモコンが早く繋がる様になりました。 It is a program which controls A with the Wii remote. ※ A Bluetooth dongle and a Wii remote control are needed.
Dependencies: USBHost mbed FATFileSystem mbed-rtos
btstack/l2cap.h@0:fccb789424fc, 2013-06-10 (annotated)
- Committer:
- jksoft
- Date:
- Mon Jun 10 16:01:50 2013 +0000
- Revision:
- 0:fccb789424fc
1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:fccb789424fc | 1 | /* |
jksoft | 0:fccb789424fc | 2 | * Copyright (C) 2009-2012 by Matthias Ringwald |
jksoft | 0:fccb789424fc | 3 | * |
jksoft | 0:fccb789424fc | 4 | * Redistribution and use in source and binary forms, with or without |
jksoft | 0:fccb789424fc | 5 | * modification, are permitted provided that the following conditions |
jksoft | 0:fccb789424fc | 6 | * are met: |
jksoft | 0:fccb789424fc | 7 | * |
jksoft | 0:fccb789424fc | 8 | * 1. Redistributions of source code must retain the above copyright |
jksoft | 0:fccb789424fc | 9 | * notice, this list of conditions and the following disclaimer. |
jksoft | 0:fccb789424fc | 10 | * 2. Redistributions in binary form must reproduce the above copyright |
jksoft | 0:fccb789424fc | 11 | * notice, this list of conditions and the following disclaimer in the |
jksoft | 0:fccb789424fc | 12 | * documentation and/or other materials provided with the distribution. |
jksoft | 0:fccb789424fc | 13 | * 3. Neither the name of the copyright holders nor the names of |
jksoft | 0:fccb789424fc | 14 | * contributors may be used to endorse or promote products derived |
jksoft | 0:fccb789424fc | 15 | * from this software without specific prior written permission. |
jksoft | 0:fccb789424fc | 16 | * 4. Any redistribution, use, or modification is done solely for |
jksoft | 0:fccb789424fc | 17 | * personal benefit and not for any commercial purpose or for |
jksoft | 0:fccb789424fc | 18 | * monetary gain. |
jksoft | 0:fccb789424fc | 19 | * |
jksoft | 0:fccb789424fc | 20 | * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS |
jksoft | 0:fccb789424fc | 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
jksoft | 0:fccb789424fc | 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
jksoft | 0:fccb789424fc | 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS |
jksoft | 0:fccb789424fc | 24 | * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
jksoft | 0:fccb789424fc | 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
jksoft | 0:fccb789424fc | 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
jksoft | 0:fccb789424fc | 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
jksoft | 0:fccb789424fc | 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
jksoft | 0:fccb789424fc | 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
jksoft | 0:fccb789424fc | 30 | * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
jksoft | 0:fccb789424fc | 31 | * SUCH DAMAGE. |
jksoft | 0:fccb789424fc | 32 | * |
jksoft | 0:fccb789424fc | 33 | * Please inquire about commercial licensing options at btstack@ringwald.ch |
jksoft | 0:fccb789424fc | 34 | * |
jksoft | 0:fccb789424fc | 35 | */ |
jksoft | 0:fccb789424fc | 36 | |
jksoft | 0:fccb789424fc | 37 | /* |
jksoft | 0:fccb789424fc | 38 | * l2cap.h |
jksoft | 0:fccb789424fc | 39 | * |
jksoft | 0:fccb789424fc | 40 | * Logical Link Control and Adaption Protocl (L2CAP) |
jksoft | 0:fccb789424fc | 41 | * |
jksoft | 0:fccb789424fc | 42 | * Created by Matthias Ringwald on 5/16/09. |
jksoft | 0:fccb789424fc | 43 | */ |
jksoft | 0:fccb789424fc | 44 | |
jksoft | 0:fccb789424fc | 45 | #pragma once |
jksoft | 0:fccb789424fc | 46 | |
jksoft | 0:fccb789424fc | 47 | #include "hci.h" |
jksoft | 0:fccb789424fc | 48 | #include "l2cap_signaling.h" |
jksoft | 0:fccb789424fc | 49 | #include <btstack/utils.h> |
jksoft | 0:fccb789424fc | 50 | #include <btstack/btstack.h> |
jksoft | 0:fccb789424fc | 51 | |
jksoft | 0:fccb789424fc | 52 | #if defined __cplusplus |
jksoft | 0:fccb789424fc | 53 | extern "C" { |
jksoft | 0:fccb789424fc | 54 | #endif |
jksoft | 0:fccb789424fc | 55 | |
jksoft | 0:fccb789424fc | 56 | #define L2CAP_SIG_ID_INVALID 0 |
jksoft | 0:fccb789424fc | 57 | |
jksoft | 0:fccb789424fc | 58 | #define L2CAP_HEADER_SIZE 4 |
jksoft | 0:fccb789424fc | 59 | |
jksoft | 0:fccb789424fc | 60 | // size of HCI ACL + L2CAP Header for regular data packets (8) |
jksoft | 0:fccb789424fc | 61 | #define COMPLETE_L2CAP_HEADER (HCI_ACL_HEADER_SIZE + L2CAP_HEADER_SIZE) |
jksoft | 0:fccb789424fc | 62 | |
jksoft | 0:fccb789424fc | 63 | // minimum signaling MTU |
jksoft | 0:fccb789424fc | 64 | #define L2CAP_MINIMAL_MTU 48 |
jksoft | 0:fccb789424fc | 65 | #define L2CAP_DEFAULT_MTU 672 |
jksoft | 0:fccb789424fc | 66 | |
jksoft | 0:fccb789424fc | 67 | // check L2CAP MTU |
jksoft | 0:fccb789424fc | 68 | #if (L2CAP_MINIMAL_MTU + L2CAP_HEADER_SIZE) > HCI_ACL_PAYLOAD_SIZE |
jksoft | 0:fccb789424fc | 69 | #error "HCI_ACL_PAYLOAD_SIZE too small for minimal L2CAP MTU of 48 bytes" |
jksoft | 0:fccb789424fc | 70 | #endif |
jksoft | 0:fccb789424fc | 71 | |
jksoft | 0:fccb789424fc | 72 | // L2CAP Fixed Channel IDs |
jksoft | 0:fccb789424fc | 73 | #define L2CAP_CID_SIGNALING 0x0001 |
jksoft | 0:fccb789424fc | 74 | #define L2CAP_CID_CONNECTIONLESS_CHANNEL 0x0002 |
jksoft | 0:fccb789424fc | 75 | #define L2CAP_CID_ATTRIBUTE_PROTOCOL 0x0004 |
jksoft | 0:fccb789424fc | 76 | #define L2CAP_CID_SIGNALING_LE 0x0005 |
jksoft | 0:fccb789424fc | 77 | #define L2CAP_CID_SECURITY_MANAGER_PROTOCOL 0x0006 |
jksoft | 0:fccb789424fc | 78 | |
jksoft | 0:fccb789424fc | 79 | void l2cap_init(void); |
jksoft | 0:fccb789424fc | 80 | void l2cap_register_packet_handler(void (*handler)(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)); |
jksoft | 0:fccb789424fc | 81 | void l2cap_create_channel_internal(void * connection, btstack_packet_handler_t packet_handler, bd_addr_t address, uint16_t psm, uint16_t mtu); |
jksoft | 0:fccb789424fc | 82 | void l2cap_disconnect_internal(uint16_t local_cid, uint8_t reason); |
jksoft | 0:fccb789424fc | 83 | uint16_t l2cap_get_remote_mtu_for_local_cid(uint16_t local_cid); |
jksoft | 0:fccb789424fc | 84 | uint16_t l2cap_max_mtu(void); |
jksoft | 0:fccb789424fc | 85 | |
jksoft | 0:fccb789424fc | 86 | void l2cap_block_new_credits(uint8_t blocked); |
jksoft | 0:fccb789424fc | 87 | int l2cap_can_send_packet_now(uint16_t local_cid); // non-blocking UART write |
jksoft | 0:fccb789424fc | 88 | |
jksoft | 0:fccb789424fc | 89 | // get outgoing buffer and prepare data |
jksoft | 0:fccb789424fc | 90 | uint8_t *l2cap_get_outgoing_buffer(void); |
jksoft | 0:fccb789424fc | 91 | |
jksoft | 0:fccb789424fc | 92 | int l2cap_send_prepared(uint16_t local_cid, uint16_t len); |
jksoft | 0:fccb789424fc | 93 | int l2cap_send_internal(uint16_t local_cid, uint8_t *data, uint16_t len); |
jksoft | 0:fccb789424fc | 94 | |
jksoft | 0:fccb789424fc | 95 | int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t len); |
jksoft | 0:fccb789424fc | 96 | int l2cap_send_connectionless(uint16_t handle, uint16_t cid, uint8_t *data, uint16_t len); |
jksoft | 0:fccb789424fc | 97 | |
jksoft | 0:fccb789424fc | 98 | void l2cap_close_connection(void *connection); |
jksoft | 0:fccb789424fc | 99 | |
jksoft | 0:fccb789424fc | 100 | void l2cap_register_service_internal(void *connection, btstack_packet_handler_t packet_handler, uint16_t psm, uint16_t mtu); |
jksoft | 0:fccb789424fc | 101 | void l2cap_unregister_service_internal(void *connection, uint16_t psm); |
jksoft | 0:fccb789424fc | 102 | |
jksoft | 0:fccb789424fc | 103 | void l2cap_accept_connection_internal(uint16_t local_cid); |
jksoft | 0:fccb789424fc | 104 | void l2cap_decline_connection_internal(uint16_t local_cid, uint8_t reason); |
jksoft | 0:fccb789424fc | 105 | |
jksoft | 0:fccb789424fc | 106 | // Bluetooth 4.0 - allows to register handler for Attribute Protocol and Security Manager Protocol |
jksoft | 0:fccb789424fc | 107 | void l2cap_register_fixed_channel(btstack_packet_handler_t packet_handler, uint16_t channel_id); |
jksoft | 0:fccb789424fc | 108 | |
jksoft | 0:fccb789424fc | 109 | |
jksoft | 0:fccb789424fc | 110 | // private structs |
jksoft | 0:fccb789424fc | 111 | typedef enum { |
jksoft | 0:fccb789424fc | 112 | L2CAP_STATE_CLOSED = 1, // no baseband |
jksoft | 0:fccb789424fc | 113 | L2CAP_STATE_WILL_SEND_CREATE_CONNECTION, |
jksoft | 0:fccb789424fc | 114 | L2CAP_STATE_WAIT_CONNECTION_COMPLETE, |
jksoft | 0:fccb789424fc | 115 | L2CAP_STATE_WAIT_CLIENT_ACCEPT_OR_REJECT, |
jksoft | 0:fccb789424fc | 116 | L2CAP_STATE_WAIT_CONNECT_RSP, // from peer |
jksoft | 0:fccb789424fc | 117 | L2CAP_STATE_CONFIG, |
jksoft | 0:fccb789424fc | 118 | L2CAP_STATE_OPEN, |
jksoft | 0:fccb789424fc | 119 | L2CAP_STATE_WAIT_DISCONNECT, // from application |
jksoft | 0:fccb789424fc | 120 | L2CAP_STATE_WILL_SEND_CONNECTION_REQUEST, |
jksoft | 0:fccb789424fc | 121 | L2CAP_STATE_WILL_SEND_CONNECTION_RESPONSE_DECLINE, |
jksoft | 0:fccb789424fc | 122 | L2CAP_STATE_WILL_SEND_CONNECTION_RESPONSE_ACCEPT, |
jksoft | 0:fccb789424fc | 123 | L2CAP_STATE_WILL_SEND_DISCONNECT_REQUEST, |
jksoft | 0:fccb789424fc | 124 | L2CAP_STATE_WILL_SEND_DISCONNECT_RESPONSE, |
jksoft | 0:fccb789424fc | 125 | } L2CAP_STATE; |
jksoft | 0:fccb789424fc | 126 | |
jksoft | 0:fccb789424fc | 127 | typedef enum { |
jksoft | 0:fccb789424fc | 128 | L2CAP_CHANNEL_STATE_VAR_NONE = 0, |
jksoft | 0:fccb789424fc | 129 | L2CAP_CHANNEL_STATE_VAR_RCVD_CONF_REQ = 1 << 0, |
jksoft | 0:fccb789424fc | 130 | L2CAP_CHANNEL_STATE_VAR_RCVD_CONF_RSP = 1 << 1, |
jksoft | 0:fccb789424fc | 131 | L2CAP_CHANNEL_STATE_VAR_SEND_CONF_REQ = 1 << 2, |
jksoft | 0:fccb789424fc | 132 | L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP = 1 << 3, |
jksoft | 0:fccb789424fc | 133 | L2CAP_CHANNEL_STATE_VAR_SENT_CONF_REQ = 1 << 4, |
jksoft | 0:fccb789424fc | 134 | L2CAP_CHANNEL_STATE_VAR_SENT_CONF_RSP = 1 << 5, |
jksoft | 0:fccb789424fc | 135 | } L2CAP_CHANNEL_STATE_VAR; |
jksoft | 0:fccb789424fc | 136 | |
jksoft | 0:fccb789424fc | 137 | // info regarding an actual coneection |
jksoft | 0:fccb789424fc | 138 | typedef struct { |
jksoft | 0:fccb789424fc | 139 | // linked list - assert: first field |
jksoft | 0:fccb789424fc | 140 | linked_item_t item; |
jksoft | 0:fccb789424fc | 141 | |
jksoft | 0:fccb789424fc | 142 | L2CAP_STATE state; |
jksoft | 0:fccb789424fc | 143 | L2CAP_CHANNEL_STATE_VAR state_var; |
jksoft | 0:fccb789424fc | 144 | |
jksoft | 0:fccb789424fc | 145 | bd_addr_t address; |
jksoft | 0:fccb789424fc | 146 | hci_con_handle_t handle; |
jksoft | 0:fccb789424fc | 147 | |
jksoft | 0:fccb789424fc | 148 | uint8_t remote_sig_id; // used by other side, needed for delayed response |
jksoft | 0:fccb789424fc | 149 | uint8_t local_sig_id; // own signaling identifier |
jksoft | 0:fccb789424fc | 150 | |
jksoft | 0:fccb789424fc | 151 | uint16_t local_cid; |
jksoft | 0:fccb789424fc | 152 | uint16_t remote_cid; |
jksoft | 0:fccb789424fc | 153 | |
jksoft | 0:fccb789424fc | 154 | uint16_t local_mtu; |
jksoft | 0:fccb789424fc | 155 | uint16_t remote_mtu; |
jksoft | 0:fccb789424fc | 156 | |
jksoft | 0:fccb789424fc | 157 | uint16_t psm; |
jksoft | 0:fccb789424fc | 158 | |
jksoft | 0:fccb789424fc | 159 | uint8_t packets_granted; // number of L2CAP/ACL packets client is allowed to send |
jksoft | 0:fccb789424fc | 160 | |
jksoft | 0:fccb789424fc | 161 | uint8_t reason; // used in decline internal |
jksoft | 0:fccb789424fc | 162 | |
jksoft | 0:fccb789424fc | 163 | // client connection |
jksoft | 0:fccb789424fc | 164 | void * connection; |
jksoft | 0:fccb789424fc | 165 | |
jksoft | 0:fccb789424fc | 166 | // internal connection |
jksoft | 0:fccb789424fc | 167 | btstack_packet_handler_t packet_handler; |
jksoft | 0:fccb789424fc | 168 | |
jksoft | 0:fccb789424fc | 169 | } l2cap_channel_t; |
jksoft | 0:fccb789424fc | 170 | |
jksoft | 0:fccb789424fc | 171 | // info regarding potential connections |
jksoft | 0:fccb789424fc | 172 | typedef struct { |
jksoft | 0:fccb789424fc | 173 | // linked list - assert: first field |
jksoft | 0:fccb789424fc | 174 | linked_item_t item; |
jksoft | 0:fccb789424fc | 175 | |
jksoft | 0:fccb789424fc | 176 | // service id |
jksoft | 0:fccb789424fc | 177 | uint16_t psm; |
jksoft | 0:fccb789424fc | 178 | |
jksoft | 0:fccb789424fc | 179 | // incoming MTU |
jksoft | 0:fccb789424fc | 180 | uint16_t mtu; |
jksoft | 0:fccb789424fc | 181 | |
jksoft | 0:fccb789424fc | 182 | // client connection |
jksoft | 0:fccb789424fc | 183 | void *connection; |
jksoft | 0:fccb789424fc | 184 | |
jksoft | 0:fccb789424fc | 185 | // internal connection |
jksoft | 0:fccb789424fc | 186 | btstack_packet_handler_t packet_handler; |
jksoft | 0:fccb789424fc | 187 | |
jksoft | 0:fccb789424fc | 188 | } l2cap_service_t; |
jksoft | 0:fccb789424fc | 189 | |
jksoft | 0:fccb789424fc | 190 | |
jksoft | 0:fccb789424fc | 191 | typedef struct l2cap_signaling_response { |
jksoft | 0:fccb789424fc | 192 | hci_con_handle_t handle; |
jksoft | 0:fccb789424fc | 193 | uint8_t sig_id; |
jksoft | 0:fccb789424fc | 194 | uint8_t code; |
jksoft | 0:fccb789424fc | 195 | uint16_t data; // infoType for INFORMATION REQUEST, result for CONNECTION request |
jksoft | 0:fccb789424fc | 196 | } l2cap_signaling_response_t; |
jksoft | 0:fccb789424fc | 197 | |
jksoft | 0:fccb789424fc | 198 | |
jksoft | 0:fccb789424fc | 199 | #if defined __cplusplus |
jksoft | 0:fccb789424fc | 200 | } |
jksoft | 0:fccb789424fc | 201 | #endif |