示例#1
0
int main() {
    int size = 16, i;
    char plaintext[] = "hello world, thi";
    char ciphertext[size], deciphered[size];
    char key[8] = "abcdefgh";

    printf("plaintext = '%s', hex:\n", plaintext);
    hex_dump(plaintext, size);
    printf("\n\n");

    cbc_encipher(plaintext, ciphertext, key, size);
    printf("ciphertext = '%s', hex:\n", ciphertext);
    hex_dump(ciphertext, size);
    printf("\n\n");

    cbc_decipher(ciphertext, deciphered, key, size);
    printf("deciphered = '%s', hex:\n", deciphered);
    hex_dump(deciphered, size);
    printf("\n\n");

    return 0;
}
示例#2
0
文件: test.c 项目: cmr/libblake2
int main(void) {
    unsigned char *out = malloc(64);
    unsigned int data[64] = {0,1,2,3,4,5,6,7,8,9};

    void *in = malloc(8192);
    memset(in, 0, 64);
    memcpy(in, data, 64);

    blake2(out, in, NULL, 64, 4096, 0);

    hex_dump(out, 64);
    return 0;
}
示例#3
0
static VOID ReservedAction(RTMP_ADAPTER *pAd, MLME_QUEUE_ELEM *Elem)
{
	UCHAR Category;

	if (Elem->MsgLen <= LENGTH_802_11)
	{
		return;
	}

	Category = Elem->Msg[LENGTH_802_11];
	DBGPRINT(RT_DEBUG_TRACE,("Rcv reserved category(%d) Action Frame\n", Category));
	hex_dump("Reserved Action Frame", &Elem->Msg[0], Elem->MsgLen);
}
示例#4
0
void dissect_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet) {
//void dissect_packet(const struct pcap_pkthdr *header, const u_char *packet) {
    static int count = 0;

    printf("###############################################\n");
    printf("Dissecting packet #%d\n", count++);
    printf("Time: %ld.%06ld\n", header->ts.tv_sec, header->ts.tv_usec);
    printf("Capture length: %d, Wire length: %d\n", header->caplen, header->len);
    print_line();
    hex_dump(packet, header->caplen);
    dissect_ether(packet);
    printf("\n");
}
示例#5
0
void issue_commands(sxa_node_t FAR *sxa)
{
	int i;
	xbee_command_list_context_t	my_clc;			// Context structure

   // Set up parameter data for any SET commands
   my_struct.new_dd = 0x0F111111;
   strcpy(my_struct.ni, "MyNodeID");

   // Start issuing commands in list
	xbee_cmd_list_execute( sxa_xbee( sxa),			// Get the XBee device from sxa
   								&my_clc,					// The command list context
									my_command_list,		// The command list itself
                           &my_struct,				// The struct to fill in
                           sxa_wpan_address( sxa));	// Target Xbee address

   // For this sample, block until complete.  Real application would be
   // doing something else in the meantime, inside the loop.
	while (xbee_cmd_list_status(&my_clc) == -EBUSY)
   {
   	sxa_tick();
   }

   // Now look at the final status
   switch (xbee_cmd_list_status(&my_clc))
   {
   	case XBEE_COMMAND_LIST_DONE:
      	printf("Completed successfully:\n");
         printf(" CH = %d\n", my_struct.ch);
         printf(" OP =\n");
			hex_dump( my_struct.op, sizeof(my_struct.op), HEX_DUMP_FLAG_TAB);
         printf(" OI = 0x%04X\n", my_struct.oi);
         printf(" MY = 0x%04X\n", my_struct.my);
         printf(" SC =");
         for (i = 0; i < 16; ++i)
         {
         	printf("%d", my_struct.sc[i]);
         }
         printf(" (ch 11..26)\n");
         printf(" DD (old) = 0x%08lX\n", my_struct.old_dd);
         printf(" DD (new) = 0x%08lX\n", my_struct.verify_dd);
         break;
      case XBEE_COMMAND_LIST_TIMEOUT:
      	printf("Timed out\n");
         break;
      case XBEE_COMMAND_LIST_ERROR:
      default:
      	printf("Completed partially or with errors\n");
         break;
   }
}
示例#6
0
void data_dump(unsigned char *data, int length, int dumpstyle)
{
	switch (dumpstyle) {

	case READABLE:
		readable_dump(data, length);
		break;
	case HEX:
		hex_dump(data, length);
		break;
	default:
		ascii_dump(data, length);
	}
}
示例#7
0
/***********************************************************************
 *
 * Function: cmd_dump
 *
 * Purpose: Dump command
 *
 * Processing:
 *     Parse the string elements for the dump command and display the
 *     dumped values.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: TRUE if the command was processed, otherwise FALSE
 *
 * Notes: None
 *
 **********************************************************************/
