Difference between revisions of "New stack"

From KolibriOS wiki
Jump to navigation Jump to search
Line 1: Line 1:
== intro ==
 
 
 
;As you may or may not know, I (hidnplayr) am since long time working on a new network stack for KolibriOS<br>
 
;As you may or may not know, I (hidnplayr) am since long time working on a new network stack for KolibriOS<br>
;I will use this page for myself as a total image of what I have done so far, but also to inform others.
+
;I will use this page as an overview of what I have done so far.
  
 
== Kernel ==
 
== Kernel ==
Line 28: Line 26:
 
== Drivers ==
 
== Drivers ==
  
These new type network drivers are MS COFF files, just like the sound drivers in KolibriOS.<br>
+
In net-branch, the network drivers are external drivers, as described in [[Writing_drivers_for_KolibriOS]].<br />
;Notice that one driver can handle multiple devices.
 
 
 
Once the driver is loaded, an application (NetCFG) can use system function 68/17 ("Driver Control") to communicate with the driver.<br>
 
For this, it uses the IOCTL structure wich looks like this:
 
<asm>
 
struc IOCTL {
 
  .handle      dd ?
 
  .io_code    dd ?
 
  .input      dd ?
 
  .inp_size    dd ?
 
  .output      dd ?
 
  .out_size    dd ? 
 
}
 
</asm>
 
for more info about this, please read [[Writing_drivers_for_KolibriOS]]
 
 
 
Here is a list of opcodes:
 
;0 - Getversion
 
standard for all drivers, not only network drivers
 
 
 
;1 - Hook
 
Attach driver to a device<br>
 
 
 
IN: (ISA)
 
<asm>
 
type    db 0 ; isa
 
io_addr  dw ?
 
irq_line db ?
 
</asm>
 
 
 
IN: (PCI)
 
<asm>
 
type    db 1 ; pci
 
pci_bus  db ?
 
pci_dev  db ?
 
</asm>
 
 
 
OUT:<br>
 
eax = device number or -1 on error
 
 
 
 
 
----
 
 
 
 
 
Once the HOOK function of the driver has been called, the driver creates the NET_DEVICE structure, allocates some buffers needed for the driver, and calls the kernel function 'NetRegDev'.<br>
 
This function registers a networkdevice (device, not driver!) to the kernel.<br>
 
It only needs one parameter: pointer to device structure (NET_DEVICE) in ebx.<br>
 
The function returns the device number in edi (..wich the driver then sends to the application in eax, see above..)
 
 
 
This NET_DEVICE structure is created and filled in by the driver, for every device it is hooked to.<br>
 
The driver may use this to store pointers to buffers, descriptors,.. etc<br>
 
But the top of the structure must always look like this: (Since it is shared by the driver and the kernel)
 
 
 
<asm>
 
NET_DEVICE:
 
        .type          dd ?    ; Type field (ethernet/slip/...)
 
        .mtu            dd ?    ; Maximal Transmission Unit (in bytes)
 
        .name          dd ?    ; Ptr to 0 terminated string
 
 
 
        .unload        dd ?    ; Ptrs to driver functions
 
        .reset          dd ?    ;
 
        .transmit      dd ?    ;
 
 
 
        .bytes_tx      dq ?    ; Statistics, updated by the driver
 
        .bytes_rx      dq ?    ;
 
        .packets_tx    dd ?    ;
 
        .packets_rx    dd ?    ;
 
 
 
        .end:
 
</asm>
 
  
This is appended by a Type-specific structure, for ethernet this will be:
+
The specifications of the new network drivers can be found in the article [[Writing_network_drivers_for_KolibriOS]].<br />
  
<asm>
 
        .set_mode      dd ?
 
        .get_mode      dd ?
 
  
        .set_MAC        dd ?
 
        .get_MAC        dd ?
 
 
        .mode          dd ?
 
        .mac            dp ?   
 
</asm>
 
 
Wich is then followed by the private data for the driver.
 
 
 
When a packet is received by the driver, it copies it into a buffer allocated using 'KernelAlloc'.<br>
 
Then the driver pushes the size of the buffer and the pointer to the buffer onto the stack (in this particular order)<br>
 
And it calls 'EthReceiver' (or another procedure for another network device type).<br>
 
This kernel function will but the packet into the incoming queue, so the appropriate protocol handler can handle it later.
 
 
When the kernel needs to send a packet, it simple looks up the appropriate driver in it's driver table.<br>
 
In the table it will find the pointer to the device structure, so the driver can directly call the transmit function listed in the structure.
 
