示例#1
0
文件: bnep.c 项目: ghent360/bluez
static bool filter_multaddr_req(struct bnep_frame *bnep_frame, uint8_t indent)
{
	struct l2cap_frame *frame = &bnep_frame->l2cap_frame;
	uint16_t length;
	char start_addr[20], end_addr[20];
	int i;

	if (!l2cap_frame_get_be16(frame, &length))
		return false;

	print_field("%*cLength: 0x%04x", indent, ' ', length);

	for (i = 0; i < length / 12; i++) {

		if (!get_macaddr(bnep_frame, start_addr))
			return false;

		if (!get_macaddr(bnep_frame, end_addr))
			return false;

		print_field("%*c%s - %s", indent, ' ', start_addr, end_addr);
	}

	return true;
}
示例#2
0
int main(int argc, char* argv[])
{
    process_arg(argc,argv);
    tcpudp_fd=open_socket();
    assert(tcpudp_fd>0);
    if(server)
        server_accept(NULL);
    tun_fd=tun_alloc(tun_name,IFF_TAP);
    assert(tun_fd>0);
    get_macaddr();
    write_n(tcpudp_fd,tun_mac,6);
    getack();
    if(pthread_create(&pt_read_from_if,NULL,read_from_if,NULL)!=0){
        perror("pthread_create");
        exit(-1);
    }
    if(pthread_create(&pt_read_from_sock,NULL,read_from_sock,NULL)!=0){
        perror("pthread_create");
        exit(-1);
    }
    printf("engin started, main() going to sleep\n");
    pthread_join(pt_read_from_if,NULL);
    pthread_join(pt_read_from_sock,NULL);
    return 0;
}
示例#3
0
int raw_send(char *net_i, uint16_t ether_type, uint8_t *ptr, int len)
{
    int fd;
    int ifindex = 0;
    uint8_t *buf = NULL;
    char *device = NULL;
    struct sockaddr_ll sll;
    uint16_t n_ethtype;
    char dmac[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
    char smac[6];

    raw_print("line: %d.\n", __LINE__);
    if (net_i) {
        device = net_i;
        if (get_macaddr(device, smac)) {
            memset(smac, 0x88, 6);
        }
    } else {
        device = "lo";
        memset(smac, 0x88, 6);
    }
    if ((ifindex = get_ifindex(device)) <= 0) {
        return -1;
    }
    n_ethtype = htons(ether_type);
    if ((fd = socket(AF_PACKET, SOCK_RAW, n_ethtype)) < 0) {
        printf("create socket failed.\n");
        return fd;
    }
    raw_print("line: %d.\n", __LINE__);

    bzero(&sll, sizeof(sll));
    sll.sll_family = AF_PACKET;
    sll.sll_halen = 6;
    //memcpy(sll.sll_addr, dmac, 6);
    sll.sll_ifindex = ifindex;
    sll.sll_protocol = n_ethtype;

    bind(fd, (struct sockaddr *)&sll, sizeof(sll));
    if (strlen((char *)ptr) == 0) {
        ptr = (uint8_t *)"xuchunxiao";
        len = strlen((char *)ptr);
    }
    buf = malloc(len + 14);
    memcpy(buf, dmac, 6);
    memcpy(buf + 6, smac, 6);
    memcpy(buf + 12, &n_ethtype, 2);
    memcpy(buf + 14, ptr, len);
    raw_print("line: %d.\n", __LINE__);
    if (sendto(fd, buf, len + 14, 0, (struct sockaddr *)&sll, sizeof(sll)) < 0) {
        perror("sendto error.\n");
        return -1;
    }
    raw_print("line: %d.\n", __LINE__);
    free(buf);
    close(fd);
    return 0;
}
示例#4
0
u08 eth_find_interface( mac_addr dest )
{
	if (mac_equal( dest, get_macaddr() ))
		return IFACE_INTERNAL;

	if (mac_equal( dest, broadcast_mac ))
		return IFACE_BROADCAST;

	return IFACE_WAN;
}
示例#5
0
文件: bnep.c 项目: ghent360/bluez
static bool bnep_general(struct bnep_frame *bnep_frame,
					uint8_t indent,	int hdr_len)
{
	struct l2cap_frame *frame;
	char src_addr[20], dest_addr[20];

	if (!get_macaddr(bnep_frame, dest_addr))
		return false;

	if (!get_macaddr(bnep_frame, src_addr))
		return false;

	frame = &bnep_frame->l2cap_frame;

	if (!l2cap_frame_get_be16(frame, &proto))
		return false;

	print_field("%*cdst %s src %s [proto 0x%04x] ", indent,
					' ', dest_addr, src_addr, proto);

	return true;

}
示例#6
0
void udp_send( udp_sock sock, u32 to_ip, u16 to_port, u08 const * data, u16 len )
{
	udp_conn * conn = &udp_conns[sock];
	u08 iface;

	if (!conn->handler)
	{
		log_printf( "udp: not_sock in send\n" );
		return;
	}

	memset( &out, 0, sizeof( out ) );

	if ( !arp_make_eth_header( &out.eth, to_ip, &iface ) )
		return;

	out.eth.src = get_macaddr();
	out.eth.ethertype = __htons( ethertype_ipv4 );
	
	__ip_make_header( &out.ip, IPPROTO_UDP, 0,
		len + sizeof( ip_header ) + sizeof( udp_header ),
		to_ip );

	out.udp.src_port = __htons(conn->port);
	out.udp.dest_port = __htons(to_port);
	out.udp.length = __htons( len + sizeof( udp_header ) );

	if ( len )
		memcpy( out.crap, data, len );

	out.udp.checksum = ~__htons(__checksum_ex( 
		__pseudoheader_checksum( &out.ip ),
		&out.udp, len + sizeof( udp_header ) ));

	__send_packet( iface, (u08 const *) &out, sizeof( eth_header ) + sizeof( ip_header ) + sizeof( udp_header ) + len );
}
示例#7
0
void feature_vector::print() {
  //
  // Display internal settings set from reading steering
  //
  string mn = "print:";
  string def = "<default>";
  
  int w1=30; //arbitrary spacing size that makes formatting look pretty for data names
  int w2=30; //arbitrary spacing size that makes formatting look pretty for data options
  
  
  cout<<cn<<mn<<" >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
      <<"\n"<<setw(w1)<<"DEBUG: "                    <<setw(w2)<<(debug? "ON":"OFF")
      <<"\n"<<setw(w1)<<"Feature Vector File Name: " <<setw(w2)<<"\""<<get_fv_file_name()<<"\""
      <<"\n"<<setw(w1)<<"Feature Vector Extention: " <<setw(w2)<<"\""<<get_fv_ext()<<"\""
      <<"\n"<<setw(w1)<<"Time: "                     <<setw(w2)<<"\""<<get_time_stamp()<<"\""
      <<"\n"<<setw(w1)<<"ID: "                       <<setw(w2)<<"\""<<get_id()<<"\""
      <<"\n"<<setw(w1)<<"Latitude: "                 <<setw(w2)<<"\""<<get_lat()<<"\""
      <<"\n"<<setw(w1)<<"Longitude: "                <<setw(w2)<<"\""<<get_lon()<<"\""
      <<"\n"<<setw(w1)<<"Mac Address: "              <<setw(w2)<<"\""<<get_macaddr()<<"\""<<endl;
  cout<<cn<<mn<<" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"<<endl;            
  
  return;
}
示例#8
0
文件: bnep.c 项目: ghent360/bluez
static void bnep_control(int level, struct frame *frm, int header_length)
{
	uint8_t uuid_size;
	int i, length;
	char *s;
	uint32_t uuid = 0;
	uint8_t type = p_get_u8(frm);

	p_indent(++level, frm);
	switch (type) {
	case BNEP_CONTROL_COMMAND_NOT_UNDERSTOOD:
		printf("Not Understood(0x%02x) type 0x%02x\n", type, p_get_u8(frm));
		break;

	case BNEP_SETUP_CONNECTION_REQUEST_MSG:
		uuid_size = p_get_u8(frm);
		printf("Setup Req(0x%02x) size 0x%02x ", type, uuid_size);
		switch (uuid_size) {
		case 2:
			uuid = p_get_u16(frm);
			printf("dst 0x%x", uuid);
			if ((s = get_uuid_name(uuid)) != 0)
				printf("(%s)", s);
			uuid = p_get_u16(frm);
			printf(" src 0x%x", uuid);
			if ((s = get_uuid_name(uuid)) != 0)
				printf("(%s)", s);
			printf("\n");
			break;
		case 4:
			uuid = p_get_u32(frm);
			printf("dst 0x%x", uuid);
			if ((s = get_uuid_name(uuid)) != 0)
				printf("(%s)", s);
			uuid = p_get_u32(frm);
			printf(" src 0x%x", uuid);
			if ((s = get_uuid_name(uuid)) != 0)
				printf("(%s)", s);
			printf("\n");
			break;
		case 16:
			uuid = p_get_u32(frm);
			printf("dst 0x%x", uuid);
			if ((s = get_uuid_name(uuid)) != 0)
				printf("(%s)", s);
			frm->ptr += 12;
			frm->len -= 12;
			uuid = p_get_u32(frm);
			printf(" src 0x%x", uuid);
			if ((s = get_uuid_name(uuid)) != 0)
				printf("(%s)", s);
			printf("\n");
			frm->ptr += 12;
			frm->len -= 12;
			break;
		default:
			frm->ptr += (uuid_size * 2);
			frm->len -= (uuid_size * 2);
			break;
		}
		break;

	case BNEP_SETUP_CONNECTION_RESPONSE_MSG:
		printf("Setup Rsp(0x%02x) res 0x%04x\n",
						type, p_get_u16(frm));
		break;

	case BNEP_FILTER_NET_TYPE_SET_MSG:
		length = p_get_u16(frm);
		printf("Filter NetType Set(0x%02x) len 0x%04x\n",
							type, length);
		for (i = 0; i < length / 4; i++) {
			p_indent(level + 1, frm);
			printf("0x%04x - ", p_get_u16(frm));
			printf("0x%04x\n", p_get_u16(frm));
		}
		break;

	case BNEP_FILTER_NET_TYPE_RESPONSE_MSG:
		printf("Filter NetType Rsp(0x%02x) res 0x%04x\n",
							type, p_get_u16(frm));
		break;

	case BNEP_FILTER_MULT_ADDR_SET_MSG:
		length = p_get_u16(frm);
		printf("Filter MultAddr Set(0x%02x) len 0x%04x\n",
							type, length);
		for (i = 0; i < length / 12; i++) {
			p_indent(level + 1, frm);
			printf("%s - ", get_macaddr(frm));
			printf("%s\n", get_macaddr(frm));
		}
		break;

	case BNEP_FILTER_MULT_ADDR_RESPONSE_MSG:
		printf("Filter MultAddr Rsp(0x%02x) res 0x%04x\n",
							type, p_get_u16(frm));
		break;

	default:
		printf("Unknown control type(0x%02x)\n", type);
		raw_ndump(level + 1, frm, header_length - 1);
		frm->ptr += header_length - 1;
		frm->len -= header_length - 1;
		return;
	}
}
示例#9
0
文件: bnep.c 项目: ghent360/bluez
void bnep_dump(int level, struct frame *frm)
{
	uint8_t type = p_get_u8(frm);
	uint16_t proto = 0x0000;
	int extension = type & 0x80;

	p_indent(level, frm);

	switch (type & 0x7f) {
	case BNEP_CONTROL:
		printf("BNEP: Control(0x%02x|%s)\n",
					type & 0x7f, extension ? "1" : "0");
		bnep_control(level, frm, -1);
		break;

	case BNEP_COMPRESSED_ETHERNET:
		printf("BNEP: Compressed(0x%02x|%s)\n",
					type & 0x7f, extension ? "1" : "0");
		p_indent(++level, frm);
		proto = p_get_u16(frm);
		printf("[proto 0x%04x]\n", proto);
		break;

	case BNEP_GENERAL_ETHERNET:
		printf("BNEP: General ethernet(0x%02x|%s)\n",
					type & 0x7f, extension ? "1" : "0");
		p_indent(++level, frm);
		printf("dst %s ", get_macaddr(frm));
		printf("src %s ", get_macaddr(frm));
		proto = p_get_u16(frm);
		printf("[proto 0x%04x]\n", proto);
		break;

	case BNEP_COMPRESSED_ETHERNET_DEST_ONLY:
		printf("BNEP: Compressed DestOnly(0x%02x|%s)\n",
					type & 0x7f, extension ? "1" : "0");
		p_indent(++level, frm);
		printf("dst %s ", get_macaddr(frm));
		proto = p_get_u16(frm);
		printf("[proto 0x%04x]\n", proto);
		break;

	case BNEP_COMPRESSED_ETHERNET_SOURCE_ONLY:
		printf("BNEP: Compressed SrcOnly(0x%02x|%s)\n",
					type & 0x7f, extension ? "1" : "0");
		p_indent(++level, frm);
		printf("src %s ", get_macaddr(frm));
		proto = p_get_u16(frm);
		printf("[proto 0x%04x]\n", proto);
		break;

	default:
		printf("(Unknown packet type)\n");
		return;
	}

	/* Extension info */
	if (extension)
		bnep_eval_extension(++level, frm);

	/* Control packet => No payload info */
	if ((type & 0x7f) == BNEP_CONTROL)
		return;

	/* 802.1p header */
	if (proto == 0x8100) {
		p_indent(level, frm);
		printf("802.1p Header: 0x%04x ", p_get_u16(frm));
		proto = p_get_u16(frm);
		printf("[proto 0x%04x]\n", proto);
	}

	if (!(parser.flags & DUMP_VERBOSE)) {
		raw_dump(level, frm);
		return;
	}

	switch (proto) {
	case ETHERTYPE_ARP:
		p_indent(++level, frm);
		printf("ARP: ");
		arp_dump(level, frm);
		break;

	case ETHERTYPE_REVARP:
		p_indent(++level, frm);
		printf("RARP: ");
		arp_dump(level, frm);
		break;

	case ETHERTYPE_IP:
		p_indent(++level, frm);
		printf("IP: ");
		ip_dump(level, frm);
		break;

	case ETHERTYPE_IPV6:
		p_indent(++level, frm);
		printf("IPV6: ");
		ip_dump(level, frm);
		break;

	default:
		raw_dump(level, frm);
		break;
	}
}
示例#10
0
void cmd_parser(unsigned long data)
{
	char *curr_pos = &user_string[0];
	int ret;

	while(1) {

		while(cmd_in_progress)
			os_TaskDelay(10);
		DBG_P(( DBG_L0 "\r\n> "));
		cmd_parser_read_line();
	   
		if(strlen(user_string) == 0) {
			/* Do Nothing. */
		}
	   
		else if(!memcmp(user_string,"iwlist",6)){
			userif_prepare_scan_cmd(0);
		}     
		else if(!memcmp(user_string,"iwconf",6)){
			curr_pos = &user_string[get_next_word(user_string)];
			if(!memcmp(curr_pos,"essid",5)) {
				curr_pos = &curr_pos[get_next_word(curr_pos)];
				specificSSID.Len  = strlen(curr_pos);
				memcpy((void *)specificSSID.SsId, curr_pos, strlen(curr_pos));
				if(link_present) {
					if(currbss_type != BSS_INDEPENDENT)
						userif_prepare_deauth_cmd();
					else
						userif_prepare_adhoc_stop_cmd();
				} else {
					userif_prepare_scan_cmd(1);
				}
				link_present = 0;				
			} else if (!memcmp(curr_pos,"mode",4)) {
				curr_pos = &curr_pos[get_next_word(curr_pos)];
				if(!memcmp(curr_pos,"ad-hoc",6)) {
					bss_type = BSS_INDEPENDENT;
				} else if(!memcmp(curr_pos,"manage",6)) {
					bss_type = BSS_INFRASTRUCTURE;
				} else {
					bss_type = BSS_ANY;
				}
			} else if (!memcmp(curr_pos,"ap",2)) {
				curr_pos = &curr_pos[get_next_word(curr_pos)];
				get_macaddr(curr_pos,(char *)specificBSSID);
				if (FindBSSIDinList()) {
					userif_prepare_auth_cmd();			
				} else {
					if(link_present) {
						link_present = 0;
						userif_prepare_deauth_cmd();
					} else {
						userif_prepare_scan_cmd(2);
					}
				}
			}
		}
		else if(!memcmp(user_string,"econfi",6)){
			unsigned int ip;
			unsigned int nm;
			unsigned int gw;
			curr_pos = &user_string[get_next_word(user_string)];
			get_ipaddr(curr_pos, (char *)&ip);
			curr_pos = &curr_pos[get_next_word(curr_pos)];
			get_ipaddr(curr_pos, (char *)&nm);
			curr_pos = &curr_pos[get_next_word(curr_pos)];
			get_ipaddr(curr_pos, (char *)&gw);
			sys_tcpip_init(ip, nm);
		}
	   
		else if(!memcmp(user_string, "printip", 7)){
			DBG_P(( DBG_L0 "%d.%d.%d.%d,", ip_addr[0], ip_addr[1], ip_addr[2], 
				ip_addr[3] ));
			DBG_P(( DBG_L0 "%d.%d.%d.%d,", net_mask[0], net_mask[1], 
				net_mask[2], net_mask[3] ));
			DBG_P(( DBG_L0 "%d.%d.%d.%d\r\n", def_gtwy[0], def_gtwy[1], 
				def_gtwy[2], def_gtwy[3] ));
		}
	   
		else if(!memcmp(user_string, "printmac", 8)){
			char mac[6];
			GetMACAddr(NULL, mac);
			DBG_P(( DBG_L0 "%02x:%02x:%02x:%02x:%02x:%02x\r\n", \
					mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]));
		}
	   
		else if(!memcmp(user_string,"ping",4)){
			curr_pos = &user_string[get_next_word(user_string)];
			if(!memcmp(curr_pos,"stop",4)) {
				send_ping = 0;
			} else {
				get_ipaddr(curr_pos, ping_ipaddr);
#ifdef EMBEDDED_TCPIP
				userif_prepare_open_raw_socket();
#else
				userif_prepare_macaddr_get_cmd();
#endif
				send_ping = 1;
			}
		}

		/* Link-local address manager. */
		else if(!memcmp(user_string, "linklocal", 9)) {
			curr_pos = &user_string[get_next_word(user_string)];
			if(!memcmp(curr_pos, "start", 5)) {
				/* Launch the link local manager */
				ret = ll_init();
				if(ret)
					DBG_P(( DBG_L0 "Error launching link local: %d.\r\n", ret));
			} else if(!memcmp(curr_pos, "stop", 4)) {
				/* Kill the link local manager. */
				ret = ll_shutdown();
				if(ret)
					DBG_P(( DBG_L0 "Error killing link local: %d.\r\n", ret));
			}
		}

		/* mDNS responder */
		else if(!memcmp(user_string, "mdns", 4)) {
			curr_pos = &user_string[get_next_word(user_string)];
			if(!memcmp(curr_pos, "start", 5)) {
				/* launch the mDNS responder */
				ret = mdns_responder_init();
				if(ret)
					DBG_P(( DBG_L0 "Error launching mDNS responder: %d.\r\n",ret));
			}
			else if(!memcmp(curr_pos, "stop", 4)) {
				/* stop the mDNS responder */
				ret = mdns_responder_shutdown();
				if(ret)
					DBG_P(( DBG_L0 "Error stopping mDNS responder: %d.\r\n", ret));
			}
		}

	else if(!memcmp(user_string, "mcast", 5 )){
		curr_pos = &user_string[get_next_word(user_string)];
		if(!memcmp(curr_pos, "get", 3 )) {
			userif_prepare_mcast_cmd();
		}
		else if(!memcmp(curr_pos, "set", 3 )) {
			userif_prepare_mcast_add_cmd();
		}
	}

		/* httpd interface */
		else if(!memcmp(user_string, "httpd", 5)) {
			curr_pos = &user_string[get_next_word(user_string)];
			if(!memcmp(curr_pos, "start", 5)) {
				ret = httpd_init();
				if(ret)
					DBG_P(( DBG_L0 "Error launching httpd: %d.\r\n",ret));
			}
			else if(!memcmp(curr_pos, "stop", 4)) {
				ret = httpd_shutdown();
				if(ret)
					DBG_P(( DBG_L0 "Error stopping httpd: %d.\r\n", ret));
			}
			else {
				DBG_P(( DBG_L0 "No such httpd command: %s.\r\n", curr_pos));
			}
		}

		/* log interface */
		else if(!memcmp(user_string, "log", 3)) {
			curr_pos = &user_string[get_next_word(user_string)];
			if(!memcmp(curr_pos, "init", 5)) {
				ret = log_init();
				if(ret)
					DBG_P(( DBG_L0 "Error launching logger: %d.\r\n",ret));
			}
			else if(!memcmp(curr_pos, "shutdown", 8)) {
				ret = log_shutdown();
				if(ret)
					DBG_P(( DBG_L0 "Error stopping logger: %d.\r\n", ret));
			}
			else if(!memcmp(curr_pos, "dump", 4)) {
				ret = log_dump();
				if(ret)
					DBG_P(( DBG_L0 "Error dumping log: %d.\r\n", ret));
			}
			else if(!memcmp(curr_pos, "purge", 5)) {
				ret = log_purge();
				if(ret)
					DBG_P(( DBG_L0 "Error purging log: %d.\r\n", ret));
			}
			else if(!memcmp(curr_pos, "write", 5)) {
				curr_pos = &curr_pos[get_next_word(curr_pos)];
				ret = log(curr_pos);
				if(ret)
					DBG_P(( DBG_L0 "Failed to write log: %d.\r\n", ret));
			}
			else {
				DBG_P(( DBG_L0 "No such log command: %s.\r\n", curr_pos));
			}
		}

	 else if(!memcmp(user_string, "help", 4)) {
		 print_usage();
	 }

	else {
#ifdef UART_DRV
			DBG_P(( DBG_L0 "Unknown command.\r\n")); 
#endif		 
		}	   
	}
}