static void a2dp_source_setup_media_header(uint8_t * media_packet, int size, int *offset, uint8_t marker, uint16_t sequence_number){ if (size < AVDTP_MEDIA_PAYLOAD_HEADER_SIZE){ log_error("small outgoing buffer"); return; } uint8_t rtp_version = 2; uint8_t padding = 0; uint8_t extension = 0; uint8_t csrc_count = 0; uint8_t payload_type = 0x60; // uint16_t sequence_number = stream_endpoint->sequence_number; uint32_t timestamp = btstack_run_loop_get_time_ms(); uint32_t ssrc = 0x11223344; // rtp header (min size 12B) int pos = 0; // int mtu = l2cap_get_remote_mtu_for_local_cid(stream_endpoint->l2cap_media_cid); media_packet[pos++] = (rtp_version << 6) | (padding << 5) | (extension << 4) | csrc_count; media_packet[pos++] = (marker << 1) | payload_type; big_endian_store_16(media_packet, pos, sequence_number); pos += 2; big_endian_store_32(media_packet, pos, timestamp); pos += 4; big_endian_store_32(media_packet, pos, ssrc); // only used for multicast pos += 4; *offset = pos; }
static uint16_t sdp_client_setup_service_attribute_request(uint8_t * data){ uint16_t offset = 0; transactionID++; // uint8_t SDP_PDU_ID_t.SDP_ServiceSearchRequest; data[offset++] = SDP_ServiceAttributeRequest; // uint16_t transactionID big_endian_store_16(data, offset, transactionID); offset += 2; // param legnth offset += 2; // parameters: // ServiceRecordHandle big_endian_store_32(data, offset, serviceRecordHandle); offset += 4; // MaximumAttributeByteCount - uint16_t 0x0007 - 0xffff -> mtu big_endian_store_16(data, offset, mtu); offset += 2; // AttibuteIDList uint16_t attribute_id_list_len = de_get_len(attribute_id_list); memcpy(data + offset, attribute_id_list, attribute_id_list_len); offset += attribute_id_list_len; // ContinuationState - uint8_t number of cont. bytes N<=16 data[offset++] = continuationStateLen; // - N-bytes previous response from server memcpy(data + offset, continuationState, continuationStateLen); offset += continuationStateLen; // uint16_t paramLength big_endian_store_16(data, 3, offset - 5); return offset; }
void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t len) { if (dump_file < 0) return; // not activated yet #ifdef HAVE_POSIX_FILE_IO // don't grow bigger than max_nr_packets if (dump_format != HCI_DUMP_STDOUT && max_nr_packets > 0){ if (nr_packets >= max_nr_packets){ lseek(dump_file, 0, SEEK_SET); ftruncate(dump_file, 0); nr_packets = 0; } nr_packets++; } // get time struct timeval curr_time; struct tm* ptm; gettimeofday(&curr_time, NULL); time_t curr_time_secs = curr_time.tv_sec; switch (dump_format){ case HCI_DUMP_STDOUT: { /* Obtain the time of day, and convert it to a tm struct. */ ptm = localtime (&curr_time_secs); /* assert localtime was successful */ if (!ptm) break; /* Format the date and time, down to a single second. */ strftime (time_string, sizeof (time_string), "[%Y-%m-%d %H:%M:%S", ptm); /* Compute milliseconds from microseconds. */ uint16_t milliseconds = curr_time.tv_usec / 1000; /* Print the formatted time, in seconds, followed by a decimal point and the milliseconds. */ printf ("%s.%03u] ", time_string, milliseconds); printf_packet(packet_type, in, packet, len); break; } case HCI_DUMP_BLUEZ: little_endian_store_16( header_bluez, 0, 1 + len); header_bluez[2] = in; header_bluez[3] = 0; little_endian_store_32( header_bluez, 4, (uint32_t) curr_time.tv_sec); little_endian_store_32( header_bluez, 8, curr_time.tv_usec); header_bluez[12] = packet_type; write (dump_file, header_bluez, HCIDUMP_HDR_SIZE); write (dump_file, packet, len ); break; case HCI_DUMP_PACKETLOGGER: big_endian_store_32( header_packetlogger, 0, PKTLOG_HDR_SIZE - 4 + len); big_endian_store_32( header_packetlogger, 4, (uint32_t) curr_time.tv_sec); big_endian_store_32( header_packetlogger, 8, curr_time.tv_usec); switch (packet_type){ case HCI_COMMAND_DATA_PACKET: header_packetlogger[12] = 0x00; break; case HCI_ACL_DATA_PACKET: if (in) { header_packetlogger[12] = 0x03; } else { header_packetlogger[12] = 0x02; } break; case HCI_SCO_DATA_PACKET: if (in) { header_packetlogger[12] = 0x09; } else { header_packetlogger[12] = 0x08; } break; case HCI_EVENT_PACKET: header_packetlogger[12] = 0x01; break; case LOG_MESSAGE_PACKET: header_packetlogger[12] = 0xfc; break; default: return; } write (dump_file, &header_packetlogger, PKTLOG_HDR_SIZE); write (dump_file, packet, len ); break; default: break; } #else // #ifdef HAVE_EMBEDDED_TICK // uint32_t time_ms = btstack_run_loop_embedded_get_time_ms(); // printf("[%06u] ", time_ms); // #endif printf_packet(packet_type, in, packet, len); #endif }