Пример #1
0
int core0_main(void)
{
    udp_pcb_t * udp;
    ip_addr_t addr;
    pbuf_t *p = (void*)0;//(pbuf_t *)pbuf_alloc_special(MEMP_PBUF);
    uint16 idx;
    uint16 total;

    /*
     * !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
     * Enable the watchdog in the demo if it is required and also service the watchdog periodically
     * */
    IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
    IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());

    /* Initialise the application state */
    g_AppCpu0.info.pllFreq = IfxScuCcu_getPllFrequency();
    g_AppCpu0.info.cpuFreq = IfxScuCcu_getCpuFrequency(IfxCpu_getCoreId());
    g_AppCpu0.info.sysFreq = IfxScuCcu_getSpbFrequency();
    g_AppCpu0.info.stmFreq = IfxStm_getFrequency(&MODULE_STM0);


    report.position = 0;

    IfxPort_Io_initModule(&conf);
    for (idx = 0; idx < conf.size; idx++)
    {
    	IfxPort_Io_ConfigPin *tbl = &conf.pinTable[idx];
    	IfxPort_setPinHigh(tbl->pin->port, tbl->pin->pinIndex); // P33.0 = 0
    }

    initStm0();

    /* Enable the global interrupts of this CPU */
    IfxCpu_enableInterrupts();

    /* Demo init */
    wMultican_init();

    Ifx_Lwip_Config config;

    IP4_ADDR(&config.ipAddr, 192, 168, 7, 123);
    IP4_ADDR(&config.netMask, 255, 255, 255, 0);
    IP4_ADDR(&config.gateway, 192, 168, 7, 6);
    MAC_ADDR(&config.ethAddr, 0x00, 0x20, 0x30, 0x40, 0x50, 0x60);

    Ifx_Lwip_init(&config);

    addr.addr8[3] = 6;
    addr.addr8[2] = 7;
    addr.addr8[1] = 168;
    addr.addr8[0] = 192;

    /* background endless loop */
    IfxPort_setPinHigh(&MODULE_P33, 6); // P33.0 = 0
    total = Ifx_g_Eth.config.phyLink();
    if (total == 1) {
    	report.phy_link = 1;
    } else {
    	report.phy_link = 0;
    }
    ethRam = NULL_PTR;

    udp = udp_new();
    while (TRUE)
    {
        Ifx_Lwip_pollTimerFlags();
        Ifx_Lwip_pollReceiveFlags();

        if (total != Ifx_g_Eth.config.phyLink()) {
        	total = Ifx_g_Eth.config.phyLink();
        	if (total == 1) {
    			IfxPort_setPinLow(&MODULE_P33, 6);
    			netif_set_up(&Ifx_g_Lwip.netif);
    			IfxEth_startTransmitter(Ifx_g_Lwip.netif.state);
    		} else {
    			netif_set_down(&Ifx_g_Lwip.netif);
    			IfxPort_setPinHigh(&MODULE_P33, 6);
    		}
        }

        report.phy_link = total;
        report.mdio_stat = IfxEth_Phy_Pef7071_MIIState();
        report.ethRam = ethRam!=NULL?1:0;

        wMultiCanNode0Demo_run(report, 0);

        if ((stat & 0x0003) != 0x01) {
            IfxPort_setPinLow(&MODULE_P33, 7);
        } else {
            IfxPort_setPinHigh(&MODULE_P33, 7);
        }
       	if (Ifx_g_Eth.config.phyLink() && (ethRam = IfxEth_getTransmitBuffer(&Ifx_g_Eth))) {
			p = (pbuf_t *)memp_malloc(MEMP_PBUF);
			if (p != NULL) {
				p->payload = LWIP_MEM_ALIGN((void *)((u8_t *)ethRam));
				p->len = 100;
				p->tot_len = p->len;
				p->next = NULL;
				p->ref = 1;
				p->type = PBUF_REF;
				udp_sendto_if(udp, p, &addr, 5001, &Ifx_g_Lwip.netif);
				pbuf_free(p);
				IfxPort_setPinLow(&MODULE_P33, 8); // P33.0 = 0
			}
        } else {
			IfxPort_setPinHigh(&MODULE_P33, 8); // P33.0 = 0
        }
        REGRESSION_RUN_STOP_PASS;
    }
	udp_remove(udp);

    return 0;
}
Пример #2
0
int dhcp_packet_parser(unsigned char *data, int data_len, struct dhcp_packet_info *dhcp_info) {
    struct bootp_msg *msg;
    unsigned char *p;
    unsigned char *end;
    int iphdr_len, udphdr_len;
    int dhcp_msg_type = 0;
    unsigned int lease_time = -1;
    int length = 0;
    char hostname[DHCP_HOSTNAME_MAX_LEN] = { 0 };
    unsigned char ifname[6] = {0};
    unsigned char uplink_mac[6] = {0};
    //char ifname_type[3] = "eth";
	
    /* IP header */
    struct iphdr *piphdr = (struct iphdr *)data;
    iphdr_len = piphdr->ihl * 4;

    /* UDP header */
    udphdr_len = sizeof(struct udphdr);

    /* For bootp Application data */
    msg = (struct bootp_msg *)(data + iphdr_len + udphdr_len);
    p = msg->options + 4;   /* offset of magic cookie */
    end = msg->options + sizeof(msg->options);
    /* ****** option structure *****
         * |-opt id-|-length-|-variable value-|
         */
    while (p < end) {
        switch(*p) {
	 case dhcpPrivateOption:
		length = p[1];
		_log(APP_DEBUG, "DHCP message private length: %d",length);
		os_memcpy(uplink_mac, &p[3 + (length - 18)], 6);
	       _log(APP_DEBUG, "nflog packet recv:"MAC_FORMAT, MAC_ADDR(uplink_mac));
		os_memcpy(ifname, &p[10 + (length - 18)], 4);
		_log(APP_DEBUG, "nflog packet recv sta type: %02x %02x %02x %02x", ifname[0], ifname[1], ifname[2], ifname[3]);
	       p += p[1];
	       p += 2;
		break;
        case endOption:
            goto OUT;
        case padOption:
            p++;
            break;
        case dhcpIPaddrLeaseTime:
            if (p[1]){
		#define GET_UINT32(_val) \
			memcpy (&_val, &p[2], sizeof (uint32_t));
		#define GET_UINT32_H(_val) \
			GET_UINT32 (_val); \
			_val = ntohl (_val);
		GET_UINT32_H(lease_time);
	     }
            p += p[1];
            p += 2;
            break;
        case hostName:
            if (p[1])
                os_memcpy(hostname, &p[2], MIN(p[1], DHCP_HOSTNAME_MAX_LEN));
            p += p[1];
            p += 2;
            break;
        case dhcpMessageType:
            if (p[1])
                dhcp_msg_type = p[2];
            p += p[1];
            p += 2;
            break;
        default:
            p += p[1];
            p += 2;
            break;
        }
    }
OUT:
    dhcp_info->dhcp_msg_type = dhcp_msg_type;
    _log(APP_DEBUG, "DHCP message type: %d", dhcp_msg_type);
    switch(dhcp_msg_type) {
    case DHCP_OFFER:
    case DHCP_ACK:     
        if(dhcp_msg_type == DHCP_ACK)
            inet_ntop(AF_INET, &msg->yiaddr, dhcp_info->sta_ip, INET_ADDRSTRLEN);
        dhcp_info->lease_time = lease_time;
        os_memcpy(dhcp_info->sta_mac, msg->chaddr, sizeof(dhcp_info->sta_mac));
        break;
    case DHCP_DISCOVER:
    case DHCP_REQUEST:
    //case DHCP_INFORM:
        inet_ntop(AF_INET, &msg->ciaddr, dhcp_info->sta_ip, INET_ADDRSTRLEN);
        os_memcpy(dhcp_info->sta_mac, msg->chaddr, sizeof(dhcp_info->sta_mac));
        os_memcpy(dhcp_info->sta_hostname, hostname, MIN(sizeof(dhcp_info->sta_hostname), DHCP_HOSTNAME_MAX_LEN));
        os_memcpy(dhcp_info->uplink_mac, uplink_mac, sizeof(dhcp_info->uplink_mac));
        os_memcpy(dhcp_info->ifname, ifname, sizeof(dhcp_info->ifname));
        break;
    case DHCP_RELEASE:
        os_memcpy(dhcp_info->sta_mac, msg->chaddr, sizeof(dhcp_info->sta_mac));
    case DHCP_NAK:
        os_memcpy(dhcp_info->sta_mac, msg->chaddr, sizeof(dhcp_info->sta_mac));
	 break;
    default:
        break;
    }    
    
    return 0;
}
Пример #3
0
/*
 * Allocate a beacon frame and fillin the appropriate bits.
 */