static BOOL_32 cmd_dump(void)
{
    UNS_32 newaddr, newwidth, newtrans;

    /* If only 1 parsed command, then print at current address and
       width */
    if (parse_get_entry_count() > 1)
    {
        newaddr = dump_addr;
        newwidth = dump_width;
        newtrans = dump_trans;

        /* Get address */
        newaddr = cmd_get_field_val(1);

        /* Convert decimal value to width */
        if (parse_get_entry_count() >= 3)
        {
            newtrans = cmd_get_field_val(2);
        }
        if (parse_get_entry_count() >= 4)
        {
            newwidth = cmd_get_field_val(3);
            if (!((newwidth == 1) || (newwidth == 2) ||
                    (newwidth == 4)))
            {
                newwidth = 1;
            }
        }

        dump_addr = newaddr;
        dump_width = newwidth;
        dump_trans = newtrans;

        /* Limit dump size to 1024 bytes */
        if ((dump_trans * dump_width) > 1024)
        {
            dump_trans = dump_trans / dump_width;
        }
    }

    /* Based on width, limit address start */
    dump_addr = dump_addr & ~(dump_width - 1);

    /* Dump data and increment address */
    hex_dump(dump_addr, dump_width, dump_trans);
    dump_addr = dump_addr + (dump_width * dump_trans);

    return TRUE;
}
示例#8
0
文件: cbson.c 项目: c4pt0r/cbson
int main() {
    bson_obj_t* b = malloc(sizeof(bson_obj_t));
    memset(b, 0, sizeof(bson_obj_t));
    // write length
    int offset = bson_reserved_length(b);
    bson_append_string(b, "hello", "world");
    bson_write_byte(b, 0);
    bson_write_uint32_with_offset(b, b->size - offset, offset);
    printf("size: %zu\n", b->size);
    hex_dump("dump:", b->bytes, b->size);
    const char* v = bson_read_string(b->bytes, "hello");
    printf("key: %s value: %s \n", "hello", v);

}
示例#9
0
文件: sim_fp.c 项目: wucan/xmux
static void prog_0_btn_press(GtkWidget *widget,
		GdkEventButton *event, gpointer *user_data)
{
	static int cnt = 1;

	fp_build_cmd(req_buf, true, 0, NULL, 0);
	hex_dump("req", req_buf, 6);
	__parse_mcu_cmd(req_buf, resp_buf, &resp_len);
	hex_dump("resp", resp_buf, resp_len);

	if (cnt % 2) {
		fp_select_program(0);
		fp_select_program(1);
		fp_select_program(2);
		fp_select_program(3);
	} else {
		fp_deselect_program(0);
		fp_deselect_program(1);
		fp_deselect_program(2);
		fp_deselect_program(3);
	}
	cnt++;
}
void process_section(int fd)
{
	uint8_t buf[MAX_SECTION_SIZE];
	int bytes;

	bytes = read(fd, buf, sizeof(buf));
	if (bytes < 0) {
		perror("read");
		if (errno != EOVERFLOW)
			exit(1);
	}
	hex_dump(buf, bytes);
	printf("\n");
}
示例#11
0
/*
========================================================================
Routine Description:
    The entry point for Linux kernel sent packet to our driver.

Arguments:
    sk_buff *skb		the pointer refer to a sk_buffer.

Return Value:
    0					

Note:
	This function is the entry point of Tx Path for Os delivery packet to 
	our driver. You only can put OS-depened & STA/AP common handle procedures 
	in here.
========================================================================
*/
int rt28xx_packet_xmit(struct sk_buff *skb)
{
	struct net_device *net_dev = skb->dev;
	PRTMP_ADAPTER pAd = NULL;
	PNDIS_PACKET pPacket = (PNDIS_PACKET) skb;

	GET_PAD_FROM_NET_DEV(pAd, net_dev);

	/* RT2870STA does this in RTMPSendPackets() */
#ifdef RALINK_ATE
	if (ATE_ON(pAd))
	{
		RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_RESOURCES);
		return 0;
	}
#endif // RALINK_ATE //

        // EapolStart size is 18
	if (skb->len < 14)
	{
		//printk("bad packet size: %d\n", pkt->len);
		hex_dump("bad packet", skb->data, skb->len);
		RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
		goto done;
	}

