void sink_write(Sink sink, const char *buf, int size) { int offset = SinkClaim(sink, size); uint8 *dest = SinkMap(sink); memcpy(dest + offset, buf, size); SinkFlush(sink, size); }
bool swatSendData(remoteDevice *device, uint8 *data, uint16 len) { uint8 * sink_ptr; /* Ptr to the first byte in the sink */ uint16 claim_result; /* Result from the sink claim */ /* Get the signalling data from the Sink */ claim_result = SinkClaim(device->signalling_sink, len); if (claim_result == 0xffff) { SWAT_DEBUG(("[SWAT] swatSendData failed claim\n")); return FALSE; } else { sink_ptr = SinkMap(device->signalling_sink); if (sink_ptr) { sink_ptr += claim_result; /* Point to the claimed data area of the sink */ memmove(sink_ptr, data, len); /* Copy data to the sink */ return(SinkFlush(device->signalling_sink, len)); /* Send the data */ } else { SWAT_DEBUG(("[SWAT] swatSendData failed ptr\n")); return FALSE; } } }
void ConnectionSendSinkDataTestExtra(Sink sink, uint16 size_data, uint8* data) { uint8* s=SinkMap(sink); uint16 o=SinkClaim(sink,size_data); memmove(s+o, data, size_data); SinkFlush(sink, size_data); }
void A2dpSendMediaPacketTestExtra(uint16 device_id, uint16 stream_id) { static const uint8 pkt[] = { 0x80, 0x01, 0x50, 0xcf, 0xcb, 0xd7, 0xd0, 0x20, 0xfa, 0x84, 0xea, 0x9b, 0x05, 0x9c, 0xbd, 0x3b, 0xff, 0xfc, 0xca, 0x88, 0x78, 0x33, 0x98, 0x86, 0x85, 0x66, 0x7f, 0xbe, 0xee, 0xdd }; Sink media_sink = A2dpMediaGetSink( device_id, stream_id ); uint8 *dest = SinkMap(media_sink) + SinkClaim(media_sink, sizeof(pkt)); memmove(dest, pkt, sizeof(pkt)); SinkFlush(media_sink, sizeof(pkt)); }
bool uart_write(const char * buffer, uint16 size) { Sink sink = StreamUartSink(); uint16 offset = SinkClaim(sink, size); uint8 * address; if (offset == 0xffff) return FALSE; address = SinkMap(sink); memcpy(address + offset, buffer, size); return SinkFlush(sink, size); }
void ConnectionSendSinkAutoDataTestExtra(Sink sink, uint16 size_data) { uint8* s=SinkMap(sink); uint16 o; printf("Data to send of size %d",size_data); o= SinkClaim(sink,size_data); if (0xFFFF == o) { printf("Failed to Claim Sink for Data size %d",size_data); return; } /* Memset with the same value */ memset(s+o, 0x31, size_data); printf("Sending Data of size %d",size_data); SinkFlush(sink, size_data); }
avrcp_status_code avrcpAvctpSendMessage( AVRCP *avrcp, uint8 cr_type, uint8 *ptr, uint16 hdr_size, uint16 data_len, Source data) { uint8 avctp_pkt_type = AVCTP0_PACKET_TYPE_SINGLE; uint8 i, start_head; uint8 no_complete_packets=0; uint16 msg_len=data_len; uint16 pkt_size = hdr_size+data_len+AVCTP_SINGLE_PKT_HEADER_SIZE; avrcp_status_code result = avrcp_success; Sink sink=avrcp->sink; /* * Check the packet size is greater than L2CAP MTU Size. Fragmentation is * required for AVCTP packets greater than MTU Size */ if(pkt_size > avrcp->l2cap_mtu) { avctp_pkt_type = AVCTP0_PACKET_TYPE_START; } if(avctp_pkt_type == AVCTP0_PACKET_TYPE_START) { msg_len = avrcp->l2cap_mtu - (hdr_size + AVCTP_START_PKT_HEADER_SIZE); /* Calculate the Number of complete_packets.*/ no_complete_packets = ((data_len - msg_len ) / (avrcp->l2cap_mtu - AVCTP_CONT_PKT_HEADER_SIZE)) +1; /* If there is a reminder of bytes add 1 more */ if((data_len - msg_len ) % (avrcp->l2cap_mtu - AVCTP_CONT_PKT_HEADER_SIZE)) no_complete_packets++; /* Packet size */ pkt_size = avrcp->l2cap_mtu ; /* Fill no_complete_packets */ ptr[AVCTP_NUM_PKT_OFFSET] = no_complete_packets; } /* Fill the AVCTP Header */ if(cr_type == AVCTP0_CR_COMMAND) { avrcpAvctpSetCmdHeader( avrcp, &ptr[AVCTP_HEADER_START_OFFSET], avctp_pkt_type, no_complete_packets); } else { /* Frame the header */ ptr[AVCTP_HEADER_START_OFFSET] = (ptr[AVCTP_HEADER_START_OFFSET] & AVCTP_TRANSACTION_MASK) | avctp_pkt_type | AVCTP0_CR_RESPONSE; /* Set Bad Profile if there is no AVRCP header to follow */ if(!hdr_size) { ptr[AVCTP_HEADER_START_OFFSET] |= AVCTP0_IPID; } } /* Store first octet for future */ start_head = ptr[AVCTP_HEADER_START_OFFSET]; /* Before calling this function , Sink Space must be checked for * first message If StreamMove() fails, Target may not get the * entire data and it may drop */ if(msg_len) { StreamMove(sink, data, msg_len); /* Reduce the data length */ data_len -= msg_len; } /* Send the data */ (void)SinkFlush(sink, pkt_size); /* Send the Rest of AVCTP Fragments. Start with 2 since we already sent 1 */ for (i = 2 ; i <= no_complete_packets; i++) { if(!(ptr= avrcpGrabSink(sink, AVCTP_CONT_PKT_HEADER_SIZE))) { result = avrcp_no_resource; break; } if(i < no_complete_packets) { AVCTP_SET_CONT_PKT_HEADER(ptr[AVCTP_HEADER_START_OFFSET], start_head); msg_len = avrcp->l2cap_mtu - AVCTP_CONT_PKT_HEADER_SIZE; } else { AVCTP_SET_END_PKT_HEADER(ptr[AVCTP_HEADER_START_OFFSET],start_head); msg_len = data_len; pkt_size = msg_len + AVCTP_END_PKT_HEADER_SIZE; } /* Copy the data to Sink. Sink Space must be validated before calling this function.*/ StreamMove(sink, data , msg_len); /* Send the data */ (void)SinkFlush(sink, pkt_size); data_len -= msg_len; } /* If Still Data to send in Source. Drop that much data */ if (data_len) { SourceDrop(data,data_len); } return result; }
void Fat16_Read(MassStorageType *ms, uint32 logical_address, uint32 transfer_length) { uint32 end_address = logical_address + transfer_length - 1; Sink sink_bulk_out = StreamUsbEndPointSink(end_point_bulk_out); MS_DEBUG(("FAT16: Read log addr: %ld end addr: %ld\n", logical_address, end_address)); if (!ms->info_read) { /* information read once from read-only file system */ uint32 fat_number_sectors; uint32 root_number_sectors; uint32 data_number_sectors; /* FAT size calculations */ fat_number_sectors = ms->file_info[FILE_INFO_FAT].size / BYTES_PER_SECTOR + 1; if ((ms->file_info[FILE_INFO_FAT].size % BYTES_PER_SECTOR) == 0) { fat_number_sectors--; } ms->file_info[FILE_INFO_FAT].end_sector = FAT1_SECTOR + fat_number_sectors - 1; /* Root dir size calculations */ root_number_sectors = ms->file_info[FILE_INFO_ROOT_DIR].size / BYTES_PER_SECTOR + 1; if ((ms->file_info[FILE_INFO_ROOT_DIR].size % BYTES_PER_SECTOR) == 0) { root_number_sectors--; } ms->file_info[FILE_INFO_ROOT_DIR].end_sector = ROOT_SECTOR + root_number_sectors - 1; /* Data area size calculations */ data_number_sectors = ms->file_info[FILE_INFO_DATA].size / BYTES_PER_SECTOR + 1; if ((ms->file_info[FILE_INFO_DATA].size % BYTES_PER_SECTOR) == 0) { data_number_sectors--; } ms->file_info[FILE_INFO_DATA].end_sector = DATA_SECTOR + data_number_sectors - 1; /* don't read this information again to speed things up */ ms->info_read = TRUE; } while (logical_address <= end_address) { MS_DEBUG(("FAT16: log addr: %ld\n", logical_address)); if (logical_address == MBR_SECTOR) /* Master Boot Record */ { uint8 *buffer = 0; /* wait for free space in Sink */ Fat16_WaitAvailable(sink_bulk_out, BYTES_PER_SECTOR); if ((buffer = claimSink(sink_bulk_out, BYTES_PER_SECTOR)) != 0) { uint16 offset = 0; uint16 size_data = sizeof(MasterBootRecordExeType); memmove(buffer, &mbr_exe, size_data); offset += size_data; size_data = sizeof(MasterBootRecordPartitionType); memmove(buffer + offset, &mbr_partition, size_data); offset += size_data; memset(buffer + offset, 0, size_data * 3); size_data = sizeof(ExeSignatureType); memmove(buffer + BYTES_PER_SECTOR - size_data, &exe_signature, size_data); SinkConfigure(sink_bulk_out, VM_SINK_USB_TRANSFER_LENGTH, BYTES_PER_SECTOR); SinkFlush(sink_bulk_out, BYTES_PER_SECTOR); MS_DEBUG(("FAT16: MBR returned data\n")); } logical_address++; } else if (logical_address == BOOT_SECTOR) /* Boot Sector */ { uint8 *buffer = 0; /* wait for free space in Sink */ Fat16_WaitAvailable(sink_bulk_out, BYTES_PER_SECTOR); if ((buffer = claimSink(sink_bulk_out, BYTES_PER_SECTOR)) != 0) { uint16 offset = 0; uint16 size_data = sizeof(BootSectorType); memmove(buffer, &boot_sector, size_data); offset += size_data; size_data = sizeof(BootSectorExeType); memmove(buffer + offset, &boot_exe, size_data); offset += size_data; size_data = sizeof(ExeSignatureType); memmove(buffer + offset, &exe_signature, size_data); SinkConfigure(sink_bulk_out, VM_SINK_USB_TRANSFER_LENGTH, BYTES_PER_SECTOR); SinkFlush(sink_bulk_out, BYTES_PER_SECTOR); MS_DEBUG(("FAT16: BOOT returned data\n")); } logical_address++; } else if ((logical_address >= FAT1_SECTOR) && (logical_address <= ms->file_info[FILE_INFO_FAT].end_sector)) /* FAT 1 */ { MS_DEBUG(("FAT16: FAT1 sector\n")); logical_address = read_sectors(&ms->file_info[FILE_INFO_FAT], logical_address, end_address - logical_address + 1, FAT1_SECTOR); } else if ((logical_address >= FAT2_SECTOR) && (logical_address <= (ms->file_info[FILE_INFO_FAT].end_sector + SECTORS_PER_FAT))) /* FAT 2 */ { MS_DEBUG(("FAT16: FAT2 sector\n")); logical_address = read_sectors(&ms->file_info[FILE_INFO_FAT], logical_address, end_address - logical_address + 1, FAT2_SECTOR); } else if ((logical_address >= ROOT_SECTOR) && (logical_address <= ms->file_info[FILE_INFO_ROOT_DIR].end_sector)) /* Root Directory */ { MS_DEBUG(("FAT16: root sector\n")); logical_address = read_sectors(&ms->file_info[FILE_INFO_ROOT_DIR], logical_address, end_address - logical_address + 1, ROOT_SECTOR); } else if ((logical_address >= DATA_SECTOR) && (logical_address <= ms->file_info[FILE_INFO_DATA].end_sector)) /* Data Area */ { MS_DEBUG(("FAT16: data sector\n")); logical_address = read_sectors(&ms->file_info[FILE_INFO_DATA], logical_address, end_address - logical_address + 1, DATA_SECTOR); } else /* sector with no data */ { uint8 *buffer = 0; /* wait for free space in Sink */ Fat16_WaitAvailable(sink_bulk_out, BYTES_PER_SECTOR); if ((buffer = claimSink(sink_bulk_out, BYTES_PER_SECTOR)) != 0) { memset(buffer, 0, BYTES_PER_SECTOR); SinkConfigure(sink_bulk_out, VM_SINK_USB_TRANSFER_LENGTH, BYTES_PER_SECTOR); SinkFlush(sink_bulk_out, BYTES_PER_SECTOR); MS_DEBUG(("FAT16: empty sector\n")); } logical_address++; } } }
static uint32 read_sectors(FileInfoType *file_info, uint32 logical_address, uint32 transfer_length, uint32 area_start_sector) { uint32 start_sector; uint32 end_sector; uint32 file_end_sector = file_info->end_sector; uint16 i = 0; Sink sink = StreamUsbEndPointSink(end_point_bulk_out); /* correct end sector for FAT2, as it's otherwise treated as FAT1 */ if (area_start_sector == FAT2_SECTOR) file_end_sector += SECTORS_PER_FAT; /* find the start sector and end sector for this type of data */ start_sector = logical_address - area_start_sector; end_sector = start_sector + transfer_length - 1; if (end_sector > (file_end_sector - area_start_sector)) end_sector = file_end_sector - area_start_sector; MS_DEBUG(("FAT16: start %ld end %ld fileend %ld log %ld areastart %ld\n",start_sector,end_sector,file_info->end_sector,logical_address,area_start_sector)); /* check to see if the file read should begin at the start of the file */ if ((file_info->src == 0) || (start_sector < file_info->current_start_sector)) { if (file_info->params) file_info->src = StreamRegionSource(file_info->params, file_info->size); else file_info->src = StreamFileSource(file_info->index); file_info->current_start_sector = 0; MS_DEBUG(("FAT16: new file\n")); } /* seek through the file until the correct sector is reached */ while ((start_sector > file_info->current_start_sector) && (file_info->current_start_sector < end_sector)) { SourceDrop(file_info->src, BYTES_PER_SECTOR); file_info->current_start_sector++; MS_DEBUG(("FAT16: src drop %ld\n",file_info->current_start_sector)); } /* send the data in the sectors from start_sector to end_sector */ while (i <= (end_sector - start_sector)) { uint8 *buffer = 0; uint16 sink_slack = 0; uint16 source_size; uint16 blocks_in_sink; uint16 blocks_in_source; uint16 blocks_to_read; uint32 bytes_to_read; uint32 remaining_bytes; uint16 bytes_to_copy = 0; /* wait for free space in Sink */ Fat16_WaitAvailable(sink, BYTES_PER_SECTOR); sink_slack = SinkSlack(sink); source_size = SourceSize(file_info->src); blocks_in_sink = sink_slack / BYTES_PER_SECTOR; /* find the maximum sectors that can be sent */ if ((source_size % BYTES_PER_SECTOR) == 0) blocks_in_source = source_size / BYTES_PER_SECTOR; else blocks_in_source = source_size / BYTES_PER_SECTOR + 1; blocks_to_read = blocks_in_sink > blocks_in_source ? blocks_in_source : blocks_in_sink; if (blocks_to_read > (end_sector - i + 1)) blocks_to_read = end_sector - i + 1; bytes_to_read = blocks_to_read * BYTES_PER_SECTOR; remaining_bytes = file_info->size - (file_info->current_start_sector * BYTES_PER_SECTOR); MS_DEBUG(("FAT16: info sink_slack:%d source_size:%d blocks_to_read:%d\n",sink_slack,source_size,blocks_to_read)); if (blocks_to_read == 0) break; if (remaining_bytes < bytes_to_read) bytes_to_copy = remaining_bytes; else bytes_to_copy = bytes_to_read; if ((buffer = claimSink(sink, bytes_to_read)) != 0) { const uint8 *data_ptr = SourceMap(file_info->src); bool flush; if (bytes_to_copy < bytes_to_read) memset(buffer + bytes_to_copy, 0, bytes_to_read - bytes_to_copy); memmove(buffer, data_ptr, bytes_to_copy); SinkConfigure(sink, VM_SINK_USB_TRANSFER_LENGTH, bytes_to_read); flush = SinkFlush(sink, bytes_to_read); SourceDrop(file_info->src, bytes_to_copy); file_info->current_start_sector += blocks_to_read; i += blocks_to_read; MS_DEBUG(("FAT16: send bytes %d pos %ld i %d flush %d\n",bytes_to_copy,file_info->current_start_sector,i,flush)); } else { break; } } /* return the next logical address to process */ return logical_address + end_sector - start_sector + 1; }