Example #1
0
/*-------------------------------------------------------------------------
	Description:	
		interface to start sta direct config process
		
	Arguments:
        	MinRssiFilter - specify the least rssi of peer ap to listen to
        				-1 ~ -127: the rssi Threshold, ap with rssi below which will be ignored
        				other: not filter by rssi
        	TryPeerNum - max number of peer ap, we try to listen to
        				0 - no restrictiion
        				other - the max number of ap

        	pCustomStr - custom string buffer(maximum 10 ascii characters), could be NULL if no custom data to receive
        	
	Return Value:
		0 - success
		other - failure
		
	Note: 
		Direct config is used for sta to get settings of ap for connection at first time,
		this function must cooperate with the matched application run in pc, smart phone, pad, etc..
		
		This interface will start wifi internally, so don`t call InfWiFiStart any more.
		
		When the process succeeds, the ssid and key data will be filled in SysParam.WiFiCfg
-------------------------------------------------------------------------*/
INT32 InfDirectCfgStart(INT8 MinRssiFilter, UINT8 TryPeerNum, UINT8 *pCustomStr)
{
	INT8U MsgBody[6] = {0};

	MsgBody[0] = MinRssiFilter;
	MsgBody[1] = (INT8U)TryPeerNum;
	if (pCustomStr)
		NST_MOVE_MEM((INT8U *)(&MsgBody[2]), &pCustomStr, 4);

	PostTaskMsg(gpMacMngTskMsgQ, MLME_DIRECT_CFG_ID, (PUINT8)MsgBody, 6);
	return 0;
}
Example #2
0
/*-------------------------------------------------------------------------
	Description:	
		set ssid
	Arguments:
		pSsid - ssid string
		SsidLen - ssid length (1 ~ 32)
		
	Return Value:
		0 - success
		other - failure
	Note:	
		
-------------------------------------------------------------------------*/
INT32 InfSsidSet(UINT8 *pSsid, UINT8 SsidLen)
{
	if (pSsid == NULL || SsidLen > 32 || SsidLen == 0)
	{
		SysParam.WiFiCfg.Ssid[0] = 0; 
		return -1;
	}

	NST_MOVE_MEM(SysParam.WiFiCfg.Ssid, pSsid, SsidLen);
	SysParam.WiFiCfg.Ssid[SsidLen] = 0;
	return 0;
}
Example #3
0
/*-------------------------------------------------------------------------
	Description:	
		set beacon period for softap or adhoc mode
	Arguments:
		BcnPrd - beacon period (ms), must be equal or larger than 100ms
		NotifyPeerEn - notify all peers to reconnect local softap, 0 - not notify, other - notify
		                     invalid in adhoc mode
		
	Return Value:
		0 - success
		other - failure
	Note:	
-------------------------------------------------------------------------*/
INT32  InfBeaconPeriodSet(UINT16 BcnPrd, UINT8 NotifyPeerEn)
{
	INT8U MsgBody[3] = {0};

	if (BcnPrd < 100)
		return -1;

	NST_MOVE_MEM((INT8U *)MsgBody, (INT8U *)&BcnPrd, 2);
	MsgBody[2] = NotifyPeerEn;
	
	PostTaskMsg(gpMacMngTskMsgQ, MLME_BCN_PRD_SET_ID, (PUINT8)MsgBody, sizeof(MsgBody));
	return 0;
}
VOID FaultHandler_c(UINT32 * FaultArgs)
{
    UINT32 StackedR0;
    UINT32 StackedR1;
    UINT32 StackedR2;
    UINT32 StackedR3;
    UINT32 StackedR12;
    UINT32 StackedLR;
    UINT32 StackedPC;
    UINT32 StackedPSR;

    StackedR0 = (UINT32)FaultArgs[0];
    StackedR1 = (UINT32)FaultArgs[1];
    StackedR2 = (UINT32)FaultArgs[2];
    StackedR3 = (UINT32)FaultArgs[3];
    StackedR12 = (UINT32)FaultArgs[4];
    StackedLR = (UINT32)FaultArgs[5];
    StackedPC = (UINT32)FaultArgs[6];
    StackedPSR = (UINT32)FaultArgs[7];

    // dump common regs and fault regs
    NST_MOVE_MEM((UINT8*)DUMP_STACK_ADR, FaultArgs, DUMP_REG_SIZE);
    NST_MOVE_MEM((UINT8*)(DUMP_STACK_ADR + DUMP_REG_SIZE), (UINT8*)SCB_BASE, sizeof(SCB_TypeDef));
    
    DBGPRINT(DEBUG_ERROR, "FaultException\n");
    DBGPRINT(DEBUG_ERROR, "R0(0x%0X), R1(0x%0X), R2(0x%0X), R3(0x%0X)\n", StackedR0, StackedR1, StackedR2, StackedR3);
    DBGPRINT(DEBUG_ERROR, "R12(0x%0X), LR(0x%0X), PC(0x%08X), PSR(0x%0X)\n", StackedR12, StackedLR, StackedPC, StackedPSR);
    DBGPRINT(DEBUG_ERROR, "BFAR(0x%0X), MMFAR(0x%0X), CFSR(0x%0X), HFSR(0x%0X)\n", 
        NST_SCB->BFAR, NST_SCB->MMFAR, 
        NST_SCB->CFSR, NST_SCB->HFSR);
    DBGPRINT(DEBUG_ERROR, "AFSR(0x%0X), DFSR(0x%0X)\n", 
        NST_SCB->AFSR, NST_SCB->DFSR);
	
    // clear FSR
    NST_SCB->HFSR = 0;
    NST_SCB->AFSR = 0;
    NST_SCB->DFSR = 0;
}
Example #5
0
/*-------------------------------------------------------------------------
	Description:	
		set dns server enable, only useful in softap mode
	Arguments:
		Enable - 0 - disable, other - enable
		DnsName - local dns name
		DnsNameLen - local dns name length

	Return Value:
		0 - success
		other - failure
	Note:	
		
-------------------------------------------------------------------------*/
INT32 InfDnsSrvSet(UINT8 Enable, UINT8 *DnsName, UINT8 DnsNameLen)
{
	if (Enable)
	{
		if (DnsName == NULL || DnsNameLen > 32)
			return -1;
		SysParam.bDnsServer = 1;
		NST_MOVE_MEM(SysParam.DnsName, DnsName, DnsNameLen);
	}
	else
		SysParam.bDnsServer = 0;

	return 0;
}
Example #6
0
/*-------------------------------------------------------------------------
	Description:	
		set key data
	Arguments:
		Index - key index, only useful in wep encryption mode (0 ~ 3)
		KeyBuf - key data buffer
		KeyLen - key length (restricted by encryption mode)
		
	Return Value:
		0 - success
		other - failure
	Note:	
		
-------------------------------------------------------------------------*/
INT32 InfKeySet(UINT8 Index, UINT8 *KeyBuf, UINT8 KeyLen)
{
	if (Index > 3 || KeyBuf == NULL || KeyLen > 64)
		return -1;

	SysParam.WiFiCfg.KeyIndex = Index;
	SysParam.WiFiCfg.KeyLength = KeyLen;
	NST_MOVE_MEM(SysParam.WiFiCfg.PSK, KeyBuf, KeyLen);

	if (KeyLen < 64)
		SysParam.WiFiCfg.PSK[KeyLen] = 0;
	
	return 0;
}
Example #7
0
/*-------------------------------------------------------------------------
	Description:	
		interface to start wps
		
	Arguments:
		WscMode - wps work mode, check PARAM_WSC_MODE for detail
		PinCode - wps pin code ( set peer netcard pin code when start AP WPS PIN mode, otherwise set 0)
		
	Return Value:
		0 - success
		other - failure
		
	Note: 

-------------------------------------------------------------------------*/
INT32 InfWPSStart(UINT8 WscMode, UINT32 PinCode)
{
       INT8U MsgBody[5] = {0};

	DBGPRINT_WSC(DEBUG_TRACE,"-----------InfWPSStart ---------\n");
	if (WscMode > PARAM_WSC_MODE_PBC)
		return -1;
	   	
#ifdef AP_WSC_INCLUDED
      if (WscMode == PARAM_WSC_MODE_PIN)
	    NST_MOVE_MEM((INT8U *)MsgBody, (INT8U *)&PinCode, 4);
#endif

	MsgBody[4] = (UINT8)WscMode;
	PostTaskMsg(gpMacMngTskMsgQ, MLME_WPS_START_SET_ID, (PUINT8)MsgBody, 5);
	return 0;
}
Example #8
0
/*-------------------------------------------------------------------------
	Description:	
		start an scan operation
	Arguments:
	
       pScanTable -  buffer to store the scan result, InfoCount field indicate the max buffer size
       			when scan result update, InfoCount field indicate the actual scan info number (1~16)

	MinRssiFilter - specify the least rssi of scan record
				-1 ~ -127: the rssi Threshold, scan records below which will be filterred
				other: not filter by rssi

	ScanType -   0 active scan, other  passive scan

	Return Value:
		0 - success
		other - failure
		
	Note:	
	scan result will update to the ScanTable when event SYS_EVT_SCAN_DONE generate
-------------------------------------------------------------------------*/
INT32 InfScanStart(SCAN_INFO_TABLE * pScanTable, INT8 MinRssiFilter, INT8 ScanType)
{
	INT8 MsgBody[6] = {0};

	if (!pScanTable || pScanTable->InfoCount == 0)
		return -1;

	if (MinRssiFilter > 0)
		MinRssiFilter = 0;

	NST_MOVE_MEM((INT8U *)MsgBody, &pScanTable, 4);
	MsgBody[4] = MinRssiFilter;
	MsgBody[5] = ScanType;
	
	PostTaskMsg(gpMacMngTskMsgQ, MLME_SCAN_REQUEST_ID, (PUINT8)MsgBody, 6);
	return 0;
}
static VOID _DHCPNakGenAndSend(INT8U * pClientMacAddr, INT32U Xid)
{
	INT32U Len;
	INT8U * Body;
	PDHCP_MSG pDhcpMsg;
	struct pbuf * pDhcpBuf;

	pDhcpBuf = pbuf_alloc(PBUF_TRANSPORT, sizeof(DHCP_MSG), PBUF_RAM);
	if(pDhcpBuf == NULL)
	{
		return;
	}
	
	pDhcpMsg = &DhcpMsg;
	memset(pDhcpMsg, 0, sizeof(*pDhcpMsg));

	/* Initialize the DHCP message header. */
	pDhcpMsg->Op = DHCP_OP_REPLY;
	pDhcpMsg->HType = DHCP_HWTYPE_ETHERNET;
	pDhcpMsg->HLen = 6;
	pDhcpMsg->Xid = htonl(Xid);
	pDhcpMsg->Siaddr = DhcpServer.ServerIpAddr.addr;
	NST_MOVE_MEM(pDhcpMsg->Chaddr, pClientMacAddr, 6);
	pDhcpMsg->Magic = htonl(DHCP_MAGIC);

	Len = 240;
	Body = &pDhcpMsg->Options[0];

	/* Set the message type. */
	DHCP_SET_OPTION_MSG_TYPE(Body, DHCP_MSG_NAK, Len);

	DHCP_SET_OPTION_END(Body, Len);

	pbuf_take(pDhcpBuf, (const VOID *)pDhcpMsg, Len);
	pbuf_realloc(pDhcpBuf, Len);

	/* Send broadcast to the DHCP client. */
	udp_sendto(DhcpServer.Socket, pDhcpBuf, IP_ADDR_BROADCAST, DHCP_CLIENT_UDP_PORT);
	pbuf_free(pDhcpBuf);
}
Example #10
0
INT32  BSP_NvInfoInit(VOID)
{
    PNV_INFO pNvInfo = (PNV_INFO)&EeBuffer;

#ifndef USE_NV_INFO

    //
    // 1: USE DEFAULT PARAM
    //
    NST_MOVE_MEM(pNvInfo->MaxTxPwr, DefaultTxPwrIdxTbl, sizeof(pNvInfo->MaxTxPwr));

#else   // USE_NV_INFO

    //
    // 2: USE FLASH PARAM
    //
    {
        {
#ifdef NULINK2_SOC
            BSP_QSpiInit(DEFAULT_QSPI_CLK);
#else
            BSP_SpiInit();
#endif

#ifdef NULINK2_SOC
            QSpiFlashRead(NV_INFO_START, (UINT8*)pNvInfo, sizeof(NV_INFO));
#else
            SpiFlashRead(NV_INFO_START, (UINT8*)pNvInfo, sizeof(NV_INFO));
#endif
        }
        
    }

    // CHECK PARAM
    CheckParam(pNvInfo);
            
#endif // USE_NV_INFO
    
    return NST_STATUS_SUCCESS;
}
Example #11
0
static VOID CheckParam(PNV_INFO pNvInfo)
{
extern BOOL_T CheckAuthCode(VOID);
extern  const UINT8    ZERO_MAC_ADDR[MAC_ADDR_LEN];
#define COPY_MAC_ADDR(Addr1, Addr2)             NST_MOVE_MEM((Addr1), (Addr2), MAC_ADDR_LEN)
#define MAC_ADDR_IS_GROUP(Addr)       (((Addr[0]) & 0x01))
#define TX_GAIN_MAP_TBL_SIZE     0x28//0x26

    UINT32  i = 0;

    // CHECK TX PWR
    for (i=0; i<MAX_TXPOWER_ARRAY_SIZE*MAX_CH_NUM; i++)
        if (*((PUINT8)&pNvInfo->MaxTxPwr[0] + i) > (TX_GAIN_MAP_TBL_SIZE-1))
        {
            *((PUINT8)&pNvInfo->MaxTxPwr[0] + i) = *((PUINT8)&DefaultTxPwrIdxTbl[0] + i);
        }
    if (i != MAX_TXPOWER_ARRAY_SIZE*MAX_CH_NUM)
    {
        DBGPRINT(DEBUG_INFO, "Power of NvInfo is invalid [%d] = 0x%0x \n", i, *((PUINT8)&pNvInfo->MaxTxPwr[0] + i));
        NST_MOVE_MEM(pNvInfo->MaxTxPwr, DefaultTxPwrIdxTbl, sizeof(pNvInfo->MaxTxPwr));
    }

    // CHECK MAC ADDR
    if ((!MAC_ADDR_IS_GROUP(pNvInfo->MacAddr)) && (!NST_EQUAL_MEM(pNvInfo->MacAddr, ZERO_MAC_ADDR, MAC_ADDR_LEN)))
        COPY_MAC_ADDR(PermanentAddress, pNvInfo->MacAddr);

#ifdef CHECK_AUTH_CODE
    if (CheckAuthCode() == NST_FALSE)
    {
        DBGPRINT(DEBUG_TRACE, "Check auth code failed, dead loop\n");
        while (1)
            ;
    }
#endif

}
static PDHCP_CLIENT _ClientTableLookup(INT8U * MacAddr, INT8U MsgType, INT32U ReqIpAddr, INT32U ServerId)
{
	INT8U i;
	INT8U IpUnavailable;
	PDHCP_CLIENT pClient;
	PDHCP_CLIENT pFreeClient;
	PDHCP_CLIENT pReqClient;
	PDHCP_CLIENT pMyHistoryClient;
	PDHCP_CLIENT pHistoryClient;
	PDHCP_CLIENT pMyClient;
	PDHCP_CLIENT pReturnClient;

	pFreeClient = NULL;
	pReqClient = NULL;
	pHistoryClient= NULL;
	pMyHistoryClient = NULL;
	pMyClient = NULL;
	pReturnClient = NULL;
	IpUnavailable = 0;
	
	for(i = 0; i < DHCPS_HISTORY_CLIENT_NUM; i++)
	{
		pClient = &DhcpServer.Clients[i];
		if(pClient->State == DHCP_CLIENT_STATE_IDLE)
		{	
			if((pMyHistoryClient == NULL) && (memcmp(pClient->MacAddr, MacAddr, 6) == 0))
			{
				/* Get my history entry. */
				pMyHistoryClient = pClient;
			}

			if((pReqClient == NULL) && ip_addr_cmp(&pClient->IpAddr, (struct ip_addr *)&ReqIpAddr) )
			{
				/* Get the idle entry that hold my requested ip address. */
				pReqClient = pClient;
			}

			if((pFreeClient == NULL) && (memcmp(pClient->MacAddr, "\x00\x00\x00\x00\x00\x00", 6) == 0) )
			{
				/* Get the first free entry. */
				pFreeClient = pClient;
			}

			if((pHistoryClient == NULL) && (memcmp(pClient->MacAddr, "\x00\x00\x00\x00\x00\x00", 6) != 0))
			{
				/* Get the first histoy entry that not belong to me. */
				pHistoryClient = pClient;
			}
		}
		else
		{
			if(memcmp(pClient->MacAddr, MacAddr, 6) == 0)
			{
				/* Is negotiating ip address or has negotiated now. */
				pMyClient = pClient;
			}
			else if(ip_addr_cmp(&pClient->IpAddr, (struct ip_addr *)&ReqIpAddr))
			{
				/* The requested ip address is allocated. */
				IpUnavailable = 1;
			}
		}
	}

	switch(MsgType)
	{
		case DHCP_MSG_DISCOVER:
			if(pMyClient)
			{
				/* Amazing!!The client restart the negotiation. */
				pMyClient->State = DHCP_CLIENT_STATE_IDLE;
				
				if(pReqClient)
				{
					/* The client request another ip address and that address is not allocated now. */
					if(pMyClient->State != DHCP_CLIENT_STATE_BIND)
					{
						memset(pMyClient->MacAddr, 0, 6);
					}
					pReturnClient = pReqClient;
				}
				else
				{
					/* The client request the same ip address. */
					pReturnClient = pMyClient;
				}
			}
			else
			{
				/* A new negotiation! */

				/*
					The IP address allocation priority(high to low):
					1. the client's request ip address.
					2. the client's history ip address.
					3. a totally free ip address.
					4. the other client's history ip address.
				*/
				if(pReqClient)
				{
					/* The client's request ip address. */
					pReturnClient = pReqClient;
				}
				else if(pMyHistoryClient)
				{
					/* The client's history ip address. */
					pReturnClient = pMyHistoryClient;
				}
				else if(pFreeClient)
				{
					/* A totally free ip address. */
					pReturnClient = pFreeClient;
				}
				else if(pHistoryClient)
				{
					/* The other client's history ip address. */
					pReturnClient = pHistoryClient;
				}
				else
				{
					/* The IP pool is full, so return null. */
					pReturnClient = NULL;
				}
			}
			break;

		case DHCP_MSG_REQUEST:
			if(pMyClient)
			{
				if(IpUnavailable == 1)
				{
					/* The client request a new address that was allocated, so return null. */
					pReturnClient = NULL;
					
					if(pMyClient->State != DHCP_CLIENT_STATE_BIND)
					{
						memset(pMyClient->MacAddr, 0, 6);
					}
					pMyClient->State = DHCP_CLIENT_STATE_IDLE;
				}
				else
				{
					if(pReqClient)
					{
						/* The client request a new address that is not allocated. */
						if(pMyClient->State != DHCP_CLIENT_STATE_BIND)
						{
							memset(pMyClient->MacAddr, 0, 6);
						}
						pMyClient->State = DHCP_CLIENT_STATE_IDLE;

						if((ServerId == 0) || (DhcpServer.ServerIpAddr.addr == ServerId))
						{
							/* The client request the new address and that is free, allocate it. */
							pReturnClient = pReqClient;
						}
						else
						{
							/* The client refuses my offer and request another ip address. */
							pReturnClient = NULL;
						}
					}
					else if((ServerId == 0) || (DhcpServer.ServerIpAddr.addr == ServerId))
					{
						/* The client request this address that has been allocated to it(a little abnorm) or the client renew the lease time. */
						pReturnClient = pMyClient;
					}
					else
					{
						/* The client refuses my offer. */
						pReturnClient = NULL;
					}
				}
			}
			else
			{
				if(IpUnavailable == 1)
				{
					/* The requested ip address was allocated, so return null. */
					pReturnClient = NULL;
				}
				else if((ServerId == 0) || (DhcpServer.ServerIpAddr.addr == ServerId))
				{
					/* The client request my free address, so allocate it. */
					pReturnClient = pReqClient;
				}
				else
				{
					/* The client request the address from another server, but send it to me, so return null. */
					pReturnClient = NULL;
				}
			}
			break;

		case DHCP_MSG_RELEASE:
			/* The client release the ip address. */
			if(pMyClient)
			{
				if(pMyClient->State != DHCP_CLIENT_STATE_BIND)
				{
					memset(pMyClient->MacAddr, 0, 6);
				}
				pMyClient->State = DHCP_CLIENT_STATE_IDLE;
			}
			pReturnClient = NULL;
			break;

		case DHCP_MSG_DECLINE:
			/* The client refuses my offer directly. */
			if(pMyClient)
			{
				if(pMyClient->State != DHCP_CLIENT_STATE_BIND)
				{
					memset(pMyClient->MacAddr, 0, 6);
				}
				pMyClient->State = DHCP_CLIENT_STATE_IDLE;
			}
			pReturnClient = NULL;
			break;

		default:
			/* Dropped the other frames. */
			pReturnClient = NULL;
			break;
	}

	if(pReturnClient)
	{
		/* Updata the client's MAC address. */
		NST_MOVE_MEM(pReturnClient->MacAddr, MacAddr, 6);
	}

	return pReturnClient;
}