Skip to content

Commit bd75b08

Browse files
committed
adding fixes
1 parent 3c221ae commit bd75b08

File tree

18 files changed

+893
-859
lines changed

18 files changed

+893
-859
lines changed

SanderOSUSB.0

4.03 KB
Binary file not shown.

boot/pxe/pxeentry.bin

4.03 KB
Binary file not shown.

cdrom.iso

4 KB
Binary file not shown.

include/symbols.h

+306-305
Large diffs are not rendered by default.

kernel.bin

4.03 KB
Binary file not shown.

kernel/dev/e1000.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ struct e1000_tx_desc {
119119
#define TSTA_LC (1 << 2) // Late Collision
120120
#define LSTA_TU (1 << 3) // Transmit Underrun
121121

122-
#define E1000_NUM_RX_DESC 512
122+
#define E1000_NUM_RX_DESC 32
123123
#define E1000_NUM_TX_DESC 8
124124

125125
unsigned long base_addr;
@@ -194,13 +194,15 @@ void irq_e1000(){
194194
}
195195

196196
int e1000_send_package(PackageRecievedDescriptor desc){
197+
int old = tx_cur;
197198
tx_descs[tx_cur]->addr_1 = (unsigned long)desc.low_buf;
198199
tx_descs[tx_cur]->addr_2 = (unsigned long)desc.high_buf;
199200
tx_descs[tx_cur]->length = desc.buffersize;
200201
tx_descs[tx_cur]->cmd = CMD_EOP | CMD_IFCS | CMD_RS;
201202
tx_descs[tx_cur]->status = 0;
202203
tx_cur = (tx_cur + 1) % E1000_NUM_TX_DESC;
203204
e1000_write_in_space(REG_TXDESCTAIL, tx_cur);
205+
while(!tx_descs[old]->status);
204206
return 1;
205207
}
206208

@@ -291,7 +293,7 @@ void init_e1000(int bus,int slot,int function){
291293
ptr = (unsigned char *)(malloc(sizeof(struct e1000_rx_desc)*E1000_NUM_RX_DESC + 16));
292294

293295
descs = (struct e1000_rx_desc *)ptr;
294-
for(int i = 0; i < 100; i++)
296+
for(int i = 0; i < E1000_NUM_RX_DESC; i++)
295297
{
296298
rx_descs[i] = (struct e1000_rx_desc *)((unsigned char *)descs + i*16);
297299
rx_descs[i]->addr_1 = (unsigned long)(unsigned char *)(malloc(8192 + 16));
@@ -342,7 +344,7 @@ void init_e1000(int bus,int slot,int function){
342344

343345
//
344346
// set interrupts
345-
// e1000_enable_int();
347+
e1000_enable_int();
346348
e1000_link_up();
347349

348350
//

kernel/dev/ethernet.c

+37-21
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,15 @@ void fillTcpHeader(struct TCPHeader *tcpheader,unsigned char *destmac,unsigned s
214214
tcpheader->checksum = 0;
215215
tcpheader->urgent_pointer = 0;
216216

217-
struct tcp_checksum_header* trx = (struct tcp_checksum_header*)malloc(sizeof(struct tcp_checksum_header));
217+
int payload = ( size - (sizeof(struct TCPHeader) - sizeof(struct EthernetHeader)) );
218+
unsigned char *start = (unsigned char*)malloc(sizeof(struct tcp_checksum_header) + payload);
219+
unsigned char *end = start;
220+
end += (sizeof(struct tcp_checksum_header) + payload);
221+
222+
struct tcp_checksum_header* trx = (struct tcp_checksum_header*)start;
218223
trx->dst = (to);
219224
trx->src = (from);
220-
trx->len = switch_endian16(20);
225+
trx->len = switch_endian16(20 + payload);
221226
trx->protocol = IPV4_TYPE_TCP;
222227
trx->source_port = switch_endian16(from_port);
223228
trx->destination_port = switch_endian16(to_port);
@@ -228,7 +233,7 @@ void fillTcpHeader(struct TCPHeader *tcpheader,unsigned char *destmac,unsigned s
228233
trx->checksum = 0;
229234
trx->urgent_pointer = 0;
230235

231-
tcpheader->checksum = switch_endian16(net_checksum((const unsigned char*)trx,(const unsigned char*)(trx+sizeof(struct tcp_checksum_header))));
236+
tcpheader->checksum = switch_endian16(net_checksum(start, end));
232237
}
233238

234239
void fillDhcpDiscoverHeader(struct DHCPDISCOVERHeader *dhcpheader){
@@ -442,28 +447,31 @@ unsigned char* getIPFromName(char* name){
442447
return targetip;
443448
}
444449

445-
void create_tcp_session(unsigned long from, unsigned long to, unsigned short from_port, unsigned short to_port){
450+
unsigned long ethjmplist[20000];
451+
452+
void setTcpHandler(unsigned short port,unsigned long func){
453+
ethjmplist[port] = func;
454+
}
455+
456+
void create_tcp_session(unsigned long from, unsigned long to, unsigned short from_port, unsigned short to_port, unsigned long func){
446457
unsigned long sizetype = sizeof(struct TCPHeader);
447458
struct TCPHeader* tcp1 = (struct TCPHeader*) malloc(sizetype);
448459
unsigned char* destmac;
449460
unsigned char* t4 = (unsigned char*)&to;
450-
if(t4[0]==192){
451-
destmac = getMACFromIp(t4);
452-
}else{
453-
destmac = (unsigned char*)&router_ip;
454-
}
461+
462+
destmac = getMACFromIp(t4);
455463
unsigned short size = sizeof(struct TCPHeader) - sizeof(struct EthernetHeader);
456464
fillTcpHeader(tcp1,destmac,size,from,to,from_port,to_port,1,0,5,TCP_SYN,512);
457465

466+
setTcpHandler(to_port,func);
467+
458468
PackageRecievedDescriptor sec;
459469
sec.buffersize = sizetype;
460470
sec.high_buf = 0;
461471
sec.low_buf = (unsigned long)tcp1;
462472
sendEthernetPackage(sec);
463473
}
464474

465-
unsigned long ethjmplist[20000];
466-
467475
int ethernet_handle_package(PackageRecievedDescriptor desc){
468476
struct EthernetHeader *eh = (struct EthernetHeader*) desc.low_buf;
469477
if(eh->type==ETHERNET_TYPE_ARP){
@@ -544,7 +552,7 @@ int ethernet_handle_package(PackageRecievedDescriptor desc){
544552
unsigned long addr = desc.low_buf + sizeof(struct TCPHeader);
545553
unsigned long count = desc.buffersize-sizeof(struct TCPHeader);
546554
unsigned long func = ethjmplist[switch_endian16(tcp->destination_port)];
547-
// debugf("[ETH] TCP message reieved: size=%x string=%s \n",count,(unsigned char*)addr);
555+
debugf("[ETH] TCP message reieved: size=%x string=%s \n",count,(unsigned char*)addr);
548556
if(func){
549557
debugf("[ETH] function handler is about to get called\n");
550558
int (*sendPackage)(unsigned long a,unsigned long b) = (void*)func;
@@ -555,6 +563,22 @@ int ethernet_handle_package(PackageRecievedDescriptor desc){
555563
}
556564
}
557565
return 1;
566+
}else if(ip->protocol==IPV4_TYPE_ICMP){
567+
struct ICMPHeader *icmp = (struct ICMPHeader*) ip;
568+
if(icmp->type==8){
569+
debugf("[ETH] ICMP ping request found!\n");
570+
571+
// struct ICMPHeader *newicmp = (struct ICMPHeader*) malloc(sizeof(struct ICMPHeader));
572+
573+
// fillIpv4Header((struct IPv4Header*)&newicmp->ipv4header,(unsigned char*)icmp->ipv4header.ethernetheader.from,size,IPV4_TYPE_ICMP,from,to);
574+
575+
// PackageRecievedDescriptor sec;
576+
// sec.buffersize = sizeof(struct ICMPHeader);
577+
// sec.high_buf = 0;
578+
// sec.low_buf = (unsigned long)newicmp;
579+
// sendEthernetPackage(sec);
580+
return 1;
581+
}
558582
}
559583
}
560584
return 0;
@@ -565,6 +589,7 @@ unsigned long getOurIpAsLong(){
565589
}
566590

567591
void exsend(unsigned long addr,unsigned long count){
592+
printf("Recieved message: ");
568593
for(unsigned long i = 0 ; i < count ; i++){
569594
printf("%c",((unsigned char*)addr)[i]);
570595
}
@@ -598,15 +623,6 @@ void initialise_ethernet(){
598623
debugf("[ETH] DNS IP is %d.%d.%d.%d \n",dns_ip[0],dns_ip[1],dns_ip[2],dns_ip[3]);
599624
debugf("[ETH] DHCP IP is %d.%d.%d.%d \n",dhcp_ip[0],dhcp_ip[1],dhcp_ip[2],dhcp_ip[3]);
600625

601-
// 192.168.2.68
602-
unsigned char xxx[SIZE_OF_IP];
603-
xxx[0] = 192;
604-
xxx[1] = 168;
605-
xxx[2] = 2;
606-
xxx[3] = 68;
607-
ethjmplist[19696] = (unsigned long)&exsend;
608-
create_tcp_session(getOurIpAsLong(), ((unsigned long*)&xxx)[0], 19696, 19696);printf("verzonden\n");for(;;);
609-
610626
unsigned char* srve = getIPFromName("tftp.local");
611627
if(srve[0]){
612628
printf("[ETH] TFTP IP is %d.%d.%d.%d \n",srve[0],srve[1],srve[2],srve[3]);

kernel/kernel.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void kernel_main(GRUBMultiboot *grub, unsigned long magic){
205205
poweroff();
206206
}
207207

208-
if(confirm("kernel created by sander de regt, shashwat shagun, johan gericke, daniel mccarthy, jark clim and pablo narvaja") == 0) {
208+
if(confirm("kernel created by sander de regt, shashwat shagun, johan gericke, daniel mccarthy, jark clim, pablo narvaja, nelson cole") == 0) {
209209
poweroff();
210210
};
211211

kernel/kernel.h

+14
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ void initialiseTFTP(Device *device);
417417
#define ETHERNET_TYPE_IP4 0x0008
418418
#define IPV4_TYPE_UDP 0x11
419419
#define IPV4_TYPE_TCP 0x06
420+
#define IPV4_TYPE_ICMP 0x01
420421
#define TCP_FIN 0b000000000001
421422
#define TCP_SYN 0b000000000010
422423
#define TCP_RES 0b000000000100
@@ -464,6 +465,19 @@ struct IPv4Header{
464465
unsigned long dest_addr;
465466
} __attribute__ ((packed));
466467

468+
struct ICMPHeader{
469+
struct IPv4Header ipv4header;
470+
unsigned char type;
471+
unsigned char code;
472+
unsigned short checksum;
473+
unsigned short ident_BE;
474+
unsigned short ident_LE;
475+
unsigned short seqe_BE;
476+
unsigned short seqe_LE;
477+
unsigned char timestamp[8];
478+
unsigned char data[1392];
479+
} __attribute__ ((packed));
480+
467481
struct UDPHeader{
468482
struct IPv4Header ipv4header;
469483
unsigned short source_port;

kernel/myos.bin

4.03 KB
Binary file not shown.

lib/libsos.a

4.04 KB
Binary file not shown.

programs/basic.bin

0 Bytes
Binary file not shown.

programs/basic/basic

0 Bytes
Binary file not shown.

programs/basic/basic.o

0 Bytes
Binary file not shown.

programs/sedit.bin

0 Bytes
Binary file not shown.

programs/sedit/sedit

0 Bytes
Binary file not shown.

programs/sedit/sedit.o

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)