Page 1 of 1

ARP format problem

Posted: Tue Oct 11, 2016 8:17 pm
by Raymond
I successfully received the frames of ne2000.I send a arp format message.as below

Code: Select all

void make_arp_pac(){
	nic_data[0] = 0xff;
	nic_data[1] = 0xff;
	nic_data[2] = 0xff;
	nic_data[3] = 0xff;
	nic_data[4] = 0xff;
	nic_data[5] = 0xff;
	nic_data[6] = 0xb0;
	nic_data[7] = 0xc4;
	nic_data[8] = 0x20;
	nic_data[9] = 0x00;
	nic_data[10] = 0x00;
	nic_data[11] = 0x01;
	nic_data[12] = 0x00;
	nic_data[13] = 0x01;//frame type
	nic_data[14] = 0x00;
	nic_data[15] = 0x01;//hardware type
	nic_data[16] = 0x08;
	nic_data[17] = 0x06;//arp type
	nic_data[18] = 0x06;
	nic_data[19] = 0x04;
	nic_data[20] = 0x00;
	nic_data[21] = 0x01;//op code
	nic_data[22] = 0xb0;
	nic_data[23] = 0xc4;
	nic_data[24] = 0x20;
	nic_data[25] = 0x00;
	nic_data[26] = 0x00;
	nic_data[27] = 0x01;//source mac address
	nic_data[28] = 0xC0;
	nic_data[29] = 0xA8;
	nic_data[30] = 0x00;
	nic_data[31] = 0x65;//source ip address
	nic_data[32] = 0x00;
	nic_data[33] = 0x00;
	nic_data[34] = 0x00;
	nic_data[35] = 0x00;
	nic_data[36] = 0x00;
	nic_data[37] = 0x00;
	nic_data[38] = 0xC0;
	nic_data[39] = 0xA8;
	nic_data[40] = 0x00;
	nic_data[41] = 0x01;//destnation ip address
	
}
Who can tell me what happened to my os to get below message that is so strange.
(At begining,4 byte is not message of arp.)

Re: ARP format problem

Posted: Wed Oct 12, 2016 12:22 am
by Octocontrabass

Code: Select all

6E 69 63 20 73 74 61 74 20 36 65 2C 36 39 2C 36
35 2C 32 65 2C 33 36 2C 33 33 2C 33 36 2C 32 63
"nic stat 6e,69,65,2e,36,33,36,2c"

Are you sure you're displaying the contents of the right buffer?

Re: ARP format problem

Posted: Wed Oct 12, 2016 2:41 am
by Raymond
No,I know those values are wrong,but my ISR register is 0x43 -- 1000011,that two bit at last of ISR means send and receive successfully ,am I right?

It must be problems of format of ARP,who can tell me ,is there any error on my format of arp?

ray

Re: ARP format problem

Posted: Wed Oct 12, 2016 2:51 am
by Octocontrabass
I think you missed my point. The hex dump you've got there is the ASCII values of the text "nic stat 6e,69,65,2e,36,33,36,2c" and obviously not the data coming from the network.

Re: ARP format problem

Posted: Wed Oct 12, 2016 3:18 am
by Raymond
Yes,i have the same idea,maybe i should clear the ISR after sending the data,
the code must have problem,the code as follow

Code: Select all

