rfcomm.c (8f4649e3ba0a9d21085f42b688929492b3ab33b7) rfcomm.c (9da9850b83fde69f1dc00ad3fb029803b8844b54)
1/*
2 * Copyright (C) 2014 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 239 unchanged lines hidden (view full) ---

248 bd_addr_to_str(channel->multiplexer->remote_addr), channel->dlci>>1, channel->rfcomm_cid);
249 uint8_t event[13];
250 event[0] = RFCOMM_EVENT_INCOMING_CONNECTION;
251 event[1] = sizeof(event) - 2;
252 reverse_bd_addr(channel->multiplexer->remote_addr, &event[2]);
253 event[8] = channel->dlci >> 1;
254 little_endian_store_16(event, 9, channel->rfcomm_cid);
255 little_endian_store_16(event, 11, channel->multiplexer->con_handle);
1/*
2 * Copyright (C) 2014 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 239 unchanged lines hidden (view full) ---

248 bd_addr_to_str(channel->multiplexer->remote_addr), channel->dlci>>1, channel->rfcomm_cid);
249 uint8_t event[13];
250 event[0] = RFCOMM_EVENT_INCOMING_CONNECTION;
251 event[1] = sizeof(event) - 2;
252 reverse_bd_addr(channel->multiplexer->remote_addr, &event[2]);
253 event[8] = channel->dlci >> 1;
254 little_endian_store_16(event, 9, channel->rfcomm_cid);
255 little_endian_store_16(event, 11, channel->multiplexer->con_handle);
256 hci_dump_packet(HCI_EVENT_PACKET, 1, event, sizeof(event));
256 hci_dump_btstack_event( event, sizeof(event));
257 (channel->packet_handler)(HCI_EVENT_PACKET, 0, event, sizeof(event));
258}
259
260// API Change: BTstack-0.3.50x uses
261// data: event(8), len(8), status (8), address (48), server channel(8), rfcomm_cid(16), max frame size(16)
262// next Cydia release will use SVN version of this
263// data: event(8), len(8), status (8), address (48), handle (16), server channel(8), rfcomm_cid(16), max frame size(16)
264static void rfcomm_emit_channel_opened(rfcomm_channel_t *channel, uint8_t status) {

--- 6 unchanged lines hidden (view full) ---

271 event[pos++] = sizeof(event) - 2; // 1
272 event[pos++] = status; // 2
273 reverse_bd_addr(channel->multiplexer->remote_addr, &event[pos]); pos += 6; // 3
274 little_endian_store_16(event, pos, channel->multiplexer->con_handle); pos += 2; // 9
275 event[pos++] = channel->dlci >> 1; // 11
276 little_endian_store_16(event, pos, channel->rfcomm_cid); pos += 2; // 12 - channel ID
277 little_endian_store_16(event, pos, channel->max_frame_size); pos += 2; // max frame size
278 event[pos++] = channel->service ? 1 : 0; // linked to service -> incoming
257 (channel->packet_handler)(HCI_EVENT_PACKET, 0, event, sizeof(event));
258}
259
260// API Change: BTstack-0.3.50x uses
261// data: event(8), len(8), status (8), address (48), server channel(8), rfcomm_cid(16), max frame size(16)
262// next Cydia release will use SVN version of this
263// data: event(8), len(8), status (8), address (48), handle (16), server channel(8), rfcomm_cid(16), max frame size(16)
264static void rfcomm_emit_channel_opened(rfcomm_channel_t *channel, uint8_t status) {

--- 6 unchanged lines hidden (view full) ---

271 event[pos++] = sizeof(event) - 2; // 1
272 event[pos++] = status; // 2
273 reverse_bd_addr(channel->multiplexer->remote_addr, &event[pos]); pos += 6; // 3
274 little_endian_store_16(event, pos, channel->multiplexer->con_handle); pos += 2; // 9
275 event[pos++] = channel->dlci >> 1; // 11
276 little_endian_store_16(event, pos, channel->rfcomm_cid); pos += 2; // 12 - channel ID
277 little_endian_store_16(event, pos, channel->max_frame_size); pos += 2; // max frame size
278 event[pos++] = channel->service ? 1 : 0; // linked to service -> incoming
279 hci_dump_packet(HCI_EVENT_PACKET, 1, event, sizeof(event));
279 hci_dump_btstack_event( event, sizeof(event));
280 (channel->packet_handler)(HCI_EVENT_PACKET, 0, event, pos);
281
282 // if channel opened successfully, also send can send now if possible
283 if (status) return;
284 if (rfcomm_channel_can_send(channel)){
285 rfcomm_emit_can_send_now(channel);
286 }
287}
288
289// data: event(8), len(8), rfcomm_cid(16)
290static void rfcomm_emit_channel_closed(rfcomm_channel_t * channel) {
291 log_info("RFCOMM_EVENT_CHANNEL_CLOSED cid 0x%02x", channel->rfcomm_cid);
292 uint8_t event[4];
293 event[0] = RFCOMM_EVENT_CHANNEL_CLOSED;
294 event[1] = sizeof(event) - 2;
295 little_endian_store_16(event, 2, channel->rfcomm_cid);
280 (channel->packet_handler)(HCI_EVENT_PACKET, 0, event, pos);
281
282 // if channel opened successfully, also send can send now if possible
283 if (status) return;
284 if (rfcomm_channel_can_send(channel)){
285 rfcomm_emit_can_send_now(channel);
286 }
287}
288
289// data: event(8), len(8), rfcomm_cid(16)
290static void rfcomm_emit_channel_closed(rfcomm_channel_t * channel) {
291 log_info("RFCOMM_EVENT_CHANNEL_CLOSED cid 0x%02x", channel->rfcomm_cid);
292 uint8_t event[4];
293 event[0] = RFCOMM_EVENT_CHANNEL_CLOSED;
294 event[1] = sizeof(event) - 2;
295 little_endian_store_16(event, 2, channel->rfcomm_cid);
296 hci_dump_packet(HCI_EVENT_PACKET, 1, event, sizeof(event));
296 hci_dump_btstack_event( event, sizeof(event));
297 (channel->packet_handler)(HCI_EVENT_PACKET, 0, event, sizeof(event));
298}
299
300static void rfcomm_emit_remote_line_status(rfcomm_channel_t *channel, uint8_t line_status){
301 log_info("RFCOMM_EVENT_REMOTE_LINE_STATUS cid 0x%02x c, line status 0x%x", channel->rfcomm_cid, line_status);
302 uint8_t event[5];
303 event[0] = RFCOMM_EVENT_REMOTE_LINE_STATUS;
304 event[1] = sizeof(event) - 2;
305 little_endian_store_16(event, 2, channel->rfcomm_cid);
306 event[4] = line_status;
297 (channel->packet_handler)(HCI_EVENT_PACKET, 0, event, sizeof(event));
298}
299
300static void rfcomm_emit_remote_line_status(rfcomm_channel_t *channel, uint8_t line_status){
301 log_info("RFCOMM_EVENT_REMOTE_LINE_STATUS cid 0x%02x c, line status 0x%x", channel->rfcomm_cid, line_status);
302 uint8_t event[5];
303 event[0] = RFCOMM_EVENT_REMOTE_LINE_STATUS;
304 event[1] = sizeof(event) - 2;
305 little_endian_store_16(event, 2, channel->rfcomm_cid);
306 event[4] = line_status;
307 hci_dump_packet( HCI_EVENT_PACKET, 1, event, sizeof(event));
307 hci_dump_btstack_event( event, sizeof(event));
308 (channel->packet_handler)(HCI_EVENT_PACKET, 0, event, sizeof(event));
309}
310
311static void rfcomm_emit_port_configuration(rfcomm_channel_t *channel, bool remote) {
312 // notify client about new settings
313 uint8_t event[2+2+1+sizeof(rfcomm_rpn_data_t)];
314 event[0] = RFCOMM_EVENT_PORT_CONFIGURATION;
315 event[1] = sizeof(event) - 2;
316 little_endian_store_16(event, 2, channel->rfcomm_cid);
317 if (remote){
318 event[4] = 1;
319 (void)memcpy(&event[5], (uint8_t *) &channel->remote_rpn_data, sizeof(rfcomm_rpn_data_t));
320 } else {
321 event[4] = 0;
322 (void)memcpy(&event[5], (uint8_t *) &channel->local_rpn_data, sizeof(rfcomm_rpn_data_t));
323 }
308 (channel->packet_handler)(HCI_EVENT_PACKET, 0, event, sizeof(event));
309}
310
311static void rfcomm_emit_port_configuration(rfcomm_channel_t *channel, bool remote) {
312 // notify client about new settings
313 uint8_t event[2+2+1+sizeof(rfcomm_rpn_data_t)];
314 event[0] = RFCOMM_EVENT_PORT_CONFIGURATION;
315 event[1] = sizeof(event) - 2;
316 little_endian_store_16(event, 2, channel->rfcomm_cid);
317 if (remote){
318 event[4] = 1;
319 (void)memcpy(&event[5], (uint8_t *) &channel->remote_rpn_data, sizeof(rfcomm_rpn_data_t));
320 } else {
321 event[4] = 0;
322 (void)memcpy(&event[5], (uint8_t *) &channel->local_rpn_data, sizeof(rfcomm_rpn_data_t));
323 }
324 hci_dump_packet( HCI_EVENT_PACKET, 1, event, sizeof(event));
324 hci_dump_btstack_event( event, sizeof(event));
325 (channel->packet_handler)(HCI_EVENT_PACKET, channel->rfcomm_cid, event, sizeof(event));
326}
327
328static void rfcomm_emit_can_send_now(rfcomm_channel_t *channel) {
329 log_debug("RFCOMM_EVENT_CHANNEL_CAN_SEND_NOW local_cid 0x%x", channel->rfcomm_cid);
330 uint8_t event[4];
331 event[0] = RFCOMM_EVENT_CAN_SEND_NOW;
332 event[1] = sizeof(event) - 2;
333 little_endian_store_16(event, 2, channel->rfcomm_cid);
325 (channel->packet_handler)(HCI_EVENT_PACKET, channel->rfcomm_cid, event, sizeof(event));
326}
327
328static void rfcomm_emit_can_send_now(rfcomm_channel_t *channel) {
329 log_debug("RFCOMM_EVENT_CHANNEL_CAN_SEND_NOW local_cid 0x%x", channel->rfcomm_cid);
330 uint8_t event[4];
331 event[0] = RFCOMM_EVENT_CAN_SEND_NOW;
332 event[1] = sizeof(event) - 2;
333 little_endian_store_16(event, 2, channel->rfcomm_cid);
334 hci_dump_packet( HCI_EVENT_PACKET, 1, event, sizeof(event));
334 hci_dump_btstack_event( event, sizeof(event));
335 (channel->packet_handler)(HCI_EVENT_PACKET, channel->rfcomm_cid, event, sizeof(event));
336}
337
338// MARK RFCOMM RPN DATA HELPER
339static void rfcomm_rpn_data_set_defaults(rfcomm_rpn_data_t * rpn_data){
340 rpn_data->baud_rate = RPN_BAUD_9600; /* 9600 bps */
341 rpn_data->flags = 0x03; /* 8-n-1 */
342 rpn_data->flow_control = 0; /* no flow control */

--- 2342 unchanged lines hidden ---
335 (channel->packet_handler)(HCI_EVENT_PACKET, channel->rfcomm_cid, event, sizeof(event));
336}
337
338// MARK RFCOMM RPN DATA HELPER
339static void rfcomm_rpn_data_set_defaults(rfcomm_rpn_data_t * rpn_data){
340 rpn_data->baud_rate = RPN_BAUD_9600; /* 9600 bps */
341 rpn_data->flags = 0x03; /* 8-n-1 */
342 rpn_data->flow_control = 0; /* no flow control */

--- 2342 unchanged lines hidden ---