l2cap.c (826c39d019dd27e2d6a5ad3875f4d5f322be7113) l2cap.c (3b81f0d3adff30ebdac0ecdbed83e8e161072187)
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

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

290
291static int l2cap_ertm_send_information_frame(l2cap_channel_t * channel, int index, int final){
292 l2cap_ertm_tx_packet_state_t * tx_state = &channel->tx_packets_state[index];
293 hci_reserve_packet_buffer();
294 uint8_t *acl_buffer = hci_get_outgoing_packet_buffer();
295 uint16_t control = l2cap_encanced_control_field_for_information_frame(tx_state->tx_seq, final, channel->req_seq, tx_state->sar);
296 log_info("I-Frame: control 0x%04x", control);
297 little_endian_store_16(acl_buffer, 8, control);
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

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

290
291static int l2cap_ertm_send_information_frame(l2cap_channel_t * channel, int index, int final){
292 l2cap_ertm_tx_packet_state_t * tx_state = &channel->tx_packets_state[index];
293 hci_reserve_packet_buffer();
294 uint8_t *acl_buffer = hci_get_outgoing_packet_buffer();
295 uint16_t control = l2cap_encanced_control_field_for_information_frame(tx_state->tx_seq, final, channel->req_seq, tx_state->sar);
296 log_info("I-Frame: control 0x%04x", control);
297 little_endian_store_16(acl_buffer, 8, control);
298 memcpy(&acl_buffer[8+2], &channel->tx_packets_data[index * channel->local_mtu], tx_state->len);
298 memcpy(&acl_buffer[8+2], &channel->tx_packets_data[index * channel->local_mps], tx_state->len);
299 // (re-)start retransmission timer on
300 l2cap_ertm_start_retransmission_timer(channel);
301 // send
302 return l2cap_send_prepared(channel->local_cid, 2 + tx_state->len);
303}
304
305static void l2cap_ertm_store_fragment(l2cap_channel_t * channel, l2cap_segmentation_and_reassembly_t sar, uint16_t sdu_length, uint8_t * data, uint16_t len){
306 // get next index for storing packets
307 int index = channel->tx_write_index;
308
309 l2cap_ertm_tx_packet_state_t * tx_state = &channel->tx_packets_state[index];
310 tx_state->tx_seq = channel->next_tx_seq;
311 tx_state->len = len;
312 tx_state->sar = sar;
313 tx_state->retry_count = 0;
314
299 // (re-)start retransmission timer on
300 l2cap_ertm_start_retransmission_timer(channel);
301 // send
302 return l2cap_send_prepared(channel->local_cid, 2 + tx_state->len);
303}
304
305static void l2cap_ertm_store_fragment(l2cap_channel_t * channel, l2cap_segmentation_and_reassembly_t sar, uint16_t sdu_length, uint8_t * data, uint16_t len){
306 // get next index for storing packets
307 int index = channel->tx_write_index;
308
309 l2cap_ertm_tx_packet_state_t * tx_state = &channel->tx_packets_state[index];
310 tx_state->tx_seq = channel->next_tx_seq;
311 tx_state->len = len;
312 tx_state->sar = sar;
313 tx_state->retry_count = 0;
314
315 uint8_t * tx_packet = &channel->tx_packets_data[index * channel->local_mtu];
315 uint8_t * tx_packet = &channel->tx_packets_data[index * channel->local_mps];
316 log_info("index %u, mtu %u, packet tx %p", index, channel->local_mtu, tx_packet);
316 int pos = 0;
317 if (sar == L2CAP_SEGMENTATION_AND_REASSEMBLY_START_OF_L2CAP_SDU){
318 little_endian_store_16(tx_packet, 0, sdu_length);
319 pos += 2;
320 }
321 memcpy(&tx_packet[pos], data, len);
322
323 // update

--- 3480 unchanged lines hidden ---
317 int pos = 0;
318 if (sar == L2CAP_SEGMENTATION_AND_REASSEMBLY_START_OF_L2CAP_SDU){
319 little_endian_store_16(tx_packet, 0, sdu_length);
320 pos += 2;
321 }
322 memcpy(&tx_packet[pos], data, len);
323
324 // update

--- 3480 unchanged lines hidden ---