//net.c
#include "bootpack.h"
#include <stdio.h>
#define PCI_BUS_CONFIG(bus,dev,func,reg) 0x80000000|(bus<<16)|(dev&0x1f<<11)|(func&0x07<<8)|(reg&0x3f<<2)|0x00
char *ns;
int nic_flag;
int ioaddr;
char *nic_data;
char *nic_rev_data;
char nstatus;
char nstatus2;
void inthandler2b(int *esp)
/*  */
{
	io_out8(PIC1_OCW2, 0x63);//nic interrupt
	io_out8(PIC0_OCW2, 0x62);
	nic_flag = 1;
	return;
}
void make_arp_pac(){
	nic_data[0] = 0xff;
	nic_data[1] = 0xff;
	nic_data[2] = 0xff;
	nic_data[3] = 0xff;
	nic_data[4] = 0xff;
	nic_data[5] = 0xff;
	nic_data[6] = 0xb0;
	nic_data[7] = 0xc4;
	nic_data[8] = 0x20;
	nic_data[9] = 0x00;
	nic_data[10] = 0x00;
	nic_data[11] = 0x01;
	nic_data[12] = 0x00;
	nic_data[13] = 0x01;//frame type
	nic_data[14] = 0x00;
	nic_data[15] = 0x01;//hardware type
	nic_data[16] = 0x08;
	nic_data[17] = 0x06;//arp type
	nic_data[18] = 0x06;
	nic_data[19] = 0x04;
	nic_data[20] = 0x00;
	nic_data[21] = 0x01;//op code
	nic_data[22] = 0xb0;
	nic_data[23] = 0xc4;
	nic_data[24] = 0x20;
	nic_data[25] = 0x00;
	nic_data[26] = 0x00;
	nic_data[27] = 0x01;//source mac address
	nic_data[28] = 0xC0;
	nic_data[29] = 0xA8;
	nic_data[30] = 0x00;
	nic_data[31] = 0x65;//source ip address
	nic_data[32] = 0x00;
	nic_data[33] = 0x00;
	nic_data[34] = 0x00;
	nic_data[35] = 0x00;
	nic_data[36] = 0x00;
	nic_data[37] = 0x00;
	nic_data[38] = 0xC0;
	nic_data[39] = 0xA8;
	nic_data[40] = 0x00;
	nic_data[41] = 0x01;//destnation ip address
	
}
void ne_send_packets(struct BOOTINFO *binfo,int lba_num,short count){
	int addr,data;
	char bus,dev,func,reg;
	reg = 0x10;
	int i;
	int net_mem = 0x40;
	
	
	ioaddr = 0xc040;
	addr = PCI_BUS_CONFIG(0,3,0,reg);
	io_out32(0xCF8,addr);
	io_out32(0xCFC,ioaddr);

	make_arp_pac();
	io_out8(ioaddr+0x00,0x22);//COMMAND register set to "start" and "nodma"
	io_out8(ioaddr+0x04,0x40);//TPSR tx_start_page
	io_out8(ioaddr+0x05,count&0xff);// TBCR0 tx_bytes low
	io_out8(ioaddr+0x06,(count>>8)&0xff);// TBCR1 tx_bytes high
	io_out8(ioaddr+0x07,(1<<6));//Remote DMA complete? ISR
	io_out8(ioaddr+0x08,0x00);//loaded with 0x00 (low)
	io_out8(ioaddr+0x09,0x40);//target page number (high)
	io_out8(ioaddr+0x0a,count&0xff);//low byte count
	io_out8(ioaddr+0x0b,(count>>8)&0xff);//high byte count
	//io_out8(ioaddr+0x0f,0x02);//set IMR receive irq allowed
	
	for(i=0;i<42;i++){
		io_out8(ioaddr+0x10,nic_data[i]);
	}
	do{
		nstatus = io_in8(ioaddr+0x07);
	}while((nstatus&0x40)==0);
	
	io_out8(ioaddr+0x00,0x14);//COMMAND register set to "start" and "remote write DMA" (0x12)
	do{
		nstatus = io_in8(ioaddr+0x07);
	}while((nstatus&0x02)==0);
	//sprintf(ns,"nic int %x",nstatus);
	//putfonts8_asc(binfo->vram, binfo->scrnx, 0, 32, COL8_FFFFFF, ns);
}
void init_net(struct BOOTINFO *binfo){
	sprintf(ns,"init net");
	putfonts8_asc(binfo->vram, binfo->scrnx, 0, 16, COL8_FFFFFF, ns);
	
	short count = 42;
	//ne_send_packets(binfo,0,count);
	int addr,data;
	char bus,dev,func,reg;
	reg = 0x10;
	int i;
	int net_mem = 0x40;
	ioaddr = 0xc040;
	addr = PCI_BUS_CONFIG(0,3,0,reg);
	io_out32(0xCF8,addr);
	io_out32(0xCFC,ioaddr);
	
	ne_send_packets(binfo,0,count);

	io_out8(ioaddr+0x00,0x0A);//start the controller and set read bit
	io_out8(ioaddr+0x01,0x40);//set start page address
	io_out8(ioaddr+0x02,0x43);//set stop page address
	io_out8(ioaddr+0x0C,0x02|0x10);//set runts_ok bit and promise bit
	io_out8(ioaddr+0x0D,0x02);//set TCR loop mode 01
	io_out8(ioaddr+0x0E,0x08);//set loop bit of DCR
	//io_out8(ioaddr+0x0F,0x01);//set IMR receive irq allowed
	io_out8(ioaddr+0x00,0x04);//set command register
	do{
		nstatus2 = io_in8(ioaddr+0x07);
	}while((nstatus2&0x01)==0);
	
	//sprintf(ns,"nic status %x",nstatus2);
	//putfonts8_asc(binfo->vram, binfo->scrnx, 0, 32, COL8_FFFFFF, ns);
	
	for(i=0;i<50;i++){
		nic_rev_data[i] = io_in8(ioaddr+0x10);
	}
	do{
		nstatus2 = io_in8(ioaddr+0x07);
	}while((nstatus2&0x40)==0);
	sprintf(ns,"nic status %x",nstatus2);
	putfonts8_asc(binfo->vram, binfo->scrnx, 0, 32, COL8_FFFFFF, ns);
	sprintf(ns,"nic data %x,%x,%x,%x,%x,%x,%x,%x",nic_rev_data[0],nic_rev_data[1],nic_rev_data[2],nic_rev_data[3],nic_rev_data[4],nic_rev_data[5],nic_rev_data[6],nic_rev_data[7]);
	putfonts8_asc(binfo->vram, binfo->scrnx, 0, 48, COL8_FFFFFF, ns);
	sprintf(ns,"nic data %x,%x,%x,%x,%x,%x,%x,%x",nic_rev_data[8],nic_rev_data[9],nic_rev_data[10],nic_rev_data[11],nic_rev_data[12],nic_rev_data[13],nic_rev_data[14],nic_rev_data[15]);
	putfonts8_asc(binfo->vram, binfo->scrnx, 0, 64, COL8_FFFFFF, ns);
	sprintf(ns,"nic data %x,%x,%x,%x,%x,%x,%x,%x",nic_rev_data[16],nic_rev_data[17],nic_rev_data[18],nic_rev_data[19],nic_rev_data[20],nic_rev_data[21],nic_rev_data[22],nic_rev_data[23]);
	putfonts8_asc(binfo->vram, binfo->scrnx, 0, 80, COL8_FFFFFF, ns);
	sprintf(ns,"nic data %x,%x,%x,%x,%x,%x,%x,%x",nic_rev_data[24],nic_rev_data[25],nic_rev_data[26],nic_rev_data[27],nic_rev_data[28],nic_rev_data[29],nic_rev_data[30],nic_rev_data[31]);
	putfonts8_asc(binfo->vram, binfo->scrnx, 0, 96, COL8_FFFFFF, ns);
	sprintf(ns,"nic data %x,%x,%x,%x,%x,%x,%x,%x",nic_rev_data[32],nic_rev_data[33],nic_rev_data[34],nic_rev_data[35],nic_rev_data[36],nic_rev_data[37],nic_rev_data[38],nic_rev_data[39]);
	putfonts8_asc(binfo->vram, binfo->scrnx, 0, 112, COL8_FFFFFF, ns);
}

