static void scanner_scanning_state_enter(void) { Source source; DEBUG(( "scanner, scanning state enter... \n" )); update_indication(); /** start scanning timeout timer **/ MessageSendLater(&scanner.task, SCANNER_SCANNING_TIMEOUT_IND, 0, SCANNER_SCANNING_TIMEOUT); /** pull-down and start timeout timer **/ trigger_drive_low(); /** MessageSendLater(&scanner.task, SCANNER_SCANNING_PULLDOWN_TIMEOUT_IND, 0, SCANNER_SCANNING_PULLDOWN_TIMEOUT); **/ /** clean-up uart source **/ source = StreamUartSource(); if (source && SourceSize(source) > 0) { SourceDrop(source, SourceSize(source)); } /** clear barcode **/ barcode_clear(&scanner.barcode); }
/*! @brief Discard unread input data Must be performed before deallocating a channel to allow the firmware to free it. */ void gaiaTransportFlushInput(gaia_transport *transport) { Source source; uint16 unread_count; source = gaiaTransportGetSource(transport); unread_count = SourceSize(source); if (unread_count) { SourceDrop(source,unread_count); } }
static void scanner_scanning_state_exit(void) { Source source; DEBUG(( "scanner, scanning state exit... \n" )); MessageCancelAll(&scanner.task, SCANNER_SCANNING_TIMEOUT_IND); trigger_pull_up(); /** don't forget this, we may exit when pulling-down triggering line **/ /** MessageCancelAll(&scanner.task, SCANNER_SCANNING_PULLDOWN_TIMEOUT_IND); **/ source = StreamUartSource(); if (source && SourceSize(source) > 0) { SourceDrop(source, SourceSize(source)); } MessageCancelAll(&scanner.task, MESSAGE_MORE_DATA); MessageCancelAll(&scanner.task, MESSAGE_MORE_SPACE); /** clear barcode **/ barcode_clear(&scanner.barcode); }
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; }
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; }
void swatHandleSwatSignallingData(Source source) { uint16 packet_size, data_size; const uint8 *ptr = SourceMap(source); /* Get the device that sent the signalling data */ remoteDevice* device = swatFindDeviceFromSink( StreamSinkFromSource(source) ); packet_size = SourceSize(source); /* Process each signalling packet in the source (may be more than one signal in the source) */ while(packet_size >= PKT_PAYLOAD) { /* calculate size of packet */ data_size = ((ptr[PKT_PAYLOAD_LEN] & 0x7f) + 3); /* Process the signalling data by the remote device */ switch(ptr[PKT_SIGNAL_ID]) { /*****************************************************************************/ case SWAT_OPEN: { /* send to command handler, include message payload */ MAKE_SWAT_MESSAGE_WITH_LEN(SWAT_COMMAND_OPEN, data_size); message->device = device; memmove(&message->data[0], &ptr[0], data_size); /* If message is a response, send immediatley, otherwise add to queue */ if (ptr[PKT_SIGNAL_TYPE] == SWAT_RSP) { MessageSend(&swat->command_task, SWAT_COMMAND_OPEN, message); } else { SWAT_DEBUG(("[SWAT] SWAT_OPEN_CMD [%x]\n", device->signalling_block)); /* Action the message or add to queue if already handling another message */ MessageSendConditionally(&swat->command_task, SWAT_COMMAND_OPEN, message, &device->signalling_block); } /* command actioned, discard buffer data leaving any additional data behind */ SourceDrop(source, data_size); /* having removed a packet reset the pointer to the start of any more packets */ ptr = SourceMap(source); } break; /*****************************************************************************/ case SWAT_CLOSE: { /* send to command handler, include message payload */ MAKE_SWAT_MESSAGE_WITH_LEN(SWAT_COMMAND_CLOSE, data_size); message->device = device; memmove(&message->data[0], &ptr[0], data_size); /* If message is a response, send immediatley, otherwise add to queue */ if (ptr[PKT_SIGNAL_TYPE] == SWAT_RSP) { MessageSend(&swat->command_task, SWAT_COMMAND_CLOSE, message); } else { SWAT_DEBUG(("[SWAT] SWAT_CLOSE_CMD [%x]\n", device->signalling_block)); /* Action the message or add to queue if already handling another message */ MessageSendConditionally(&swat->command_task, SWAT_COMMAND_CLOSE, message, &device->signalling_block); } /* command actioned, discard buffer data leaving any additional data behind */ SourceDrop(source, data_size); /* having removed a packet reset the pointer to the start of any more packets */ ptr = SourceMap(source); } break; /*****************************************************************************/ case SWAT_START: { /* send to command handler, include message payload */ MAKE_SWAT_MESSAGE_WITH_LEN(SWAT_COMMAND_START, data_size); message->device = device; memmove(&message->data[0], &ptr[0], data_size); /* If message is a response, send immediatley, otherwise add to queue */ if (ptr[PKT_SIGNAL_TYPE] == SWAT_RSP) { MessageSend(&swat->command_task, SWAT_COMMAND_START, message); } else { SWAT_DEBUG(("[SWAT] SWAT_START_CMD [%x]\n", device->signalling_block)); /* Action the message or add to queue if already handling another message */ MessageSendConditionally(&swat->command_task, SWAT_COMMAND_START, message, &device->signalling_block); } /* command actioned, discard buffer data leaving any additional data behind */ SourceDrop(source, data_size); /* having removed a packet reset the pointer to the start of any more packets */ ptr = SourceMap(source); } break; /*****************************************************************************/ case SWAT_SUSPEND: { /* send to command handler, include message payload */ MAKE_SWAT_MESSAGE_WITH_LEN(SWAT_COMMAND_SUSPEND, data_size); message->device = device; memmove(&message->data[0], &ptr[0], data_size); /* If message is a response, send immediatley, otherwise add to queue */ if (ptr[PKT_SIGNAL_TYPE] == SWAT_RSP) { MessageSend(&swat->command_task, SWAT_COMMAND_SUSPEND, message); } else { SWAT_DEBUG(("[SWAT] SWAT_SUSPEND_CMD [%x]\n", device->signalling_block)); /* Action the message or add to queue if already handling another message */ MessageSendConditionally(&swat->command_task, SWAT_COMMAND_SUSPEND, message, &device->signalling_block); } /* command actioned, discard buffer data leaving any additional data behind */ SourceDrop(source, data_size); /* having removed a packet reset the pointer to the start of any more packets */ ptr = SourceMap(source); } break; /*****************************************************************************/ case SWAT_SET_VOLUME: { /* send to command handler, include message payload */ MAKE_SWAT_MESSAGE_WITH_LEN(SWAT_COMMAND_SET_VOLUME, data_size); message->device = device; memmove(&message->data[0], &ptr[0], data_size); /* If message is a response, send immediatley, otherwise add to queue */ if (ptr[PKT_SIGNAL_TYPE] == SWAT_RSP) { MessageSend(&swat->command_task, SWAT_COMMAND_SET_VOLUME, message); } else { SWAT_DEBUG(("[SWAT] SWAT_SET_VOLUME_CMD [%x]\n", device->signalling_block)); /* Action the message or add to queue if already handling another message */ MessageSendConditionally(&swat->command_task, SWAT_COMMAND_SET_VOLUME, message, &device->signalling_block); } /* command actioned, discard buffer data leaving any additional data behind */ SourceDrop(source, data_size); /* having removed a packet reset the pointer to the start of any more packets */ ptr = SourceMap(source); } break; /*****************************************************************************/ case SWAT_SAMPLE_RATE: { /* send to command handler, include message payload */ MAKE_SWAT_MESSAGE_WITH_LEN(SWAT_COMMAND_SAMPLE_RATE, data_size); message->device = device; memmove(&message->data[0], &ptr[0], data_size); /* If message is a response, send immediatley, otherwise add to queue */ if (ptr[PKT_SIGNAL_TYPE] == SWAT_RSP) { MessageSend(&swat->command_task, SWAT_COMMAND_SAMPLE_RATE, message); } else { SWAT_DEBUG(("[SWAT] SWAT_SAMPLE_RATE_CMD [%x]\n", device->signalling_block)); /* Action the message or add to queue if already handling another message */ MessageSendConditionally(&swat->command_task, SWAT_COMMAND_SAMPLE_RATE, message, &device->signalling_block); } /* Command actioned, discard buffer data leaving any additional data behind */ SourceDrop(source, data_size); /* Having removed a packet reset the pointer to the start of any more packets */ ptr = SourceMap(source); } break; /*****************************************************************************/ case SWAT_GET_VERSION: { /* send to command handler, include message payload */ MAKE_SWAT_MESSAGE_WITH_LEN(SWAT_COMMAND_GET_VERSION, data_size); message->device = device; memmove(&message->data[0], &ptr[0], data_size); /* If message is a response, send immediatley, otherwise add to queue */ if (ptr[PKT_SIGNAL_TYPE] == SWAT_RSP) { MessageSend(&swat->command_task, SWAT_COMMAND_GET_VERSION, message); } else { SWAT_DEBUG(("[SWAT] SWAT_COMMAND_GET_VERSION [%x]\n", device->signalling_block)); /* Action the message or add to queue if already handling another message */ MessageSendConditionally(&swat->command_task, SWAT_COMMAND_GET_VERSION, message, &device->signalling_block); } /* Command actioned, discard buffer data leaving any additional data behind */ SourceDrop(source, data_size); /* Having removed a packet reset the pointer to the start of any more packets */ ptr = SourceMap(source); } break; /*****************************************************************************/ case SWAT_GENERAL_REJECT: { /* send to command handler, include message payload */ MAKE_SWAT_MESSAGE_WITH_LEN(SWAT_COMMAND_GENERAL_REJECT, data_size); message->device = device; memmove(&message->data[0], &ptr[0], data_size); /* Handle the GENERAL_REJECT command as it won't affect ongoing operations */ MessageSend(&swat->command_task, SWAT_COMMAND_GENERAL_REJECT, message); /* command actioned, discard buffer data leaving any additional data behind */ SourceDrop(source, data_size); /* having removed a packet reset the pointer to the start of any more packets */ ptr = SourceMap(source); } break; /*****************************************************************************/ default: { /* send to command handler, include message payload */ MAKE_SWAT_MESSAGE(SWAT_COMMAND_DEFAULT); message->device = device; MessageSend(&swat->command_task, SWAT_COMMAND_DEFAULT, message); /* block any more signalling commands until current process has completed */ device->signalling_block = DATA_BLOCK; /* Discard entire buffer as got out of sync */ SourceDrop(source, packet_size); } } /* recalculate the packet size of any data left in the source */ packet_size = SourceSize(source); } }
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); } } }
void ConnectionHandleComplexMessage(Task task, MessageId id, Message message) { switch (id) { case CL_L2CAP_CONNECT_IND: { CL_L2CAP_CONNECT_IND_T *original; CL_L2CAP_CONNECT_IND_TEST_EXTRA_T *new_msg = malloc(sizeof(CL_L2CAP_CONNECT_IND_TEST_EXTRA_T)); original = (CL_L2CAP_CONNECT_IND_T *) message; new_msg->bd_addr = original->bd_addr; new_msg->psm = original->psm; new_msg->cid = original->connection_id; new_msg->identifier = original->identifier; new_msg->task = (uint16) task; MessageSend(task, CL_L2CAP_CONNECT_IND_TEST_EXTRA, new_msg); } break; case CL_L2CAP_CONNECT_CFM: { CL_L2CAP_CONNECT_CFM_T *original; CL_L2CAP_CONNECT_CFM_TEST_EXTRA_T *new_msg = malloc(sizeof(CL_L2CAP_CONNECT_CFM_TEST_EXTRA_T)); original = (CL_L2CAP_CONNECT_CFM_T *) message; new_msg->status = original->status; new_msg->psm_local = original->psm_local; new_msg->sink = original->sink; new_msg->connection_id = original->connection_id; new_msg->mtu_remote = original->mtu_remote; new_msg->flush_timeout_remote = original->flush_timeout_remote; new_msg->qos_remote = original->qos_remote; new_msg->flow_mode = original->mode; new_msg->task = (uint16) MessageSinkGetTask(original->sink); MessageSend(task, CL_L2CAP_CONNECT_CFM_TEST_EXTRA, new_msg); } break; case MESSAGE_MORE_DATA: { Source src = ((MessageMoreData*)message)->source; CL_SYSTEM_MORE_DATA_TEST_EXTRA_T *pdu; const uint8 *s = SourceMap(src); uint16 len = SourceBoundary(src); uint16 datalen=len; /* Do not allow large data more than 512 ..Just Limit to * 128 bytes. */ if(len > 128) len=128; pdu = malloc(sizeof(CL_SYSTEM_MORE_DATA_TEST_EXTRA_T)+len); memset(pdu, 0, sizeof(CL_SYSTEM_MORE_DATA_TEST_EXTRA_T)); pdu->sink = StreamSinkFromSource(src); pdu->size_data = datalen; memmove(pdu->data, s, len); SourceDrop(src, datalen); MessageSend(task, CL_SYSTEM_MORE_DATA_TEST_EXTRA, pdu); } break; case MESSAGE_MORE_SPACE: case MESSAGE_SOURCE_EMPTY: break; case CL_SM_READ_LOCAL_OOB_DATA_CFM: { /* Create new message */ CL_SM_READ_LOCAL_OOB_DATA_CFM_T *original; CL_SM_READ_LOCAL_OOB_DATA_CFM_TEST_EXTRA_T *new_msg = malloc( sizeof(CL_SM_READ_LOCAL_OOB_DATA_CFM_TEST_EXTRA_T) + (2 * CL_SIZE_OOB_DATA) ); original = (CL_SM_READ_LOCAL_OOB_DATA_CFM_T*)message; /* Copy over the status */ new_msg->status = original->status; /* Copy over transport */ new_msg->transport = original->transport; /* Copy over what type of OOB data is present */ new_msg->oob_data_present = original->oob_data; /* Set size */ new_msg->size_oob_data = 2*CL_SIZE_OOB_DATA; /* Copy over the OOB data */ memmove( new_msg->oob_data, original->oob_hash_c, CL_SIZE_OOB_DATA ); memmove( new_msg->oob_data+CL_SIZE_OOB_DATA, original->oob_rand_r, CL_SIZE_OOB_DATA ); /* Send it to the app */ MessageSend( task, CL_SM_READ_LOCAL_OOB_DATA_CFM_TEST_EXTRA, new_msg ); } break; /* Flatten CL_SM_GET_INDEXED_ATTRIBUTE_CFM */ case CL_SM_GET_INDEXED_ATTRIBUTE_CFM: { CL_SM_GET_INDEXED_ATTRIBUTE_CFM_T *original = (CL_SM_GET_INDEXED_ATTRIBUTE_CFM_T *) message; CL_SM_GET_INDEXED_ATTRIBUTE_CFM_TEST_EXTRA_T *new_msg = malloc( sizeof(CL_SM_GET_INDEXED_ATTRIBUTE_CFM_TEST_EXTRA_T) + (original->size_psdata * sizeof(uint8)) - 1 /* for the psdata array of 1 */ ); new_msg->status = original->status; new_msg->type = original->taddr.type; new_msg->bd_addr = original->taddr.addr; new_msg->size_psdata = original->size_psdata; memmove(new_msg->psdata, original->psdata, original->size_psdata); /* Send the copied message to the app. */ MessageSend( task, CL_SM_GET_INDEXED_ATTRIBUTE_CFM_TEST_EXTRA, new_msg ); } break; FLATTEN_BDADDR(CL_DM_ACL_OPENED_IND); FLATTEN_BDADDR(CL_DM_ACL_CLOSED_IND); FLATTEN_BDADDR(CL_DM_APT_IND); FLATTEN_BDADDR(CL_SM_USER_PASSKEY_REQ_IND); FLATTEN_BDADDR(CL_SM_USER_PASSKEY_NOTIFICATION_IND); FLATTEN_BDADDR(CL_SM_USER_CONFIRMATION_REQ_IND); FLATTEN_BDADDR(CL_SM_PIN_CODE_IND); FLATTEN_BDADDR(CL_SM_ENCRYPTION_KEY_REFRESH_IND); FLATTEN_BDADDR(CL_SM_ENCRYPTION_CHANGE_IND); FLATTEN_BDADDR(CL_SM_IO_CAPABILITY_REQ_IND); FLATTEN_BDADDR(CL_SM_REMOTE_IO_CAPABILITY_IND); #ifndef DISABLE_BLE /* Flatten the typed_bdaddr parts of the message - grrr! */ case CL_DM_BLE_ADVERTISING_REPORT_IND: { CL_DM_BLE_ADVERTISING_REPORT_IND_T *original = (CL_DM_BLE_ADVERTISING_REPORT_IND_T *)message; CL_DM_BLE_ADVERTISING_REPORT_IND_TEST_EXTRA_T *new_msg = (CL_DM_BLE_ADVERTISING_REPORT_IND_TEST_EXTRA_T *) PanicUnlessMalloc( sizeof(CL_DM_BLE_ADVERTISING_REPORT_IND_TEST_EXTRA_T) + original->size_advertising_data - 1 ); new_msg->num_reports = original->num_reports; new_msg->event_type = original->event_type; new_msg->current_addr_type = original->current_taddr.type; new_msg->current_addr = original->current_taddr.addr; new_msg->permanent_addr_type = original->permanent_taddr.type; new_msg->permanent_addr = original->permanent_taddr.addr; new_msg->rssi = original->rssi; new_msg->size_ad_data = original->size_advertising_data; memmove( new_msg->ad_data, original->advertising_data, original->size_advertising_data ); MessageSend( task, CL_DM_BLE_ADVERTISING_REPORT_IND_TEST_EXTRA, new_msg ); } break; FLATTEN_BDADDR(CL_SM_BLE_SIMPLE_PAIRING_COMPLETE_IND); FLATTEN_BDADDR(CL_DM_BLE_SECURITY_CFM); FLATTEN_BDADDR(CL_DM_BLE_CONFIGURE_LOCAL_ADDRESS_CFM); #endif default: printf("CL_MESSAGE_TOP 0x%X\n", CL_MESSAGE_TOP); printf("CL_SHIM_MESSAGE_TOP 0x%X\n", CL_SHIM_MESSAGE_TOP); printf("Message received id 0x%X\n", id); Panic(); break; } }
static void scanner_scanning_state_handler(Task task, MessageId id, Message message) { switch (id) { case HAL_MESSAGE_FUNCTION_BUTTON_PRESS: DEBUG(( "scanner, scanner_scanning_state_handler, FUNCTION_BUTTON_0 arrived... ignored... \n" )); break; /** this is something wrong case SCANNER_SCANNING_PULLDOWN_TIMEOUT_IND: DEBUG(( "scanner, scanner_scanning_state_handler, SCANNER_SCANNING_PULLDOWN_TIMEOUT_IND arrived... \n" )); trigger_pull_up(); break; **/ case SCANNER_SCANNING_TIMEOUT_IND: DEBUG(( "scanner, scanner_scanning_state_handler, SCANNER_SCANNING_TIMEOUT_IND arrived... \n" )); scanner_scanning_state_exit(); scanner.on_state = SCANNER_ON_READY; scanner_ready_state_enter(); break; case MESSAGE_MORE_DATA: { Source source; uint16 size; const uint8* ptr; bool fill_success; DEBUG(( "scanner, scanner_scanning_state_handler, MESSAGE_MORE_DATA arrived... \n" )); source = StreamUartSource(); size = SourceSize(source); DEBUG(( " source has %d bytes of data... \n", size )); ptr = SourceMap(source); fill_success = barcode_fill_raw_bytes(&scanner.barcode, ptr, size); SourceDrop(source, size); /* enable_buzzer(); MessageSendLater(&scanner.task, SCANNER_SCANNING_BUZZER_TIMEOUT_IND, 0, SCANNER_SCANNING_BUZZER_TIMEOUT); */ if ( TRUE == fill_success ) { DEBUG(( " barcode_fill_raw_bytes succeed... \n" )); if ( barcode_is_terminated(&scanner.barcode) ) { barcode_t* result; DEBUG(( " barcode is terminated... \n" )); DEBUG(( " %s", scanner.barcode.code )); result = (barcode_t*)malloc(sizeof(barcode_t)); if (0 == result) { /** mem fail, then neglect the result **/ DEBUG(( " mem error, no result sent... \n" )); scanner_scanning_state_exit(); scanner.on_state = SCANNER_ON_READY; scanner_ready_state_enter(); } else { /** throw out message to client **/ DEBUG(( " result sent to client in SCANNER_RESULT_MESSAGE... \n" )); memcpy(result, &scanner.barcode, sizeof(barcode_t)); MessageSend(scanner.client, SCANNER_RESULT_MESSAGE, result); scanner_scanning_state_exit(); scanner.on_state = SCANNER_ON_READY; scanner_ready_state_enter(); } } else { DEBUG(( " barcode is not terminated... \n" )); } } else { DEBUG(( " barcode_fill_raw_bytes failed... \n" )); scanner_scanning_state_exit(); scanner.on_state = SCANNER_ON_READY; scanner_ready_state_enter(); } } break; /* case SCANNER_SCANNING_BUZZER_TIMEOUT_IND: DEBUG(( "scanner, scanner_scanning_state_handler, SCANNER_SCANNING_BUZZER_TIMEOUT_IND arrived... \n" )); disable_buzzer(); break; */ } }