struct sk_buff *
ieee80211_beacon_alloc(struct ieee80211_node *ni,
	struct ieee80211_beacon_offsets *bo)
{
	struct ieee80211vap *vap = ni->ni_vap;
	struct ieee80211com *ic = ni->ni_ic;
	struct ieee80211_frame *wh;
	struct sk_buff *skb;
	int pktlen;
	u_int8_t *frm;
	struct ieee80211_rateset *rs;

	/*
	 * beacon frame format
	 *	[8] time stamp
	 *	[2] beacon interval
	 *	[2] capability information
	 *	[tlv] ssid
	 *	[tlv] supported rates
	 *	[7] FH/DS parameter set
	 *	[tlv] IBSS/TIM parameter set
	 *	[tlv] country code 
	 *	[3] power constraint
	 *	[5] channel switch announcement
	 *	[3] extended rate phy (ERP)
	 *	[tlv] extended supported rates
	 *	[tlv] WME parameters
	 *	[tlv] WPA/RSN parameters
	 *	[tlv] Atheros Advanced Capabilities
	 *	[tlv] AtherosXR parameters
	 * XXX Vendor-specific OIDs (e.g. Atheros)
	 * NB: we allocate the max space required for the TIM bitmap.
	 */
	rs = &ni->ni_rates;
	pktlen = 8					/* time stamp */
		 + sizeof(u_int16_t)			/* beacon interval */
		 + sizeof(u_int16_t)			/* capability information */
		 + 2 + ni->ni_esslen			/* ssid */
		 + 2 + IEEE80211_RATE_SIZE		/* supported rates */
		 + 7 					/* FH/DS parameters max(7,3) */
		 + 2 + 4 + vap->iv_tim_len		/* IBSS/TIM parameter set*/
		 + ic->ic_country_ie.country_len + 2	/* country code */
		 + 3					/* power constraint */
		 + 5					/* channel switch announcement */
		 + 3					/* ERP */
		 + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE) /* Ext. Supp. Rates */
		 + (vap->iv_caps & IEEE80211_C_WME ?	/* WME */
			sizeof(struct ieee80211_wme_param) : 0)
		 + (vap->iv_caps & IEEE80211_C_WPA ?	/* WPA 1+2 */
			2 * sizeof(struct ieee80211_ie_wpa) : 0)
		 + sizeof(struct ieee80211_ie_athAdvCap)