Re: ARP format problem

Posted: Wed Oct 12, 2016 3:45 am
by Octocontrabass
Raymond wrote:

Code: Select all

char *ns;

char *nic_data;
char *nic_rev_data;
These three pointers are null (i.e. pointing to 0), and since they all point to the same thing, your sprintf() calls that fill ns are also overwriting nic_data. You need to allocate space for your buffers before you can use them.

Re: ARP format problem

Posted: Wed Oct 12, 2016 4:57 am
by Raymond
Yes,you are right, 6e is just 'n' of nic words.I change the code ,but i have not to write memory part ,i use a way below:

Code: Select all

char *nic_data=0x00400000;
char *nic_rev_data = 0x00400200;
but result is all 0.why?

Re: ARP format problem

Posted: Wed Oct 12, 2016 5:06 am
by Octocontrabass
Is there usable memory mapped at those addresses?

Re: ARP format problem

Posted: Wed Oct 12, 2016 5:21 am
by Raymond
my os is free from 0x00400000, i test it in the ata , i stop the ata module and use it at here.

my memory map:
    • 0x00000000 - 0x000fffff :VRAM(1MB)
      0x00100000 - 0x00267fff : save floppy
      0x00268000 - 0x0026f7ff : empty 30kb
      0x0026f800 - 0x0026ffff : IDT(2KB)
      0x00270000 - 0x0027ffff : GDT(64KB)
      0x00280000 - 0x002fffff : bootpack.hrb(512KB)
      0x00300000 - 0x003fffff : stack and other 1mb
      0x00400000 - :empty

Re: ARP format problem

Posted: Wed Oct 12, 2016 1:22 pm
by Octocontrabass
Are you initializing it correctly? It looks like you might be missing some required initialization steps.

Re: ARP format problem

Posted: Wed Oct 12, 2016 2:29 pm
by iansjack
What does the frame look like in Wireshark?

Re: ARP format problem

Posted: Wed Oct 12, 2016 8:14 pm
by Raymond
Below pic is my wireshark ,it tell me that 'malformed' ,can you find the error for me ,i really don't have an idea.

Maybe my mac addr is from bochs config file,is not real mac.

Re: ARP format problem

Posted: Wed Oct 12, 2016 8:42 pm
by Raymond
I have changed the arp data ,and i get correct data in the wireshark,but return value is still 0.

Code: Select all

