/***************************************************************************** * FUNCTION: WF_LibInitialize * * RETURNS: None * * PARAMS: None * * NOTES: Performs initialization which is specific to the Microchip Demo code. *****************************************************************************/ static void WF_LibInitialize() { /* Disable Tx Data confirms (from the MRF24W) */ WF_SetTxDataConfirm(WF_DISABLED); /* if the user has left the default MAC address in TCPIPConfig.h unchanged then use */ /* the unique MRF24W MAC address so prevent multiple devices from having the same */ /* MAC address. */ if ( memcmp((void *)AppConfig.MyMACAddr.v, (void *)MchpDefaultMacAddress, WF_MAC_ADDRESS_LENGTH) == 0) { /* get the MRF24W MAC address and overwrite the MAC in AppConfig */ WF_GetMacAddress((UINT8 *)AppConfig.MyMACAddr.v); } /* else presume the user has a unique MAC address of their own that they wish to use */ else { // set MAC address with user-supplied MAC */ WF_SetMacAddress((UINT8 *)AppConfig.MyMACAddr.v); } #ifdef WF_CONFIG_DHCP WF_SET_DHCP_STATE(DHCP_ENABLED); #endif }
/***************************************************************************** * * exoHAL_ReadUUID * * \param if_nbr - Interface Number (1 - WiFi) * UUID_buf - buffer to return hexadecimal MAC * * \return 0 if failure; len of UUID if success; * * \brief Reads the MAC address from the hardware * *****************************************************************************/ int exoHAL_ReadUUID(unsigned char if_nbr, char * UUID_buf) { int retval = 0; MAC_ADDR macbuf; unsigned char macstr[20]; switch (if_nbr) { case IF_GPRS: break; case IF_ENET: break; case IF_WIFI: WF_GetMacAddress(macbuf.v); sprintf((char *)macstr,"%02X%02X%02X%02X%02X%02X", macbuf.v[0], macbuf.v[1], macbuf.v[2], macbuf.v[3], macbuf.v[4], macbuf.v[5]); retval = strlen((char *)macstr); memcpy(UUID_buf, macstr, retval); UUID_buf[retval] = 0; break; default: break; } return retval; }
int PostHeaderGenerate(char * cgiprogram, int cmd, int start, int end ) { int length; char DataLen[12]; MAC_ADDR macbuf; unsigned char macstr[20]; header[0] = 0; // The initial data length is length = 3 + 4 + 6 + 5 + 5 + 4 + 12; // id= + cmd= + start= + stop= + data= + 4*& + 6 bytes MAC sprintf(DataLen, "%d", cmd); length +=strlen(DataLen); sprintf(DataLen, "%d", start); length +=strlen(DataLen); sprintf(DataLen, "%d", end); length +=strlen(DataLen); sprintf(DataLen, "%10d", length); memset(header, 0, 250); // 250 should be enough for HTTP header except POST data part addLine(header, POSTDATA_LINE, cgiprogram); addLine(header, HOST_LINE, NULL); addLine(header, CONTENT_LINE, NULL); header_assember(header, "Connection: close\r\n"); addLine(header, LENGTH_LINE, DataLen); // Attn: the content-length number must be exactly equal to the size of POST data, //otherwise we cannot get the whole data on HTTP server side, or make server be waiting statement of receiving data // The first parameter device id header_assember(header, "id="); WF_GetMacAddress(macbuf.v); sprintf((char *)macstr,"%02X%02X%02X%02X%02X%02X&", macbuf.v[0], macbuf.v[1], macbuf.v[2], macbuf.v[3], macbuf.v[4], macbuf.v[5]); header_assember(header, macstr); // cmd for identifying the data usage header_assember(header, "cmd"); sprintf(DataLen, "=%d&", cmd); header_assember(header, DataLen); // starting time for collecting data header_assember(header, "start"); sprintf(DataLen, "=%d&", start); header_assember(header, DataLen); // ending time for collecting data header_assember(header, "stop"); sprintf(DataLen, "=%d&", end); header_assember(header, DataLen); // The last parameter in POST is collected data header_assember(header, "data="); return length; }
static void OutputMacAddress(void) { UINT8 mac[6]; int i; char buf[4]; WF_GetMacAddress(mac); for (i = 0; i < 6; ++i) { sprintf(buf, "%02X ", mac[i]); putsUART(buf); } putrsUART("\r\n"); }
/***************************************************************************** Function: static void OutputMacAddress(void) Summary: Outputs WiFi MAC address Description: Called by OuputDomain() Precondition: None Parameters: None Returns: None Remarks: None ***************************************************************************/ static void OutputMacAddress(void) { uint8_t mac[6]; int i; char buf[16]; WF_GetMacAddress(mac); SYS_CONSOLE_MESSAGE("MAC: "); for (i = 0; i < 6; ++i) { sprintf(buf, "%02X ", mac[i]); SYS_CONSOLE_MESSAGE(buf); } SYS_CONSOLE_MESSAGE("\r\n"); }
/***************************************************************************** * FUNCTION: IfconfigDisplayStatus * * RETURNS: None * * PARAMS: None * * NOTES: Responds to the user invoking ifconfig with no parameters *****************************************************************************/ static void IfconfigDisplayStatus(void) { UINT8 p_mac[6]; sprintf( (char *) g_ConsoleContext.txBuf, "\tIP addr: %d.%d.%d.%d", AppConfig.MyIPAddr.v[0], AppConfig.MyIPAddr.v[1], AppConfig.MyIPAddr.v[2], AppConfig.MyIPAddr.v[3] ); WFConsolePrintRamStr( (char *) g_ConsoleContext.txBuf , TRUE); WF_GetMacAddress(p_mac); sprintf( (char *) g_ConsoleContext.txBuf, "\tMAC addr: %02X:%02X:%02X:%02X:%02X:%02X", p_mac[0], p_mac[1], p_mac[2], p_mac[3], p_mac[4], p_mac[5]); WFConsolePrintRamStr( (char *) g_ConsoleContext.txBuf , TRUE); sprintf( (char *) g_ConsoleContext.txBuf, "\tNetmask: %d.%d.%d.%d", AppConfig.MyMask.v[0], AppConfig.MyMask.v[1], AppConfig.MyMask.v[2], AppConfig.MyMask.v[3] ); WFConsolePrintRamStr( (char *) g_ConsoleContext.txBuf , TRUE); sprintf( (char *) g_ConsoleContext.txBuf, "\tGateway: %d.%d.%d.%d", AppConfig.MyGateway.v[0], AppConfig.MyGateway.v[1], AppConfig.MyGateway.v[2], AppConfig.MyGateway.v[3] ); WFConsolePrintRamStr( (char *) g_ConsoleContext.txBuf , TRUE); #if defined(STACK_USE_DHCP_CLIENT) if ( DHCPIsEnabled(0) ) WFConsolePrintRomStr("\tDHCP: Started", TRUE); else WFConsolePrintRomStr("\tDHCP: Stopped", TRUE); #endif }