#if defined (CONFIG_RA_HW_NAT) || defined (CONFIG_RA_HW_NAT_MODULE)
#if !defined (CONFIG_RA_NAT_NONE)
	if (ra_sw_nat_hook_tx != NULL)
	{
		ra_sw_nat_hook_tx(pPacket, 0);
	}
#endif
#endif

#ifdef CONFIG_5VT_ENHANCE
	RTMP_SET_PACKET_5VT(pPacket, 0);
	if (*(int*)(skb->cb) == BRIDGE_TAG) {
		RTMP_SET_PACKET_5VT(pPacket, 1);
	}
#endif

#ifdef CONFIG_AP_SUPPORT
	IF_DEV_CONFIG_OPMODE_ON_AP(pAd)
		APSendPackets((NDIS_HANDLE)pAd, (PPNDIS_PACKET) &pPacket, 1);
#endif // CONFIG_AP_SUPPORT //

done:
	return 0;
}
示例#12
0
VOID PeerVHTAction(RTMP_ADAPTER *pAd, MLME_QUEUE_ELEM *Elem)
{
	UCHAR Action = Elem->Msg[LENGTH_802_11+1];
	
	if (Elem->Wcid >= MAX_LEN_OF_MAC_TABLE)
		return;

	switch(Action)
	{
		case ACT_VHT_OPMODE_NOTIFY:
			{
				OPERATING_MODE *op_mode = (OPERATING_MODE *)&Elem->Msg[LENGTH_802_11+2];
				MAC_TABLE_ENTRY *pEntry = &pAd->MacTab.Content[Elem->Wcid];

				DBGPRINT(RT_DEBUG_TRACE,("ACTION - Operating Mode Notification action---->\n"));
				hex_dump("OperatingModeNotify", &Elem->Msg[0], Elem->MsgLen);
				DBGPRINT(RT_DEBUG_TRACE, ("\t RxNssType=%d, RxNss=%d, ChBW=%d\n",
							op_mode->rx_nss_type, op_mode->rx_nss, op_mode->ch_width));

				if (op_mode->rx_nss_type == 0) {
					pEntry->force_op_mode = TRUE;
					NdisMoveMemory(&pEntry->operating_mode, op_mode, 1);
				}
			}
			break;
#ifdef VHT_TXBF_SUPPORT
		case ACT_VHT_COMPRESS_BF:
			{
				DBGPRINT(RT_DEBUG_OFF,("ACTION - VHT Compressed Beamforming action---->\n"));
				hex_dump("VHT Compressed BF", &Elem->Msg[0], Elem->MsgLen);
				break;
			}
#endif /* VHT_TXBF_SUPPORT */
		default:
			break;
	}
}
示例#13
0
int main( void )
{
    int retcode;
    char outbuf[BUFSIZE];
    unsigned char iv[] = {1,2,3,4,5,6,7,8};
    unsigned char new_iv[8];

    RAND_pseudo_bytes( iv, 8 );
    printf( "iv1:\n" );
    hex_dump( iv, 8 );

    retcode = write_cipher_data( "out.dat", msg, strlen(msg), passphrase, iv );
    assert( retcode == strlen(msg) );
    printf( "iv2:\n" );
    hex_dump( iv, 8 );

    retcode = write_b64( "out.dat.iv", iv, 8 );
    assert( retcode == 8 );
    memset( new_iv, 0, sizeof(new_iv) );
    retcode = read_b64( "out.dat.iv", new_iv, 8 );
    assert( retcode == 8 );
    printf( "new_iv:\n" );
    hex_dump( new_iv, 8 );
    assert( memcmp( iv, new_iv, 8 ) == 0 );
    
    memset( outbuf, 0, BUFSIZE );
    retcode = read_cipher_data( "out.dat", outbuf, BUFSIZE, passphrase, iv );
    assert( retcode == strlen(msg) );
    printf( "iv3:\n" );
    hex_dump( iv, 8 );
    printf( "outbuf:\n" );
    hex_dump( outbuf, 64 );
    assert( strncmp( msg, outbuf, strlen(msg) ) == 0 );

    printf( "success!\n" );
    return 0;
}
/*
==========================================================================
	Description:

	IRQL = PASSIVE_LEVEL
==========================================================================
*/
NDIS_STATUS
TDLS_ChannelSwitchRspAction(
    IN	PRTMP_ADAPTER	pAd,
    IN	PRT_802_11_TDLS	pTDLS,
    IN	USHORT	ChSwitchTime,
    IN	USHORT	ChSwitchTimeOut,
    IN	UINT16	StatusCode,
    IN	UCHAR	FrameType)
{
    UCHAR	TDLS_ETHERTYPE[] = {0x89, 0x0d};
    UCHAR	Header802_3[14];
    PUCHAR	pOutBuffer = NULL;
    ULONG	FrameLen = 0;
    ULONG	TempLen;
    UCHAR	RemoteFrameType = PROTO_NAME_TDLS;
    NDIS_STATUS	NStatus = NDIS_STATUS_SUCCESS;

    DBGPRINT(RT_DEBUG_WARN, ("TDLS ===> TDLS_ChannelSwitchRspAction\n"));

    MAKE_802_3_HEADER(Header802_3, pTDLS->MacAddr, pAd->CurrentAddress, TDLS_ETHERTYPE);

    // Allocate buffer for transmitting message
    NStatus = MlmeAllocateMemory(pAd, &pOutBuffer);

    if (NStatus	!= NDIS_STATUS_SUCCESS)
    {
        DBGPRINT(RT_DEBUG_ERROR,("ACT - TDLS_ChannelSwitchRspAction() allocate memory failed \n"));
        return NStatus;
    }

    MakeOutgoingFrame(pOutBuffer,			&TempLen,
                      1,				&RemoteFrameType,
                      END_OF_ARGS);

    FrameLen = FrameLen + TempLen;

    TDLS_BuildChannelSwitchResponse(pAd, pOutBuffer, &FrameLen, pTDLS, ChSwitchTime, ChSwitchTimeOut, StatusCode);

    RTMPToWirelessSta(pAd, &pAd->MacTab.Content[pTDLS->MacTabMatchWCID], Header802_3,
                      LENGTH_802_3, pOutBuffer, (UINT)FrameLen, FALSE, FrameType);

    hex_dump("TDLS send channel switch response pack", pOutBuffer, FrameLen);

    MlmeFreeMemory(pAd, pOutBuffer);

    DBGPRINT(RT_DEBUG_WARN, ("TDLS <=== TDLS_ChannelSwitchRspAction\n"));

    return NStatus;
}
示例#15
0
void fm_raw_pkt_sock_read (fm_raw_sock_data_t *info, short int revents)
{
    static int count = 0;
    struct iovec *ring = info->iovec;
    u_char *pkt;
#ifdef ENABLE_VLAN
    struct tpacket2_hdr *h;
#else
    struct tpacket_hdr *h;
#endif

    h = ring[info->iovhead].iov_base;
    while (h->tp_status) {
        pkt = (u_char*)h + h->tp_mac;
        /* dissecting packets */
        printf("###############################################\n");
        printf("Dissecting packet #%d\n", count++);
#ifdef ENABLE_VLAN
        printf("Time: %d.%09d\n", h->tp_sec, h->tp_nsec);
#else
        printf("Time: %d.%06d\n", h->tp_sec, h->tp_usec);
#endif
        printf("Capture length: %d, Wire length: %d\n", h->tp_snaplen, h->tp_len);
#ifdef ENABLE_VLAN
#ifdef FILL_8021Q
        if(h->tp_vlan_tci & 0x0FFF) {
            pkt -= 4; 
            memmove(pkt, pkt + 4, 2 * 6);
            *(uint16_t*)(pkt+12) = htons(0x8100);
            *(uint16_t*)(pkt+14) = htons(h->tp_vlan_tci);
            h->tp_snaplen += 4;
            h->tp_len += 4;
        }
#else
        printf("VLAN is %d\n", h->tp_vlan_tci & 0x0FFF);
#endif  // endif FILL_8021Q
#endif  // endif ENABLE_VLAN
        print_line();
        hex_dump(pkt, h->tp_snaplen);
        dissect_ether(pkt);
        printf("\n");
        /* end dissecting packets */

        /* release packet back */
        h->tp_status = TP_STATUS_KERNEL;
        info->iovhead = (info->iovhead == info->iovmax) ? 0 : info->iovhead+1;
        h = ring[info->iovhead].iov_base;
    }
}
示例#16
0
static void cmd_reset_b3(int level, uint8_t subcmd, struct frame *frm)
{
	uint8_t len;

	cmd_common(level, subcmd, frm);

	if (subcmd == 0x80 || subcmd == 0x82) {
		len = CAPI_U8(frm);
		if (len > 0) {
			p_indent(level, frm);
			printf("NCPI:\n");
			hex_dump(level, frm, len);
		}
	}
}
示例#17
0
static inline void security(int level, uint8_t hdr, struct frame *frm)
{
	switch (hdr & 0x03) {
	case 0x00:
		acp_seid(level, frm);
	case 0x02:
		hex_dump(level + 1, frm, frm->len);
		frm->ptr += frm->len;
		frm->len = 0;
		break;
	case 0x03:
		errorcode(level, frm);
		break;
	}
}
示例#18
0
static void cmd_alert(int level, uint8_t subcmd, struct frame *frm)
{
	uint8_t len;

	cmd_common(level, subcmd, frm);

	if (subcmd == 0x80) {
		len = CAPI_U8(frm);
		if (len > 0) {
			p_indent(level, frm);
			printf("Additional info:\n");
			hex_dump(level, frm, len);
		}
	}
}
示例#19
0
/*** EndHeader */
int xbee_route_dump_record_indicator( xbee_dev_t *xbee,
	const void FAR *frame, uint16_t length, void FAR *context)
{
	const xbee_frame_route_record_indicator_t FAR *record = frame;
	char buffer[ADDR64_STRING_LENGTH];
	const uint16_t FAR *addr_be;
	int i;
	
	if (frame == NULL)
	{
		return -EINVAL;
	}
	if (record->address_count == 0
		&& record->address_count > XBEE_ROUTE_MAX_ADDRESS_COUNT)
	{
		printf( "invalid address count, must be 1 to %u (not %u)\n",
			XBEE_ROUTE_MAX_ADDRESS_COUNT, record->address_count);
	}
	else if (length ==
			offsetof( xbee_frame_route_record_indicator_t, route_address_be) +
			record->address_count * sizeof *record->route_address_be)
	{
		printf( "route record indicator from %" PRIsFAR " (0x%04X):\n",
			addr64_format( buffer, &record->ieee_address),
			be16toh( record->network_address_be));
		if (record->receive_options & XBEE_RX_OPT_ACKNOWLEDGED)
		{
			printf( "acknowledged, ");
		}
		if (record->receive_options & XBEE_RX_OPT_BROADCAST)
		{
			printf( "broadcast, ");
		}
		printf( "\t%u addresses:\n\tdest -> ", record->address_count);
		addr_be = record->route_address_be;
		for (i = record->address_count; i; ++addr_be, --i)
		{
			printf( "0x%04X -> ", be16toh( *addr_be));
		}
		puts( "source");

		return 0;
	}
	
	puts( "malformed route record indicator:");
	hex_dump( frame, length, HEX_DUMP_FLAG_TAB);
	return -EINVAL;
}
示例#20
0
/*
========================================================================
Routine Description:
	Check if ASIC can go to sleep mode.

Arguments:
	pAd				- WLAN control block pointer

Return Value:
	None

Note:
	Check all TDLS entries and return TRUE if all SPs are closed.
========================================================================
*/
BOOLEAN TDLS_UAPSDP_AsicCanSleep(
	IN	PRTMP_ADAPTER				pAd)
{
	RT_802_11_TDLS *pTDLS;
	UINT32 IdEntry;
	BOOLEAN FlgAllSpClosed = TRUE;


	TDLS_SEMLOCK(pAd);

	/* check if all SPs are closed */
	for(IdEntry=0; IdEntry<MAX_NUM_OF_TDLS_ENTRY; IdEntry++)
	{
		pTDLS = (PRT_802_11_TDLS)&pAd->StaCfg.TdlsInfo.TDLSEntry[IdEntry];

		if ((pTDLS->Valid == TRUE) &&
			(pTDLS->Status == TDLS_MODE_CONNECTED))
		{
			UINT32 Wcid = pTDLS->MacTabMatchWCID;
			PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[Wcid];


			if (!IS_ENTRY_TDLS(pEntry))
				continue;

			/*
				Two cases we can not sleep:
				1. One of any SP is not ended.
				2. A traffic indication is sent and no response is received.
			*/
			if ((pEntry->bAPSDFlagSPStart != 0) ||
				(pTDLS->FlgIsWaitingUapsdTraRsp == TRUE))
			{
				DBGPRINT(RT_DEBUG_TRACE,
						("tdls uapsd> SP not close or Ind sent (%d %d)!\n",
						pEntry->bAPSDFlagSPStart,
						pTDLS->FlgIsWaitingUapsdTraRsp));
				hex_dump("pEntry=", pEntry->Addr, 6);
				FlgAllSpClosed = FALSE;
				break;
			}
		}
	}

	TDLS_SEMUNLOCK(pAd);

	return FlgAllSpClosed;
}
示例#21
0
文件: sim_fp.c 项目: wucan/xmux
static void read_map_analyse_status_btn_press(GtkWidget *widget,
		GdkEventButton *event, gpointer *user_data)
{
	uint16_t sys_cmd = FP_SYS_CMD_READ_MAP_ANALYSE_STATUS;
	CHN_NUM_T chnum;

	sys_cmd = htons(sys_cmd);
	fp_build_cmd(req_buf, true, FP_CMD_SYS, &sys_cmd, sizeof(sys_cmd));
	__parse_mcu_cmd(req_buf, resp_buf, &resp_len);
	if (!fp_validate_cmd(resp_buf, resp_len, sizeof(CHN_NUM_T))) {
		g_print("response cmd invalidate!\n");
		return;
	}
	memcpy(&chnum, &resp_buf[sizeof(struct fp_cmd_header)], sizeof(chnum));
	hex_dump("chan num", &chnum, sizeof(chnum));
}
示例#22
0
VOID dump_tmac_info(RTMP_ADAPTER *pAd, UCHAR *tmac_info)
{
	TXWI_STRUC *pTxWI = (TXWI_STRUC *)tmac_info;
	hex_dump("TxWI Raw Data: ", (UCHAR *)pTxWI, pAd->chipCap.TXWISize);

	DBGPRINT(RT_DEBUG_OFF, ("TxWI Fields:\n"));
#ifdef RLT_MAC
	if (pAd->chipCap.hif_type == HIF_RLT)
		dump_rlt_txwi(pAd, pTxWI);
#endif /* RLT_MAC */

#ifdef RTMP_MAC
	if (pAd->chipCap.hif_type == HIF_RTMP)
		dump_rtmp_txwi(pAd, pTxWI);
#endif /* RTMP_MAC */
}
示例#23
0
VOID dump_txinfo(RTMP_ADAPTER *pAd, TXINFO_STRUC *pTxInfo)
{
	hex_dump("TxInfo Raw Data: ", (UCHAR *)pTxInfo, sizeof(TXINFO_STRUC));
	
	DBGPRINT(RT_DEBUG_OFF, ("TxInfo Fields:\n"));

#ifdef RLT_MAC
	if (pAd->chipCap.hif_type == HIF_RLT)
		dump_rlt_txinfo(pAd, pTxInfo);
#endif /* RLT_MAC */

#ifdef RTMP_MAC
	if (pAd->chipCap.hif_type == HIF_RTMP)
		DBGPRINT(RT_DEBUG_OFF, ("\n"));
#endif /* RTMP_MAC */
}
示例#24
0
/* write generic data to the serial port */
int mwsp_write(int fd, void* data, int len)
{
    /* write data */
    tcflush(fd, TCIOFLUSH);
    int wrt = write(fd, data, len);

    if(wrt < 0){
        return MWSP_ERR_WRITE;
    }

#ifdef DEBUG
    hex_dump("mwsp_write", data, len);
#endif

    return wrt;
}
示例#25
0
/* Capture packets from the network, and print them. */
static int
start_cap(char *dev)
{
    char temp[PCAP_ERRBUF_SIZE];
    struct pcap_pkthdr *hdr;
    const unsigned char *pkt;
    struct tm *ltime;
    time_t now;
    pcap_t *pcap;
    int rc;

    /* Open the device for reading from it. */
    pcap = f_pcap_open_live(dev,
			    1518,	/* MTU */
			    1,		/* promisc mode */
			    10,		/* timeout */
			    temp);
    if (pcap == NULL) {
	fprintf(stderr, "Pcap: open_live(%s): %s\n", dev, temp);
	return(2);
    }

    printf("Listening on '%s'..\n", dev);
    for (;;) {
	rc = f_pcap_next_ex(pcap, &hdr, &pkt);
	if (rc < 0) break;

	/* Did we time out? */
	if (rc == 0) continue;

        /* Convert the timestamp to readable format. */
        now = hdr->ts.tv_sec;
        ltime = localtime(&now);
        strftime(temp, sizeof(temp), "%H:%M:%S", ltime);
        
	/* Process and print the packet. */
        printf("\n<< %s,%.6ld len=%u\n",
		temp, hdr->ts.tv_usec, hdr->len);
	rc = eth_prhdr((unsigned char *)pkt);
	hex_dump((unsigned char *)pkt+rc, hdr->len-rc);
    }

    /* All done, close up. */
    f_pcap_close(pcap);

    return(0);
}
示例#26
0
  unsigned int hu_aad_dmp (unsigned char * prefix, int type, unsigned char * buf, int len) {   // type 1 = rx from HU > AA     type 2 = tx from AA > HU
    unsigned int rmv = 0, adj = 0;
    unsigned int lft = len;

    if (len < 2) {                                                      // Need at least 2 bytes for msg_type
      loge ("hu_aad_dmp len: %d", len);
      return (rmv);
    }

    hex_dump (prefix, 16, buf, len);

    int checksum = 0;
    int ctr = 0;
    for (ctr = 16; ctr < len; ctr ++)
      checksum += (int) buf [ctr];

    unsigned int msg_type = (((unsigned int) buf [0]) << 8) + ((unsigned int) buf [1]);
    //msg_type = buf [0] << 8;
    //msg_type += buf [1];

    adj = 2;
    iaad_adj (& rmv, & buf, & lft, adj);                                // Adjust = past the msg_type to content
    char * msg_type_str = iaad_msg_type_str_get (msg_type, type, len);  // Get msg_type string
    logd ("len: %5d  checksum: %12d  msg_type: %6d (%s)", len, checksum, msg_type, msg_type_str);

    if (msg_type_enc_get (type) == NULL) {                              // Ignore encrypted data
      return (len);
    }

    if (lft == 0)                                                       // If no content
      return (rmv);
    if (lft < 2) {                                                      // Need at least 2 bytes for content
      loge ("hu_aad_dmp len: %d  lft: %d", len, lft);
      return (rmv);
    }

    //hex_dump ("0  ", 16, buf, len - 2);

    adj = iaad_dmp_n (1, 1, buf, lft);                                   // Dump the content w/ n=1
    iaad_adj (& rmv, & buf, & lft, adj);                                  // Adjust past the content (to nothing, presumably)
    if (lft != 0 || rmv != len || rmv < 0)
      loge ("hu_aad_dmp after content len: %d  lft: %d  rmv: %d  buf: %p", len, lft, rmv, buf);

    logd ("");  // Empty line

    return (rmv);
  }
