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); }
static uint8 *claimSink(Sink sink, uint16 size) { uint8 *dest = SinkMap(sink); uint16 claim_result = SinkClaim(sink, size); if (claim_result == 0xffff) { return 0; } return (dest + claim_result); }
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); }
/* Check which AT cmd was waiting for this response */ static void atCmdAckReceived(hfp_link_data* link, hfp_lib_status status) { Sink sink = hfpGetLinkSink(link); MessageId cfm_id = HFP_NO_CFM; /* Cancel the AT response timeout message */ (void) MessageCancelAll(&theHfp->task, hfpGetLinkTimeoutMessage(link, HFP_INTERNAL_WAIT_AT_TIMEOUT_LINK_0_IND)); /* Which message was waiting for this? */ switch (link->at_cmd_resp_pending) { case hfpCmdPending: /* This is a cmd which we don't particularly care about, as long as we get the ack */ break; case hfpBrsfCmdPending: /* Have received response to AT+BRSF */ hfpHandleBrsfAtAck(link, status); break; case hfpBacCmdPending: /* Have received response to AT+BAC */ hfpHandleBacAtAck(link, status); break; case hfpCindTestCmdPending: /* Have received response to AT+CIND=? */ hfpHandleCindTestAtAck(link, status); break; case hfpCindReadCmdPending: /* Have received response to AT+CIND? */ hfpHandleCindReadAtAck(link, status); break; case hfpCmerCmdPending: /* Have received response to AT+CMER */ hfpHandleCmerAtAck(link, status); break; case hfpChldStatusCmdPending: /* Have received response to AT+CHLD=? */ (void)hfpSlcCheckAtAck(link, status); break; case hfpBccCmdPending: /* Have received a response to AT+BCC */ hfpHandleBccAtAck(link, status); break; case hfpBcsCmdPending: /* Have received a response to AT+BCS */ hfpHandleBcsAtAck(link, status); break; case hfpBldnCmdPending: /* Have received a response to AT+BLDN */ cfm_id = HFP_DIAL_LAST_NUMBER_CFM; /* This is necessary when dealing with 0.96 AGs */ hfpHandleCallDialComplete(link, status); break; case hfpAtdNumberCmdPending: /* Have received a response to ATD */ cfm_id = HFP_DIAL_NUMBER_CFM; /* This is necessary when dealing with 0.96 AGs */ hfpHandleCallDialComplete(link, status); break; case hfpAtdMemoryCmdPending: /* Have received a response to ATD> */ cfm_id = HFP_DIAL_MEMORY_CFM; /* This is necessary when dealing with 0.96 AGs */ hfpHandleCallDialComplete(link, status); break; case hfpBvraCmdPending: /* Have received a response to AT+BVRA */ cfm_id = HFP_VOICE_RECOGNITION_ENABLE_CFM; /* This is necessary when dealing with 0.96 AGs */ hfpHandleCallDialComplete(link, status); break; case hfpNrecCmdPending: /* Have received a response to AT+NREC */ hfpHandleNrecAtAck(link, status); break; case hfpBiaCmdPending: /* Have received a response to AT+BIA */ hfpHandleBiaAtAck(link, status); break; case hfpCopsFormatCmdPending: /* Have received a response to AT+COPS= */ cfm_id = hfpHandleCopsFormatAtAck(link, status); break; case hfpChldOneCmdPending: /* Have received response to AT+CHLD=1 */ hfpHandleChldAtAck(link, hfp_chld_release_active_accept_other, status); break; case hfpChldThreeCmdPending: /* Have received response to AT+CHLD=3 */ hfpHandleChldAtAck(link, hfp_chld_add_held_to_multiparty, status); break; case hfpBtrhStatusCmdPending: /* Have received a response to AT+BTRH? */ hfpHandleBtrhStatusAtAck(link, status); break; case hfpCsrSfPending: /* Have received a response to AT+CSRSF */ hfpCsrFeaturesHandleCsrSfAtAck(link, status); break; case hfpCsrGetSmsPending: /* Have received a response to AT+CSRGETSMS */ hfpCsrFeaturesHandleGetSmsAtAck(link, status); break; #ifndef HFP_MIN_CFM case hfpClipCmdPending: /* Have received a response to AT+CLIP= */ cfm_id = HFP_CALLER_ID_ENABLE_CFM; break; case hfpAtaCmdPending: /* Have received response to ATA */ cfm_id = HFP_CALL_ANSWER_CFM; break; case hfpChupCmdPending: /* Have received response to AT+CHUP */ cfm_id = hfpHandleChupAtAck(link); break; case hfpCcwaCmdPending: /* Have received response to AT+CCWA */ cfm_id = HFP_CALL_WAITING_ENABLE_CFM; break; case hfpBtrhZeroCmdPending: /* Have received a response to AT+BTRH=0 */ hfpHandleBtrhAtAck(link, hfp_incoming_call_held, status); break; case hfpBtrhOneCmdPending: /* Have received a response to AT+BTRH=1 */ hfpHandleBtrhAtAck(link, hfp_held_call_accepted, status); break; case hfpBtrhTwoCmdPending: /* Have received a response to AT+BTRH=2 */ hfpHandleBtrhAtAck(link, hfp_held_call_rejected, status); break; case hfpChldZeroCmdPending: /* Have received response to AT+CHLD=0 */ hfpHandleChldAtAck(link, hfp_chld_release_held_reject_waiting, status); break; case hfpChldOneIdxCmdPending: /* Have received response to AT+CHLD=1x */ hfpHandleChldAtAck(link, hfp_chld_release_active_accept_other, status); break; case hfpChldTwoCmdPending: /* Have received response to AT+CHLD=2 */ hfpHandleChldAtAck(link, hfp_chld_hold_active_accept_other, status); break; case hfpChldTwoIdxCmdPending: /* Have received response to AT+CHLD=2x */ hfpHandleChldAtAck(link, hfp_chld_hold_active_accept_other, status); break; /* Always need to handle multiparty ack */ case hfpChldFourCmdPending: /* Have received response to AT+CHLD=4 */ hfpHandleChldAtAck(link, hfp_chld_join_calls_and_hang_up, status); break; case hfpCkpdCmdPending: /* Have received a response to AT+CKPD=200 */ cfm_id = HFP_HS_BUTTON_PRESS_CFM; break; case hfpVtsCmdPending: /* Have received a response to AT+VTS */ cfm_id = HFP_DTMF_CFM; break; case hfpCnumCmdPending: /* Have received a response to AT+CNUM */ cfm_id = HFP_SUBSCRIBER_NUMBERS_CFM; break; case hfpClccCmdPending: /* Have received a response to AT+CLCC */ cfm_id = HFP_CURRENT_CALLS_CFM; break; case hfpCopsReqCmdPending: /* Have received a response to AT+COPS? */ cfm_id = HFP_NETWORK_OPERATOR_CFM; break; case hfpBinpCmdPending: /* Have received a response to AT+BINP */ cfm_id = HFP_VOICE_TAG_NUMBER_CFM; break; case hfpAtCmdPending: cfm_id = HFP_AT_CMD_CFM; break; #endif case hfpNoCmdPending: default: /* This should not happen, if we get an ack we should be waiting for it! */ break; } /* Send _CFM message to app if necessary */ if(cfm_id) hfpSendCommonCfmMessageToApp(cfm_id, link, status); /* Reset the flag as we've just received a response */ link->at_cmd_resp_pending = hfpNoCmdPending; PRINT(("\n")); /* Try to send the next AT cmd pending */ hfpSendNextAtCmd(link, SinkClaim(sink, 0), SinkMap(sink)); }
static void handleHidClassRequest(Source source, usb_device_class_type class_type) { static uint8 idle_rate = 0; { Sink sink = StreamSinkFromSource(source); uint16 packet_size; while ((packet_size = SourceBoundary(source)) != 0) { /* Build the respnse. It must contain the original request, so copy from the source header. */ UsbResponse resp; memcpy(&resp.original_request, SourceMapHeader(source), sizeof(UsbRequest)); /* Set the response fields to default values to make the code below simpler */ resp.success = FALSE; resp.data_length = 0; switch (resp.original_request.bRequest) { /* GET_REPORT */ case 0x01: { PRINT(("USB: HID Get_Report src=0x%X wValue=0x%X wIndex=0x%X wLength=0x%X\n", (uint16)source, resp.original_request.wValue, resp.original_request.wIndex, resp.original_request.wLength)); break; } /* GET_IDLE */ case 0x02: { uint8 *out; if ((out = claimSink(sink, 1)) != 0) { PRINT(("USB: HID Get_Idle src=0x%X wValue=0x%X wIndex=0x%X\n", (uint16)source, resp.original_request.wValue, resp.original_request.wIndex)); out[0] = idle_rate; resp.success = TRUE; resp.data_length = 1; } break; } /* SET_REPORT */ case 0x09: { const uint8 *in = SourceMap(source); uint16 size_data = resp.original_request.wLength; uint8 report_id = resp.original_request.wValue & 0xff; PRINT(("USB: HID Set_Report src=0x%X wValue=0x%X wIndex=0x%X wLength=0x%X -> \n", (uint16)source, resp.original_request.wValue, resp.original_request.wIndex, resp.original_request.wLength)); resp.success = TRUE; if (size_data) { if (class_type == USB_DEVICE_CLASS_TYPE_HID_CONSUMER_TRANSPORT_CONTROL) { USB_DEVICE_CLASS_MSG_REPORT_IND_T *message = PanicUnlessMalloc(sizeof(USB_DEVICE_CLASS_MSG_REPORT_IND_T) + size_data); uint16 source_size = SourceSize(source); PRINT((" send report ind source_size[0x%x]\n", source_size)); message->class_type = class_type; message->report_id = report_id; message->size_report = size_data; in = SourceMap(source); if (source_size < message->size_report) { message->size_report = source_size; } memmove(message->report, in, message->size_report); MessageSend(device->app_task, USB_DEVICE_CLASS_MSG_REPORT_IND, message); PRINT((" sent report ind to Task [0x%x]\n", (uint16)device->app_task)); } } break; } /* SET_IDLE */ case 0x0A: { PRINT(("USB: HID Set_Idle src=0x%X wValue=0x%X wIndex=0x%X\n", (uint16)source, resp.original_request.wValue, resp.original_request.wIndex)); idle_rate = resp.original_request.wValue >> 8; resp.success = TRUE; break; } default: { PRINT(("USB: HID req=0x%X src=0x%X wValue=0x%X wIndex=0x%X wLength=0x%X\n", resp.original_request.bRequest, (uint16)source, resp.original_request.wValue, resp.original_request.wIndex, resp.original_request.wLength)); break; } } /* Send response */ if (resp.data_length) { (void)SinkFlushHeader(sink, resp.data_length, (uint16 *)&resp, sizeof(UsbResponse)); } else { /* Sink packets can never be zero-length, so flush a dummy byte */ (void) SinkClaim(sink, 1); (void) SinkFlushHeader(sink, 1, (uint16 *) &resp, sizeof(UsbResponse)); } /* Discard the original request */ SourceDrop(source, packet_size); } } }