void make_arp_pac(){
	nic_data[0] = 0xff;
	nic_data[1] = 0xff;
	nic_data[2] = 0xff;
	nic_data[3] = 0xff;
	nic_data[4] = 0xff;
	nic_data[5] = 0xff;
	nic_data[6] = 0x08;
	nic_data[7] = 0x62;
	nic_data[8] = 0x66;
	nic_data[9] = 0xC7;
	nic_data[10] = 0x9F;
	nic_data[11] = 0x69;
	nic_data[12] = 0x08;
	nic_data[13] = 0x06;//frame type
	nic_data[14] = 0x00;
	nic_data[15] = 0x01;//hardware type
	nic_data[16] = 0x08;
	nic_data[17] = 0x00;//arp type
	nic_data[18] = 0x06;
	nic_data[19] = 0x04;
	nic_data[20] = 0x00;
	nic_data[21] = 0x01;//op code
	nic_data[22] = 0x08;
	nic_data[23] = 0x62;
	nic_data[24] = 0x66;
	nic_data[25] = 0xC7;
	nic_data[26] = 0x9F;
	nic_data[27] = 0x69;//source mac address
	nic_data[28] = 0xC0;
	nic_data[29] = 0xA8;
	nic_data[30] = 0x00;
	nic_data[31] = 0x65;//source ip address
	nic_data[32] = 0x00;
	nic_data[33] = 0x00;
	nic_data[34] = 0x00;
	nic_data[35] = 0x00;
	nic_data[36] = 0x00;
	nic_data[37] = 0x00;
	nic_data[38] = 0xC0;
	nic_data[39] = 0xA8;
	nic_data[40] = 0x00;
	nic_data[41] = 0x01;//destnation ip address
	
}

Re: ARP format problem

Posted: Wed Oct 12, 2016 8:48 pm
by Raymond
Octocontrabass, can you give me a simple of initialize code for ne2000 that are nessary and easy to read?

And should I set the broadcast bit of RCR to receive the data?because now sending seems ok.

thanks,
ray

Re: ARP format problem

Posted: Thu Oct 13, 2016 4:13 am
by Raymond
Finally,i received the data.
I have not set the start page pointer,stop pointer,current page pointer and boundary pointer
It is the code below(my hub mac is c8 3a 35 28 83 00) and i should use right mac in bochs ne2k config:
'mac=08:62:66:c7:9f:69'

Code: Select all

ne_send_packets(binfo,0,count);
	for(i=0;i<1024;i++){
		nic_rev_data[i] = 0x08;
	}
	io_out8(ioaddr+0x00,0x40);//select page1 function
	io_out8(ioaddr+0x07,0x46);//set current page pointer
	io_out8(ioaddr+0x00,0x0A);//start the controller and set read bit
	io_out8(ioaddr+0x01,0x46);//set start page address
	io_out8(ioaddr+0x02,0x80);//set stop page address
	io_out8(ioaddr+0x03,0x49);//set boundary pointer
	io_out8(ioaddr+0x07,0x41);//clear the ISR
	io_out8(ioaddr+0x08,0x00);//loaded with 0x00 (remote dma low)
	io_out8(ioaddr+0x09,0x46);//target page number (remote dma high)
	io_out8(ioaddr+0x0a,60&0xff);//low byte count
	io_out8(ioaddr+0x0b,(60>>8)&0xff);//high byte count
	io_out8(ioaddr+0x0C,0x02|0x10);//set runts_ok bit and promise bit
	io_out8(ioaddr+0x0D,0x02);//set TCR loop mode 01
	io_out8(ioaddr+0x0E,0x08);//set loop bit of DCR
	//io_out8(ioaddr+0x0F,0x01);//set IMR receive irq allowed
	do{
		nstatus2 = io_in8(ioaddr+0x07);
	}while((nstatus2&0x01)==0);
	io_out8(ioaddr+0x00,0x04);//set command register
	
	
	//sprintf(ns,"nic status %x",nstatus2);
	//putfonts8_asc(binfo->vram, binfo->scrnx, 0, 32, COL8_FFFFFF, ns);
	
	for(i=0;i<1024;i++){
		nic_rev_data[i] = io_in8(ioaddr+0x10)&0xff;
	}
	do{
		nstatus2 = io_in8(ioaddr+0x07);
	}while((nstatus2&0x01)==0);
	sprintf(ns,"nic status %x",nstatus2);
	putfonts8_asc(binfo->vram, binfo->scrnx, 0, 32, COL8_FFFFFF, ns);
	sprintf(ns," %2x,%2x",nic_rev_data[10],nic_rev_data[11]);
	putfonts8_asc(binfo->vram, binfo->scrnx, 0, 48, COL8_FFFFFF, ns);