示例#27
0
文件: nfc.c 项目: 23171580/ralink
VOID NfcCommand(
	IN	PRTMP_ADAPTER	pAd, 
	IN	UCHAR Action,
	IN  UCHAR Type,
	IN  SHORT DataLen,
	IN  PUCHAR pData) 
{
	PNET_DEV pNetDev = pAd->net_dev;
	UCHAR *pBuffer = NULL;
	USHORT len;
	USHORT vendor_id = NFC_VENDOR_ID, type = ETH_MTK_NFC, net_type;
	UCHAR Header802_3[LENGTH_802_3];
	UCHAR SrcMacAddr[MAC_ADDR_LEN]  = {0x00, 0x00, 0x00, 0x00, 0x66, 0x05};
	struct wifi_dev *wdev;
	MULTISSID_STRUCT *pMbss;

	len = sizeof(vendor_id) + sizeof(Action) + sizeof(Type) + sizeof(USHORT) + LENGTH_802_3;
	if (DataLen > 0)
		len += DataLen;

	os_alloc_mem(pAd, (UCHAR **)&pBuffer, (len*sizeof(UCHAR)));
	if (pBuffer == NULL)
		return;

	pMbss = &pAd->ApCfg.MBSSID[0];
	wdev = &pMbss->wdev;
	NdisZeroMemory(pBuffer, len);
	NdisZeroMemory(&Header802_3[0], LENGTH_802_3);

	NdisMoveMemory(&Header802_3[0], wdev->bssid, MAC_ADDR_LEN);
    NdisMoveMemory((&Header802_3[0] + MAC_ADDR_LEN), &SrcMacAddr[0], MAC_ADDR_LEN);
	net_type = htons(type);
    NdisMoveMemory((&Header802_3[0] + MAC_ADDR_LEN * 2), &net_type, LENGTH_802_3_TYPE);
	//hex_dump("Header802_3", &Header802_3[0], LENGTH_802_3);

	NdisMoveMemory(pBuffer, &Header802_3[0], LENGTH_802_3);
	NdisMoveMemory(pBuffer+LENGTH_802_3, &vendor_id, sizeof(vendor_id));
	NdisMoveMemory(pBuffer+LENGTH_802_3+sizeof(vendor_id), &Action, sizeof(Action));
	NdisMoveMemory(pBuffer+LENGTH_802_3+sizeof(vendor_id)+sizeof(Action), &Type, sizeof(Type));
	NdisMoveMemory(pBuffer+LENGTH_802_3+sizeof(vendor_id)+sizeof(Action)+sizeof(Type), &DataLen, sizeof(USHORT));
	if ((DataLen > 0) && (pData != NULL))
		NdisMoveMemory(pBuffer+LENGTH_802_3+sizeof(vendor_id)+sizeof(Action)+sizeof(Type)+sizeof(USHORT), pData, DataLen);
	hex_dump("NfcCommand", pBuffer, len);
	RtmpOSNotifyRawData(pNetDev, pBuffer, len, 0, ETH_MTK_NFC);
	os_free_mem(NULL,pBuffer);
	return;
}
示例#28
0
VOID dump_vht_op(RTMP_ADAPTER *pAd, VHT_OP_IE *vht_ie)
{
	VHT_OP_INFO *vht_op = &vht_ie->vht_op_info;
	VHT_MCS_MAP *vht_mcs = &vht_ie->basic_mcs_set;
	
	DBGPRINT(RT_DEBUG_OFF, ("Dump VHT_OP IE\n"));	
	hex_dump("VHT OP IE Raw Data", (UCHAR *)vht_ie, sizeof(VHT_OP_IE));

	DBGPRINT(RT_DEBUG_OFF, ("VHT Operation Info Field\n"));
	DBGPRINT(RT_DEBUG_OFF, ("\tChannelWidth=%d\n", vht_op->ch_width));
	DBGPRINT(RT_DEBUG_OFF, ("\tChannelCenterFrequency Seg 1=%d\n", vht_op->center_freq_1));
	DBGPRINT(RT_DEBUG_OFF, ("\tChannelCenterFrequency Seg 1=%d\n", vht_op->center_freq_2));

	DBGPRINT(RT_DEBUG_OFF, ("VHT Basic MCS Set Field\n"));
	DBGPRINT(RT_DEBUG_OFF, ("\tRxMCS Map_1SS=%d\n", vht_mcs->mcs_ss1));
	DBGPRINT(RT_DEBUG_OFF, ("\tRxMCS Map_2SS=%d\n", vht_mcs->mcs_ss2));
}
示例#29
0
/* read generic data from the serial port */
int mwsp_read(int fd, char *buffer, int len)
{
    char *pbuf;
    int ttl, rd, rem, cnt;

    ttl = rd = cnt = 0;
    rem = len;

    memset(buffer, 0, len);
    pbuf = buffer;

    do {
        rd = read(fd, pbuf, rem);

        /* if we read something */
        if(rd > 0){
            ttl += rd;
            rem -= rd;

            pbuf += rd;

            /* we have read all we expected */
            if(ttl == len){
                break;
            }

            /* if not, read some more */
            if((ttl > 0) && (ttl < len)){
                continue;
            }
        }
        cnt++;
    } while((ttl < len) && (cnt < MWSP_SERIAL_RETRY));

    tcflush(fd, TCIOFLUSH);

#ifdef DEBUG
    hex_dump("mwsp_read", buffer, len);
#endif

    if(ttl == 0){
        return MWSP_ERR_READ;
    }

    return ttl;
}
示例#30
0
static void
syscall_handler (struct intr_frame *f) 
{
  
  printf ("In System call handler!\n");
  // Extracting Stack Pointer
  void * esp = f->esp;
  hex_dump(esp,esp,20,true);
  
  printf("Esp %p\n",esp); 
  // First 4 bytes represent sys
  int syscall_number = *((int *) esp);
  esp+= 4;


  
  
  //printf("Stack pointer %x\n",esp);
  char * buffer;
  int fd;
  unsigned length;
  switch (syscall_number)
  {
    case SYS_WRITE:

      fd = *((int *)esp);
      esp+=4;

      buffer = (char *)esp;
      //buffer = user_to_kernel_ptr((const void *) buffer);
      esp+=4;
      length = *((unsigned *)esp);
      esp+=4;
      printf("Boy want's to write\n");
      printf("Extracted Arguments:\n");
      printf("Buffer str: %s\n", buffer);
      printf("fd : %d\nbuffer: %p\nlength: %d\n",fd,(void *)buffer,length);
      break;
    default:
      printf("No match\n");
  }

  if (thread_tid () == child.id)
    child.flag = 1;
  thread_exit ();
}