#ifdef ATH_SUPERG_XR
		 + (ic->ic_ath_cap & IEEE80211_ATHC_XR ?	/* XR */
			sizeof(struct ieee80211_xr_param) : 0)
#endif
		 ;
	skb = ieee80211_getmgtframe(&frm, pktlen);
	if (skb == NULL) {
		IEEE80211_NOTE(vap, IEEE80211_MSG_ANY, ni,
			"%s: cannot get buf; size %u", __func__, pktlen);
		vap->iv_stats.is_tx_nobuf++;
		return NULL;
	}

	SKB_NI(skb) = ieee80211_ref_node(ni);

	frm = ieee80211_beacon_init(ni, bo, frm);

	skb_trim(skb, frm - skb->data);

	wh = (struct ieee80211_frame *)
		skb_push(skb, sizeof(struct ieee80211_frame));
	wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_MGT |
		IEEE80211_FC0_SUBTYPE_BEACON;
	wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
	wh->i_dur = 0;
	IEEE80211_ADDR_COPY(wh->i_addr1, ic->ic_dev->broadcast);
	IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
	IEEE80211_ADDR_COPY(wh->i_addr3, vap->iv_bssid);
	IEEE80211_DPRINTF(vap, IEEE80211_MSG_ASSOC,
			  "%s: beacon bssid:" MAC_FMT "\n",
			  __func__, MAC_ADDR(wh->i_addr3));
	*(u_int16_t *)wh->i_seq = 0;

	return skb;
}