Пример #1
0
static void _ZCLLDisable(TCPIP_NET_IF* pNetIf)
{
    ZCLL_NET_HANDLE *hZcll;

    hZcll = (phZCLL+TCPIP_STACK_NetIxGet(pNetIf));
    TCPIP_ARP_CallbacksDeregister(hZcll->arpRegId);
    hZcll->zcll_state = SM_INIT;   //  stop the ZCLL state machine
    pNetIf->Flags.bIsZcllEnabled = false;
}
Пример #2
0
static bool _ZCLLEnable(TCPIP_NET_IF* pNetIf)
{
    ZCLL_NET_HANDLE* hZcll;

    hZcll = (phZCLL+TCPIP_STACK_NetIxGet(pNetIf));
    hZcll->arpRegId = TCPIP_ARP_CallbacksRegister(&callbacks);
    if(hZcll->arpRegId <0)
    {
        hZcll->zcll_state = SM_INIT;   //  should already be in idle state
        SYS_ERROR(SYS_ERROR_ERROR, "_ZCLLEnable: ARP registration Failed!!! \r\n");
        return false;
    }

    pNetIf->Flags.bIsZcllEnabled = true;
    hZcll->zcll_state = SM_ADDR_INIT;
    return true;
}
Пример #3
0
/***************************************************************
  Function:
static void _ZeroconfARPPktNotify ( TCPIP_NET_IF*  pNetIf
                                 ,uint32_t SenderIPAddr
                                 ,uint32_t TargetIPAddr
                                 ,TCPIP_MAC_ADDR* SenderMACAddr
                                 ,TCPIP_MAC_ADDR* TargetMACAddr
                                 ,uint8_t op_req)

  Summary:
   Callback registered with ARP-Module. This gets invoked from ARP-
    module and runs in the same context.

  Description:
   This function is registered as a callback with ARP-module to get
    notified about incoming Packet-events. Based on the type of packet
    received and Link-Local current state, appropriate action will be
    taken. To find the type of ARP-Packet this function makes use of
    _FindARPPktType routine.

    Primary purpose of this function is to decipher the ARP-Packet rxed
    and check whether its leading to a conflict with the selected IP-
    address.

    Two types of conflicts are defined: Probe-Conflict and Late-Conflict
    If the current state of Link-Local is Probe/Claim and a conflict is
    detected its called "Probe-Conflict"
    If the current state of Link-Local is Defend-state and a conflict is
    detected its called "Late-Conflict"

  Parameters:
   SenderIPAddr    - Sender IP-Address
    TargetIPAddr    - Target IP-Address
    SenderMACAddr   - Sender MAC-Address
    TargetMACAddr   - Target MAC-Address
    op_req          - Operation-Request (ARP-Request/Response)

  Returns:
     None
  ***************************************************************/