NOTE: the kernel will put the address of buffer to send in [esp+4], and length of that buffer in [esp+8]
 
 
----
 
 
== Status of the drivers ==
 
 
(items with a * are being worked on)
 
(items with a * are being worked on)
 
 
*RTL8139: Working (FIXME: error occurs on wrapping of the RX buffer).
 
*RTL8139: Working (FIXME: error occurs on wrapping of the RX buffer).
 
*SIS900: Working? (Written by clevermouse)
 
*SIS900: Working? (Written by clevermouse)
Line 170: Line 72:
 
''This program uses network.obj''
 
''This program uses network.obj''
  
== Upcoming ==
 
 
*;ICMP: program for sending ICMP echo reply's (ping) and trace-route.
 
  
 
== Libraries ==
 
== Libraries ==
  
*;network_lib: The network library for KolibriOS, written by Clevermouse, was ported to the net branch, by the same person
+
=== network_lib ===
 
+
The network library for KolibriOS, written by Clevermouse.
  
 
== I need your help! ==
 
== I need your help! ==
  
 
I would really appreciate it if somebody could write some network applications,<br>
 
I would really appreciate it if somebody could write some network applications,<br>
so I can further test the kernel code without having to code them myself now :),<br>  
+
So I can concentrate on kernel code now :),<br>  
 
If you are interessed please contact me at hidnplayr@kolibrios.org (or find me in #general on irc.kolibrios.org)
 
If you are interessed please contact me at hidnplayr@kolibrios.org (or find me in #general on irc.kolibrios.org)
  
 
[[Category:Coding]]
 
[[Category:Coding]]
 
[[Category:System_documentation]]
 
[[Category:System_documentation]]

Revision as of 17:31, 19 July 2010

As you may or may not know, I (hidnplayr) am since long time working on a new network stack for KolibriOS
I will use this page as an overview of what I have done so far.

Kernel

The old kernel functions 52 and 53 have been removed and the New_network_api has been created.

Internally, the stack has been completely rewritten (mostly from scratch)

  • What works
    • Attaching network drivers to the kernel
    • Sending and receiving Ethernet/IPv4/UDP/ICMP packets
    • IPv4/UDP/TCP checksum generation and confirmation
    • Queuing of packets (altough queing ethernet packets is disabled ATM)
    • UDP sockets
    • ~Working with multiple network card's (unfortunately, some kernel functions are hardcoded to a specific device ATM)
  • TODO (items with a * are currently being worked on)
    • Sending fragmented IPv4 packets
    • finish TCP code*
    • finish ARP code
    • IPC sockets (unix-like sockets)
    • RAW sockets
    • Port trunking (IEEE 802.1AX-2008)
    • ..

Drivers

In net-branch, the network drivers are external drivers, as described in Writing_drivers_for_KolibriOS.

The specifications of the new network drivers can be found in the article Writing_network_drivers_for_KolibriOS.


(items with a * are being worked on)

  • RTL8139: Working (FIXME: error occurs on wrapping of the RX buffer).
  • SIS900: Working? (Written by clevermouse)
  • 3c90x/3c59x: Working (only boomerang for now) (FIXME: may hang on UpUnstall procedure)
  • RTL8029: Working
  • PCnet32: Working
  • DEC21x4x*: Working in Virtual PC, but not on real hardware.
  • i8255x*: (Intel eepro 100): Work in progress (hidnplayr)
  • i8254x: (Intel eepro 1000): Planned for future (hidnplayr)
  • mtd80x: Planned for future (hidnplayr)

Programs

NetCFG

This is a program I wrote to load the drivers.
The program detects all PCI network cards in your computer, and lets you load the appropriate driver for it.
You can run it with paramters 'F' to silently load first detected card,or parameter 'A' to load all cards

Netstat

This program allows you to read some variables from the stack.

ARPcfg

This program allows you to view the ARP entries.
In future, you should be able to add and remove static entry's using this progam.

Zeroconf

This program is the newer version of what used to be 'autodhcp', it works with the new network API.

nslookup

Commandline DNS client from CleverMouse
This program uses network.obj

TFTPc

A TFTP client with a GUI.
This program can receive and send files, using libio.obj, network.obj and box_lib.obj

Telnet

A new telnet client, based on the code of nslookup (usefull to test TCP code)
This program uses network.obj


Libraries

network_lib

The network library for KolibriOS, written by Clevermouse.

I need your help!

I would really appreciate it if somebody could write some network applications,
So I can concentrate on kernel code now :),
If you are interessed please contact me at hidnplayr@kolibrios.org (or find me in #general on irc.kolibrios.org)