/** * @fn INT16 rsi_bt_execute_cmd(UINT08 *descparam,UINT08 *payloadparam,UINT16 size_param) * @brief Common function for all the commands. * @param[in] UINT08 *descparam, pointer to the frame descriptor parameter structure * @param[in] UINT08 *payloadparam, pointer to the command payload parameter structure * @param[in] UINT16 size_param, size of the payload for the command * @return errCode * -1 = SPI busy / Timeout * -2 = SPI Failure * 0 = SUCCESS * @section description * This is a common function used to process a command to the BT module. */ INT16 rsi_bt_execute_cmd(UINT08 *descparam, UINT08 *payloadparam, UINT16 size_param) { INT16 retval; RSI_BT_FRAME_DESC uFrameDscFrame; //! 16 bytes, send/receive command descriptor frame //! Create the Command Frame Descriptor rsi_bt_build_frame_descriptor(&uFrameDscFrame, descparam); #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL3,"Descriptor write"); #endif //! Write descriptor and payload retval = rsi_frame_write((rsi_uFrameDsc *)&uFrameDscFrame, payloadparam, size_param); if (retval != 0x00) { #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL4,"Frame write failErr=%02x", (UINT16)retval); #endif return retval; } return retval; }
/** * @fn int16 rsi_frame_write(rsi_uFrameDsc *uFrameDscFrame,uint8 *payloadparam,uint16 size_param) * @brief Common function for all the commands. * @param[in] uFrameDsc uFrameDscFrame, frame descriptor * @param[in] uint8 *payloadparam, pointer to the command payload parameter structure * @param[in] uint16 size_param, size of the payload for the command * @return errCode * -1 = SPI busy / Timeout * -2 = SPI Failure * 0 = SUCCESS * @section description * This is a common function used to process a command to the Wi-Fi module. */ int16 rsi_frame_write(rsi_uFrameDsc *uFrameDscFrame,uint8 *payloadparam,uint16 size_param) { int16 retval; //! Write out the Command Frame Descriptor retval = rsi_spi_frame_dsc_wr(uFrameDscFrame); if (retval != 0x00) { #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL4,"Descriptor write failErr=%02x", (uint16)retval); #endif return retval; } //! Write the Command Frame Data if(size_param) { size_param= (size_param+3)&~3; retval = rsi_spi_frame_data_wr(size_param, payloadparam, 0, NULL); if (retval != 0x00) { #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL4,"FramePayload writeErr=%02x", (uint16)retval); #endif return retval; } } return retval; }
int32_t rsi_zigb_framework_init(void) { int16_t retval = RSI_ZB_SUCCESS; retval = rsi_nl_socket_init(); if (retval != RSI_ZB_SUCCESS) { RSI_DPRINT(RSI_PL1,"\n Netlink socket creation failed \n"); return RSI_ZB_FAIL; } #ifdef ZB_DEBUG RSI_DPRINT(RSI_PL1,"NL Socket created\n"); #endif rsi_fill_genl_nl_hdrs_for_cmd(); #ifdef ZB_DEBUG RSI_DPRINT(RSI_PL1,"NL gnl hdr filled\n"); #endif if(pthread_mutex_init(&rsi_linux_app_cb.mutex1, NULL) != 0) { RSI_DPRINT(RSI_PL1,"\n Mutex init failed..."); return RSI_ZB_FAIL; } if(pthread_create(&zigb_rcv_thd, NULL, zigb_read_pkt_thread, 0)) { RSI_DPRINT(RSI_PL1,"\n Receive Thread creation failed \n"); return RSI_ZB_FAIL; } return RSI_ZB_SUCCESS; }
int main(int argc, char *argv[]) { int32_t status = RSI_ZB_SUCCESS; uint8_t skip_card_ready = 0; status = rsi_zigb_framework_init(); #ifdef ZB_DEBUG RSI_DPRINT(RSI_PL14,"Framework init done\n"); #endif if (status != RSI_ZB_SUCCESS) { RSI_DPRINT(RSI_PL14,"\n Error in Netlink socket creation \n"); return -1; } if (argc == 1) { skip_card_ready = 0; } else { skip_card_ready = 1; } status = zigb_main(skip_card_ready); if (status != RSI_ZB_SUCCESS) { RSI_DPRINT(RSI_PL1,"\n Exit from ZigBee main \n"); return -1; } exit(0); }
/** * @fn int16 rsi_waitfor_boardready(void) * @brief Waits to receive board ready from WiFi module * @param[in] none * @param[out] none * @return errCode * 0 = SUCCESS * @section description * This API is used to check board ready from WiFi module. */ int16 rsi_waitfor_boardready(void) { int16 retval = 0; uint16 read_value = 0; while(1) { retval = rsi_boot_insn(REG_READ, (uint32 *)&read_value); #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL3,"WAITING TO RECEIVE BOARD READY\n"); #endif if ((read_value & 0xFF00) == (HOST_INTERACT_REG_VALID & 0xFF00)) { if((read_value & 0xFF) == BOOTLOADER_VERSION) { #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL3,"BOOTLOADER VERSION CORRECT\n"); #endif } else { #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL3,"BOOTLOADER VERSION NOT MATCHING\n"); #endif } #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL3,"RECIEVED BOARD READY\n"); #endif break; } } return retval; }
/** * @fn int16 rsi_frame_read(uint8 *pkt_buffer) * @brief This function is used to read the response from module. * @param[in] uint8 *pkt_buffer, pointer to the buffer to which packet has to read * which is used to store the response from the module * @param[out] none * @return errCode * -1 = SPI busy / Timeout * -2 = SPI Failure * 0 = SUCCESS * @section description * This is a common function to read response for all the command and data from Wi-Fi module. */ int16 rsi_frame_read(uint8 *pkt_buffer) { int16 retval; uint8 local_buffer[8]; retval = rsi_pre_dsc_rd(&local_buffer[0]); if (retval != 0x00) { #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL4,"DscRd Error=%02x ", (uint16)retval); #endif return retval; } #ifdef CO_EX retval = rsi_pkt_rd(pkt_buffer, ((*(uint16 *)&local_buffer[2])-4),((*(uint16 *)&local_buffer[0])-4)); #else retval = rsi_pkt_rd(pkt_buffer, *(uint16 *)&local_buffer[2], *(uint16 *)&local_buffer[0]); #endif if (retval != 0x00) { #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL4,"DscRdError=%02x ", (uint16)retval); #endif return retval; } return retval; }
int16_t rsi_frame_read(uint8_t *packet_buffer) { /* Variables */ rsi_linux_app_cb_t *linux_app_cbPtr = &rsi_linux_app_cb; pkt_struct_t *rspPtr = NULL; /* Length of the data to copy */ int16_t length = 0; /* Pointer to the Packet file descriptor */ uint8_t *descPtr = NULL; #ifdef RSI_DEBUG_PRINT int i; #endif /* Do actual deque from the RX queue */ pthread_mutex_lock(&linux_app_cbPtr->mutex1); rspPtr = rsi_dequeue_from_rcv_q(); pthread_mutex_unlock(&linux_app_cbPtr->mutex1); /* Assign pointers to appropriate addresses */ descPtr = rspPtr->data + RSI_NL_HEAD_SIZE; /* Calculate length of the packet from the first two bytes of the frame descriptor */ #ifdef RSI_LITTLE_ENDIAN length = *(int16_t*)descPtr & 0x0fff; #else length = rsi_bytes2R_to_uint16(descPtr); #endif length += RSI_FRAME_DESC_LEN; /* Debug: Print the length & contents of the packet */ #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL0,"RX Len of the packet: %d\n", length); for (i=0; i<length; i++) { RSI_DPRINT (RSI_PL0, "0x%x ", descPtr[i]); if ((i % 16 == 0) && (i != 0)) { RSI_DPRINT(RSI_PL0, "\n"); } } RSI_DPRINT(RSI_PL0, "\n"); #endif memset(packet_buffer, 0, length); memcpy(packet_buffer, descPtr, length); rsi_free(rspPtr); /* Return success */ return RSI_ZB_SUCCESS; }
/** * @fn int16 rsi_spi_frame_data_wr(uint16 bufLen, uint8 *dBuf,uint16 tbufLen,uint8 *tBuf) * @brief Writes a Control data frame decriptor. * @param[in] uint16 buflen length of the data buffer to write * @param[in] uint8 *dBuf, pointer to the buffer of data to write * @param[in] uint16 tbuflen length of the data fragment to write * @param[in] uint8 *tBuf, pointer to the buffer of data fragment to write * @param[out] none * @return errCode * -1 = SPI busy / Timeout * -2 = SPI Failure * 0 = SUCCESS * @section description * This function performs Frame Data Write. */ int16 rsi_spi_frame_data_wr(uint16 bufLen, uint8 *dBuf,uint16 tbufLen,uint8 *tBuf) { int16 retval; uint8 c1; uint8 c2; uint8 c3; uint8 c4; #ifdef LINUX uint8 localBuf[1600]; #else uint8 localBuf[8]; #endif uint16 tempbufLen; tempbufLen = bufLen + tbufLen; c1 = RSI_C1FRMWR16BIT4BYTE; #ifdef RSI_BIT_32_SUPPORT c2 = RSI_C2RDWR4BYTE; #else c2 = RSI_C2RDWR1BYTE; #endif c3 = (uint8)(tempbufLen & 0x00ff); //! lower byte of transfer length c4 = (uint8)((tempbufLen >> 8) & 0x00FF);//! upper byte of transfer length #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL5,"\r\nFrmDataWr"); #endif retval = rsi_send_c1c2(c1, c2); //! send C1/C2 if (retval != 0) { #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL6,"\r\n data write - C1C2 Failed"); #endif return retval; } //!exit with error if we timed out waiting for the SPI to get ready retval = rsi_send_c3c4(c3, c4); //! send C3/C4 #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL5," FrameData="); #endif #if 1 retval = rsi_spi_send(dBuf, bufLen,localBuf,RSI_MODE_32BIT); if(tbufLen) { retval = rsi_spi_send(tBuf, tbufLen,localBuf,RSI_MODE_32BIT); } #endif return retval; }
int16_t rsi_zigb_execute_cmd(uint8_t *descparam, uint8_t *payloadparam, uint16_t size_param) { int16_t retval = 0; rsi_zigb_uFrameDsc uFrameDscFrame; uint8_t *cmd_buff; #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL14,"\nrsi_zigb_execute_cmd:\n"); #endif //! Build 16 bytes, send/receive command descriptor frame rsi_zigb_build_frame_descriptor(&uFrameDscFrame, descparam, size_param); cmd_buff = rsi_alloc_and_init_cmdbuff((uint8_t *)&uFrameDscFrame,payloadparam,size_param); if(rsi_send_usr_cmd(cmd_buff, GET_SEND_LENGTH(cmd_buff)) < 0) { retval = -2; } if(retval < 0) { printf("Unable to issue command\n"); } //! Free the command buffer rsi_free(cmd_buff); return retval; }
/** * @fn int16 rsi_pre_dsc_rd(uint8 *dbuf) * @brief Reads a pre frame descriptor * @param[in] uint8 *dbuf, pointer to the buffer into which pre decriptor has to be read * @param[out] none * @return errCode * -1 = SPI busy / Timeout * -2 = SPI Failure * 0 = SUCCESS * @section description * This function performs pre frame decriptor read. */ int16 rsi_pre_dsc_rd(uint8 *dbuf) { int16 retval; uint8 c1; uint8 c2; uint8 c3; uint8 c4; c1 = RSI_C1FRMRD16BIT4BYTE; //! 0x5c #ifdef RSI_BIT_32_SUPPORT c2 = RSI_C2SPIADDR4BYTE; //! 0x40 #else c2 = RSI_C2MEMRDWRNOCARE; //! 0x00 #endif c3 = 0x04; //! command frame response descriptor c4 = 0x00; //! upper bye of transfer length #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL5," CFrameDscRd="); #endif // Send C1/C2 retval = rsi_send_c1c2(c1, c2); if (retval != 0) { #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL6," pre desc read - C1C2 Failed"); #endif return retval; //! exit with error if we timed out waiting for the SPI to get ready } // Send C3/C4 retval = rsi_send_c3c4(c3, c4); // Wait for start token retval = rsi_spi_wait_start_token(RSI_START_TOKEN_TIMEOUT,RSI_MODE_32BIT); if (retval != 0) { #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL6," pre desc read - Start token wait Failed"); #endif return retval; //! exit with error if we timed out waiting for the SPI to get ready } #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL6," CFrameDscRd="); #endif retval = rsi_spi_recv((uint8 *)dbuf, 0x4, RSI_MODE_32BIT); //! read the command frame descriptor return retval; //! return the control frame length }
int16 rsi_load_web_page(rsi_uWebServer *uWebServer, uint8* webpage_file) { int16 retval = 0; uint16 curr_len = MAX_WEBPAGE_SEND_SIZE; uint16 file_size = *(uint16*)(uWebServer->webServFrameSnd.Webpage_info.total_len); static uint16 offset; #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL3,"\nLoad Webpage Start\n"); #endif //! Get the current length that you want to send curr_len = (file_size - offset > MAX_WEBPAGE_SEND_SIZE) ? MAX_WEBPAGE_SEND_SIZE : (file_size - offset); //! Update the current length to be sent *(uint16*) (uWebServer->webServFrameSnd.Webpage_info.current_len) = curr_len; #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL3, "total, current, offset: %d, %d, %d\n", file_size, curr_len, offset); #endif //! Copy the webpage file contents into the buffer memcpy((uint8*)(uWebServer->webServFrameSnd.Webpage_info.webpage), (uint8*)(webpage_file + offset), curr_len); //! Send the data retval = rsi_execute_cmd((uint8 *)rsi_frameCmdWebServer ,(uint8 *)uWebServer, sizeof(rsi_uWebServer)); //! Adjust the offset offset += curr_len; //! Reset offset for next file if required if (offset == file_size) { offset = 0; webpage_load_done = 1; } return retval; }
/** * @fn int16 rsi_web_fields(rsi_uWebFields *uWebFields) * @brief Sends the WebFields command to the Wi-Fi module via SPI * @param[in] rsi_uWebFields *uWebFields, Pointer to Webfields structure * @param[out] none * @return errCode * -2 = Command execution failure * -1 = Buffer Full * 0 = SUCCESS * @section description * This API is used to load the webpage to the Wi-Fi module. * This API should be called only after rsi_init API. * * @section prerequisite * The rsi_init for the Wi-Fi Module initialization should be done successfully. */ int16 rsi_web_fields(rsi_uWebFields *uWebFields) { int16 retval; #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL3,"\r\n\n Web Fields Start"); #endif retval = rsi_execute_cmd((uint8 *)rsi_frameCmdWebFields ,(uint8 *)uWebFields, sizeof(rsi_uWebFields)); return retval; }
/** * @fn int16 rsi_band(uint8 band) * @brief Sends the Band command to the Wi-Fi module * @param[in] uint8 band, band value to configure,0 for 2.4GHz and 1 for 5GHz. * @param[out] none * @return errCode * -1 = Buffer Full * 0 = SUCCESS * @section description * This API is used to select the 2.4 GHz mode or 5GHz mode. * which have an option of operating in either the 2.4GHz or 5GHz modes. * in the 2.4GHz mode. This API has to be called only after the rsi_opermode API. */ int16 rsi_band(uint8 band) { int16 retval; rsi_uBand uBandFrame; #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL3,"\r\n\nBand Start"); #endif uBandFrame.bandFrameSnd.bandVal = band; retval =rsi_execute_cmd((uint8 *)rsi_frameCmdBand,(uint8 *)&uBandFrame, sizeof(rsi_uBand)); return retval; }
int16 rsi_send_raw_data(uint8 *payload, uint32 payloadLen,uint32 *bytes_sent) { int16 retval = 0; rsi_uFrameDsc uFrameDscFrame; //!payload length sent in each packet uint32 send_payload_len; //!payload offset uint32 payload_offset = 0; //! build the SEND frame descriptor rsi_build_frame_descriptor(&uFrameDscFrame,(uint8 *) rsi_frameCmdSend); while(payloadLen) { if(payloadLen >= 1500) { send_payload_len = 1500; } else { send_payload_len = payloadLen; } #ifdef RSI_LITTLE_ENDIAN //! set the frame length LSB uFrameDscFrame.frameDscDataSnd.dataFrmLenAndQueue[0] = (uint8)(send_payload_len & 0x00ff); //! set the frame length MSB uFrameDscFrame.frameDscDataSnd.dataFrmLenAndQueue[1] = (uint8)(((send_payload_len >> 8) & 0x000f)| 0x50); #else //! set the frame length LSB uFrameDscFrame.frameDscDataSnd.dataFrmLenAndQueue[0] = (uint8)(send_payload_len & 0x00ff); //! set the frame length MSB uFrameDscFrame.frameDscDataSnd.dataFrmLenAndQueue[1] = (uint8)(((send_payload_len >> 8) & 0x000f) | 0x50); #endif #ifndef UART_INTERFACE //! Write out the command frame descriptor retval = rsi_spi_frame_dsc_wr(&uFrameDscFrame); //! Write the Raw Data to send retval = rsi_spi_frame_data_wr(send_payload_len,(uint8 *)(payload + payload_offset),0,NULL); #endif if (retval != 0x00) { #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL4,"SndFrmDescErr=%02x", (uint16)retval); #endif return retval; } payloadLen -= send_payload_len; payload_offset += send_payload_len; *bytes_sent += send_payload_len; } return retval; }
int16 rsi_ht_caps(rsi_uHtCaps *uHtCapsFrame) { int16 retval; #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL3,"\r\n\n HT CAPS starts"); #endif retval = rsi_execute_cmd((uint8 *)rsi_frameCmdHtCaps,(uint8 *)uHtCapsFrame,sizeof(rsi_uHtCaps)); return retval; }
/** * @fn int16 rsi_spi_frame_dsc_wr(uFrameDsc *uFrameDscFrame) * @brief Writes a Frame descriptor * @param[in] uFrameDsc uFrameDscFrame, frame descriptor * @param[in] uint8 type, To indicate the type whether it is DATA or MGMT * @param[out] none * @return errCode * -1 = SPI busy / Timeout * -2 = SPI Failure * 0 = SUCCESS * @section description * This function performs Frame Decriptor Write. */ int16 rsi_spi_frame_dsc_wr(rsi_uFrameDsc *uFrameDscFrame) { int16 retval; uint8 c1; uint8 c2; uint8 c3; uint8 c4; uint8 localBuf[16]; c1 = RSI_C1FRMWR16BIT4BYTE; // 0x7c #ifdef RSI_BIT_32_SUPPORT c2 = RSI_C2RDWR4BYTE; #else c2 = RSI_C2RDWR1BYTE; #endif c3 = RSI_FRAME_DESC_LEN; //! frame descriptor is 16 bytes long c4 = 0x00; //! upper bye of transfer length #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL5,"\r\nCFrmDscWr"); #endif retval = rsi_send_c1c2(c1, c2); //! send C1/C2 if (retval != 0) { #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL6," desc write - C1C2 Failed"); #endif return retval; //! exit with error if we timed out waiting for the SPI to get ready } retval = rsi_send_c3c4(c3, c4); //! send C3/C4 #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL5," CFrameDscWr="); #endif retval = rsi_spi_send(&uFrameDscFrame->uFrmDscBuf[0], RSI_FRAME_DESC_LEN,localBuf,RSI_MODE_32BIT); //! the Management Type byte is in byte 1 (byte 0 is the length) return retval; //! here we can only return ok }
void * zigb_read_pkt_thread(void *arg) { pkt_struct_t *rcvPktPtr; int32_t rsp_len; //char *s = arg; #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL14,"\nRecvThreadBody:\n"); #endif //RSI_DPRINT(RSI_PL13,"%s\n",s); while(1) { rcvPktPtr = (pkt_struct_t*)rsi_malloc(RSI_ZIGB_MAX_PAYLOAD_SIZE + RSI_RXPKT_HEAD_ROOM); if(rcvPktPtr == NULL) { #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL13,"Allocation failed to recv packet\n"); #endif return NULL; } rcvPktPtr->data = (uint8_t *)(((uint8_t *)rcvPktPtr) + RSI_RXPKT_HEAD_ROOM); rsp_len = recv(rsi_linux_app_cb.nl_sd, rcvPktPtr->data , RSI_ZIGB_MAX_PAYLOAD_SIZE, 0); #ifdef ZB_DEBUG RSI_DPRINT(RSI_PL1,"recvd resp in Thread \n"); #endif if(rsp_len < 0) { perror("recv"); return NULL; } pthread_mutex_lock(&rsi_linux_app_cb.mutex1); rsi_enqueue_to_rcv_q(rcvPktPtr); pthread_mutex_unlock(&rsi_linux_app_cb.mutex1); } }
/** * @fn void rsi_build_frame_descriptor(rsi_uFrameDsc *uFrameDscFrame, uint8 *cmd) * @brief Creates a Frame Descriptor * @param[in] rsi_uFrameDsc *uFrameDscFrame,Frame Descriptor * @param[in] uint8 *cmd,Indicates type of the packet(data or management) * @param[out] none * @return none * * @section description * This API is used to build the frame descriptor for the packet which is supposed to be * given to the firmware/module * */ void rsi_build_frame_descriptor(rsi_uFrameDsc *uFrameDscFrame, uint8 *cmd) { uint8 i; uint8 queue_no; for (i = 0; i < RSI_FRAME_DESC_LEN; i++) { uFrameDscFrame->uFrmDscBuf[i] = 0x00; } queue_no = (cmd[1] & 0xf0) >> 4; //!zero the frame descriptor buffer //!data or management frame type if ((queue_no == WLAN_MGMT_TYPE )||(queue_no == WLAN_DATA_TYPE)) { //!The first two bytes have different functions for management frames and //!control frames, but these are set in the pre-defined uFrameDscFrame->uFrmDscBuf[0] = cmd[0]; //!arrays which are the argument passed to this function, so we just set the two values uFrameDscFrame->uFrmDscBuf[1] = cmd[1]; uFrameDscFrame->uFrmDscBuf[2] = cmd[2]; } else if ((queue_no == BT_MGMT_TYPE )||(queue_no == BT_DATA_TYPE)) { //!The first two bytes have different functions for management frames and //!control frames, but these are set in the pre-defined uFrameDscFrame->uFrmDscBuf[0] = cmd[0]; //!arrays which are the argument passed to this function, so we just set the two values uFrameDscFrame->uFrmDscBuf[1] = cmd[1]; uFrameDscFrame->uFrmDscBuf[2] = cmd[2]; uFrameDscFrame->uFrmDscBuf[3] = cmd[3]; } else if(queue_no == ZB_MGMT_TYPE) { for (i = 0; i < RSI_FRAME_DESC_LEN; i++) { uFrameDscFrame->uFrmDscBuf[i] = cmd[i]; } } else { #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL4,"\n INVALID QUEUE : ERROR !!!!!\n "); #endif } return; }
int16 rsi_send_websocket_data(uint16 socketDescriptor, uint8 *payload, uint32 payloadLen,uint8 protocol, uint8 opcode, uint32 *total_bytes_sent) { int16 retval = 0; uint16 send_length = 0; uint32 payload_offset = 0; uint8 websocket_info = 0; uint32 bytes_sent = 0; while(payloadLen) { websocket_info = opcode; if(payloadLen > RSI_TCP_MAX_SEND_SIZE) { send_length = RSI_TCP_MAX_SEND_SIZE; } else { send_length = payloadLen; //! Set the fin bit websocket_info |= BIT(7); } socketDescriptor |= (websocket_info << 8); //! call actual send API retval = rsi_send_data(socketDescriptor, (payload + payload_offset), send_length, (protocol | BIT(7)), &bytes_sent); if(retval != 0) { #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL4,"SendCmd Err=%02x", (uint16)retval); #endif return retval; } payloadLen -= bytes_sent; *total_bytes_sent += bytes_sent; payload_offset += bytes_sent; } return retval; }
int16 rsi_http_get(rsi_uHttpReq *uHttpGetReqFrame) { int16 retval; uint16 buf_len; /*Http GET Request Frame */ uint8 rsi_frameCmdHttpGetReq[RSI_BYTES_3] = {0x00, 0x40, 0x51}; buf_len = sizeof(rsi_uHttpReq) - HTTP_BUFFER_LEN; buf_len += strlen((char *)uHttpGetReqFrame->HttpReqFrameSnd.buffer); *(uint16 *)&rsi_frameCmdHttpGetReq[0] = (buf_len & 0xFFF); rsi_frameCmdHttpGetReq[1] |= 0x40; #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL3,"\r\n\n HTTP GET Start"); #endif retval = rsi_execute_cmd((uint8 *)rsi_frameCmdHttpGetReq,(uint8 *)uHttpGetReqFrame, buf_len); return retval; }
/** * @fn rsi_uCmdRsp *rsi_parse_response(uint8_t *rsp) * @brief To parse the resposne received from Kernel * @param[in] uint8_t *rsp, response buffer pointer * @param[out] none * @return rsi_uCmdRsp *ptr, response pointer * @section description * This API is used to parse the recieved response. This returns the * pointer which points to rsptype, status, response payload in order. */ rsi_init_uCmdRsp *rsi_parse_response(uint8_t *rsp) { rsi_init_uCmdRsp *temp_uCmdRspPtr = NULL; uint8_t temp_rspCode; uint16_t temp_status; uint8_t *descPtr = rsp ; uint8_t *payloadPtr = rsp + RSI_FRAME_DESC_LEN; #ifdef RSI_DEBUG_PRINT uint8_t i; #endif #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL13,"Recieved Packet PRINT3 \n"); #endif /* Check whether it is any rxpkt or just a status indication */ #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL13,"Recieved Packet PRINT4 \n"); #endif /* In Response received First 24 bytes are header. * And then Desc and Payload of the response is present. * 2nd byte of the Desc is status and 14th byte of the Desc is RspType. */ /* Retrieve response code from the received packet */ #ifdef RSI_LITTLE_ENDIAN temp_status = (*(uint16_t *)(descPtr + RSI_STATUS_OFFSET)); temp_rspCode = *((uint8_t *)(descPtr + RSI_RSP_TYPE_OFFSET)); #else temp_status = (uint8_t)rsi_bytes2R_to_uint16(descPtr + RSI_STATUS_OFFSET); temp_rspCode = rsi_bytes2R_to_uint16(descPtr + RSI_RSP_TYPE_OFFSET); #endif #ifdef RSI_DEBUG_PRINT for(i=0; i<16; i++) { RSI_DPRINT(RSI_PL13,"received rspcode: 0x%x \n",descPtr[i]); } #endif if(temp_rspCode) { #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL13,"received status : 0x%x \n",temp_status); RSI_DPRINT(RSI_PL13,"received rspcode: 0x%x \n",temp_rspCode); #endif } /* Copy the response type and status to payloadPtr-4, payloadPtr-2 * locations respectively. */ #ifdef RSI_LITTLE_ENDIAN *((uint16_t *)(payloadPtr - 2)) = temp_status; *((uint16_t *)(payloadPtr - 4)) = temp_rspCode; #else rsi_uint16_to_2bytes((payloadPtr - 2), temp_status); rsi_uint16_to_2bytes((payloadPtr - 4), temp_rspCode); #endif temp_uCmdRspPtr = (rsi_init_uCmdRsp *)(payloadPtr - 4); return temp_uCmdRspPtr; }
/** * @fn int16 rsi_pkt_rd(uint8 *buf, uint16 dummy_len, uint16 total_len) * @brief Reads frame descriptor and payload * @param[in] uint8 *dbuf, pointer to the buffer into which decriptor and payload has to be read * @param[in] uint16 dummy_len, number of dummy bytes which can be discarded * @param[in] uint16 total_len, number of bytes to be read * @param[out] none * @return errCode * -1 = SPI busy / Timeout * -2 = SPI Failure * 0 = SUCCESS * @section description * This function performs frame decriptor and payload read. */ int16 rsi_pkt_rd(uint8 *buf, uint16 dummy_len, uint16 total_len) { int16 retval; uint8 c1; uint8 c2; uint8 c3; uint8 c4; #ifdef CO_EX uint8 dummy_buf[300]; #else uint8 dummy_buf[8]; #endif uint8 local_buf[1600]; uint32 aligned_len=0; #ifdef CO_EX aligned_len = ((total_len) + 3) & ~3; #else aligned_len = ((total_len + dummy_len) + 3) & ~3; #endif c1 = RSI_C1FRMRD16BIT1BYTE; //! 0x5d #ifdef RSI_BIT_32_SUPPORT c2 = RSI_C2SPIADDR1BYTE; //! 0x40 #else c2 = RSI_C2MEMRDWRNOCARE; //! 0x00 #endif c3 = aligned_len & 0xff; //! command frame response descriptor c4 = (aligned_len & 0xff00) >> 8; //! upper bye of transfer length //! Send C1/C2 retval = rsi_send_c1c2(c1, c2); if (retval != 0) { #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL6," packet read - C1C2 Failed"); #endif return retval; //! exit with error if we timed out waiting for the SPI to get ready } //! Send C3/C4 retval = rsi_send_c3c4(c3, c4); //! Wait for start token retval = rsi_spi_wait_start_token(RSI_START_TOKEN_TIMEOUT,RSI_MODE_32BIT); if (retval != 0) { #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL6," packet read - Start token wait Failed"); #endif return retval; //! exit with error if we timed out waiting for the SPI to get ready } #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL6," packet read="); #endif if(dummy_len) { //! spi recv for dummy bytes retval = rsi_spi_recv((uint8 *)&dummy_buf[0],dummy_len,RSI_MODE_8BIT); } //! Actual spi read for descriptor and payload retval = rsi_spi_recv(&local_buf[0], (aligned_len - dummy_len),RSI_MODE_32BIT); //TODO: this support only in 8bit mode need fix it for 32bit mode memcpy((uint8 *)buf, local_buf, (total_len)); //! read the command frame descriptor return retval; //! return the control frame length }
/** * @fn int16 rsi_upgrade_fw(uint8 image_type, uint8 *fw_image, uint32 fw_image_size) * @brief Upgrades firmware to WiFi module * @param[in] uint8 image_type, type of firmware image to upgrade * @param[in] uint8* fw_image, pointer to firmware * @param[in] uint32 fw_image_size, size of firmware image * @param[out] none * @return errCode * 0 = SUCCESS * @section description * This API is used to upgrade firmware to WiFi module. */ int16 rsi_upgrade_fw(uint8 image_type, uint8 *fw_image , uint32 fw_image_size) { uint32 boot_cmd = HOST_INTERACT_REG_VALID | image_type; uint32 read_value = 0; uint32 offset = 0; int16 retval; uint32 boot_insn = 0,poll_resp = 0; retval = rsi_boot_insn(REG_WRITE, &boot_cmd); while(1) { retval = rsi_boot_insn(REG_READ, &read_value); if (read_value == (HOST_INTERACT_REG_VALID | SEND_RPS_FILE)) { break; } } boot_cmd = HOST_INTERACT_REG_VALID | PONG_VALID; while(offset <= fw_image_size){ switch (boot_cmd){ case (HOST_INTERACT_REG_VALID | PING_VALID): boot_insn = PONG_WRITE; poll_resp = PING_AVAIL; boot_cmd = HOST_INTERACT_REG_VALID |PONG_VALID; break; case (HOST_INTERACT_REG_VALID | PONG_VALID): boot_insn = PING_WRITE; poll_resp = PONG_AVAIL; boot_cmd = HOST_INTERACT_REG_VALID |PING_VALID; break; } #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL3,"Burning from %x to %x of %x\n", offset, (offset + 4096), fw_image_size); #endif retval = rsi_boot_insn(boot_insn, (uint32 *)((uint8 *)fw_image + offset)); while(1) { retval = rsi_boot_insn(REG_READ, &read_value); if (read_value == (HOST_INTERACT_REG_VALID | poll_resp)) { break; } } offset += 1024*4; } boot_cmd = HOST_INTERACT_REG_VALID | EOF_REACHED; #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL3,"EOF REACHED\n"); #endif retval = rsi_boot_insn(REG_WRITE, &boot_cmd); while(1){ retval = rsi_boot_insn(REG_READ, &read_value); #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL3,"WAITING TO RECEIVE FIRMWARE UPGRADATION STATUS\n"); #endif if (read_value == (HOST_INTERACT_REG_VALID | FWUP_SUCCESSFUL)) { #ifdef RSI_DEBUG_PRINT RSI_DPRINT(RSI_PL3,"FIRMWARE UPGRADATION SUCCESSFUL\n"); #endif break; } } return retval; }