static void _ZeroconfARPPktNotify ( TCPIP_NET_IF*  pNetIf
                                 ,uint32_t SenderIPAddr
                                 ,uint32_t TargetIPAddr
                                 ,TCPIP_MAC_ADDR* SenderMACAddr
                                 ,TCPIP_MAC_ADDR* TargetMACAddr
                                 ,uint8_t op_req)
{
    ARP_PKT_TYPE pkt_type;
    ZCLL_NET_HANDLE *hZcll;

    int i;

    pkt_type = _FindARPPktType (SenderIPAddr, TargetIPAddr, op_req);

    if(pkt_type == UNKNOWN_TYPE)
        return; // Can't hit this

    i = TCPIP_STACK_NetIxGet(pNetIf);
    hZcll =(phZCLL+i);

    switch (hZcll->zcll_state)
    {
        case SM_ADDR_PROBE:
        case SM_ADDR_CLAIM:
            {
                switch(pkt_type)
                {
                    case ARP_PROBE_TYPE:
                    case ARP_CLAIM_TYPE:
                    case ARP_DEFEND_TYPE:
                        if(hZcll->temp_IP_addr.Val == TargetIPAddr ) // Probe-Conflict
                        {
                            if(memcmp(SenderMACAddr, &pNetIf->netMACAddr.v, 6))
                            {
                                hZcll->zcll_flags.probe_conflict =1;
                            }
                        }
                        break;

                    case ARP_RESPONSE_TYPE:
                        /* Some-body has been using probed addr
                         * We need to choose different Address */
                        if(hZcll->temp_IP_addr.Val == SenderIPAddr)
                        {
                            INFO_ZCLL_PRINT("IP address conflict. Please wait...\r\n");
                            hZcll->zcll_flags.probe_conflict =1;
                        }
                        break;
                    default:
                        break;
                }
            }
            break;

        case SM_ADDR_DEFEND:
            if(pNetIf->netIPAddr.Val == SenderIPAddr)
            {
                if(memcmp(SenderMACAddr, &pNetIf->netMACAddr, 6))
                {
                    INFO_ZCLL_PRINT("Zero Conf is defending the IP address\r\n");
                    hZcll->zcll_flags.late_conflict = 1;
                }
            }
            break;

        default:
            break; // Nothing to do in other states
    }

}
Пример #4
0
/*********************************************************************
 * Function:        bool TCPIP_ANNOUNCE_Task(void)
 *
 * Summary:         Announce callback task.
 *
 * PreCondition:    Stack is initialized()
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Recurring task used to listen for Discovery
 *                  messages on the specified TCPIP_ANNOUNCE_PORT.  These
 *                  messages can be sent using the TCP/IP
 *                  Discoverer tool. If one is received, this
 *                  function will transmit a reply.
 *
 * Note:            A UDP socket must be available before this 
 *					function is called.  It is freed at the end of 
 *					the function.  UDP_MAX_SOCKETS may need to be 
 *					increased if other modules use UDP sockets.
 ********************************************************************/
bool TCPIP_ANNOUNCE_Task(TCPIP_NET_IF * pNetIf)
{
	uint8_t 		    i;
    int                 netIx;
    UDP_SOCKET          s;

    if(!pNetIf)
    {
        return false;
    }
    else
    {
        netIx = TCPIP_STACK_NetIxGet(pNetIf);
    }
    
    s = announceDcpt.skt;

	switch(announceDcpt.sm)
	{
		case DISCOVERY_HOME:
			// Open a UDP socket for inbound and outbound transmission
			// Allow receive on any interface 
			s = TCPIP_UDP_ServerOpen(IP_ADDRESS_TYPE_IPV4, TCPIP_ANNOUNCE_PORT, 0);

			if(s == INVALID_UDP_SOCKET)
            {
				return false;
            }

            if(!TCPIP_UDP_RemoteBind(s, IP_ADDRESS_TYPE_IPV4, TCPIP_ANNOUNCE_PORT,  0))
            {
                TCPIP_UDP_Close(s);
                break;
            }

            if(!TCPIP_UDP_OptionsSet(s, UDP_OPTION_STRICT_PORT, (void*)true))
            {
                TCPIP_UDP_Close(s);
                break;
            }

			announceDcpt.skt = s;
            announceDcpt.sm++;
			break;

		case DISCOVERY_LISTEN:
			// Do nothing if no data is waiting
			if(!TCPIP_UDP_GetIsReady(s))
				return false;
			
			// See if this is a discovery query or reply
			TCPIP_UDP_Get(s, &i);
			TCPIP_UDP_Discard(s);
			if(i != 'D')
				return false;

			// We received a discovery request, reply when we can
			announceDcpt.sm++;
			// No break needed.  If we get down here, we are now ready for the DISCOVERY_REQUEST_RECEIVED state

		case DISCOVERY_REQUEST_RECEIVED:
            ANNOUNCE_Notify (pNetIf, DHCP_EVENT_BOUND, NULL);   // fake a legitimate DHCP event		
			// Listen for other discovery requests
			announceDcpt.sm = DISCOVERY_LISTEN;
			break;

		case DISCOVERY_DISABLED:
			break;
	}	

    return true;
}