|
50 | 50 | * Pre-processor Definitions
|
51 | 51 | ****************************************************************************/
|
52 | 52 |
|
53 |
| -#define SIM_BTHCI_RX_FRAMELEN 1024 |
| 53 | +#define SIM_BTHCI_RX_FRAMELEN 2048 |
54 | 54 | #define SIM_BTHCI_WORK_DELAY USEC2TICK(1000)
|
55 | 55 |
|
56 | 56 | /****************************************************************************
|
57 | 57 | * Private Types
|
58 | 58 | ****************************************************************************/
|
59 | 59 |
|
| 60 | +union bt_hdr_u |
| 61 | +{ |
| 62 | + struct bt_hci_cmd_hdr_s cmd; |
| 63 | + struct bt_hci_acl_hdr_s acl; |
| 64 | + struct bt_hci_evt_hdr_s evt; |
| 65 | + struct bt_hci_iso_hdr_s iso; |
| 66 | +}; |
60 | 67 | struct bthcisock_s
|
61 | 68 | {
|
62 | 69 | struct bt_driver_s drv;
|
63 | 70 | int id;
|
64 | 71 | int fd;
|
65 | 72 |
|
| 73 | + uint16_t rxlen; |
| 74 | + uint8_t rxbuf[SIM_BTHCI_RX_FRAMELEN]; |
| 75 | + |
66 | 76 | /* Work queue for transmit */
|
67 | 77 |
|
68 | 78 | struct work_s worker;
|
@@ -124,36 +134,80 @@ static void bthcisock_close(struct bt_driver_s *drv)
|
124 | 134 | static int bthcisock_receive(struct bt_driver_s *drv)
|
125 | 135 | {
|
126 | 136 | struct bthcisock_s *dev = (struct bthcisock_s *)drv;
|
127 |
| - char data[SIM_BTHCI_RX_FRAMELEN]; |
128 | 137 | enum bt_buf_type_e type;
|
| 138 | + union bt_hdr_u *hdr; |
| 139 | + uint16_t pktlen; |
129 | 140 | int ret;
|
130 | 141 |
|
131 |
| - ret = host_bthcisock_receive(dev->fd, data, sizeof(data)); |
| 142 | + ret = host_bthcisock_receive(dev->fd, &dev->rxbuf[dev->rxlen], |
| 143 | + sizeof(dev->rxbuf) - dev->rxlen); |
132 | 144 | if (ret <= 0)
|
133 | 145 | {
|
134 | 146 | return ret;
|
135 | 147 | }
|
136 | 148 |
|
137 |
| - if (data[0] == H4_EVT) |
138 |
| - { |
139 |
| - type = BT_EVT; |
140 |
| - } |
141 |
| - else if (data[0] == H4_ACL) |
142 |
| - { |
143 |
| - type = BT_ACL_IN; |
144 |
| - } |
145 |
| - else if (data[0] == H4_ISO) |
146 |
| - { |
147 |
| - type = BT_ISO_IN; |
148 |
| - } |
149 |
| - else |
| 149 | + dev->rxlen += ret; |
| 150 | + |
| 151 | + while (dev->rxlen) |
150 | 152 | {
|
151 |
| - return -EINVAL; |
| 153 | + hdr = (union bt_hdr_u *)&dev->rxbuf[H4_HEADER_SIZE]; |
| 154 | + switch (dev->rxbuf[0]) |
| 155 | + { |
| 156 | + case H4_EVT: |
| 157 | + { |
| 158 | + if (dev->rxlen < H4_HEADER_SIZE |
| 159 | + + sizeof (struct bt_hci_evt_hdr_s)) |
| 160 | + { |
| 161 | + return ret; |
| 162 | + } |
| 163 | + |
| 164 | + type = BT_EVT; |
| 165 | + pktlen = H4_HEADER_SIZE + sizeof(struct bt_hci_evt_hdr_s) |
| 166 | + + hdr->evt.len; |
| 167 | + } |
| 168 | + break; |
| 169 | + case H4_ACL: |
| 170 | + { |
| 171 | + if (dev->rxlen < H4_HEADER_SIZE |
| 172 | + + sizeof(struct bt_hci_acl_hdr_s)) |
| 173 | + { |
| 174 | + return ret; |
| 175 | + } |
| 176 | + |
| 177 | + type = BT_ACL_IN; |
| 178 | + pktlen = H4_HEADER_SIZE + sizeof(struct bt_hci_acl_hdr_s) |
| 179 | + + hdr->acl.len; |
| 180 | + } |
| 181 | + break; |
| 182 | + case H4_ISO: |
| 183 | + { |
| 184 | + if (dev->rxlen < H4_HEADER_SIZE |
| 185 | + + sizeof(struct bt_hci_iso_hdr_s)) |
| 186 | + { |
| 187 | + return ret; |
| 188 | + } |
| 189 | + |
| 190 | + type = BT_ISO_IN; |
| 191 | + pktlen = H4_HEADER_SIZE + sizeof(struct bt_hci_iso_hdr_s) |
| 192 | + + hdr->iso.len; |
| 193 | + } |
| 194 | + break; |
| 195 | + default: |
| 196 | + return -EINVAL; |
| 197 | + } |
| 198 | + |
| 199 | + if (dev->rxlen < pktlen) |
| 200 | + { |
| 201 | + return ret; |
| 202 | + } |
| 203 | + |
| 204 | + bt_netdev_receive(&dev->drv, type, dev->rxbuf + H4_HEADER_SIZE, |
| 205 | + pktlen - H4_HEADER_SIZE); |
| 206 | + dev->rxlen -= pktlen; |
| 207 | + memmove(dev->rxbuf, dev->rxbuf + pktlen, dev->rxlen); |
152 | 208 | }
|
153 | 209 |
|
154 |
| - return bt_netdev_receive(&dev->drv, type, |
155 |
| - data + H4_HEADER_SIZE, |
156 |
| - ret - H4_HEADER_SIZE); |
| 210 | + return ret; |
157 | 211 | }
|
158 | 212 |
|
159 | 213 | static int bthcisock_open(struct bt_driver_s *drv)
|
|
0 commit comments