prajwal wrote:
1. If not writing code from scratch, would Linux kernel open-source have required code/library/modules that can be ported - is that feasible ?
I'm sure the Linux drivers can be ported, but I doubt it would be easy. Haiku also has some open-source wireless drivers.
prajwal wrote:
2. Even if I am able to port, what does the device driver code correspond to in network protocol stack ? the PHY/Data link layer ?
Yes. The device driver, whether it's wireless or ethernet transmits and receives packets across the physical network.
prajwal wrote:
3. Appreciate if you can point me to some guide and/or explain (in brief) what are the different layers/protocol stacks to implement to build support up-to TCP/IP ?
A minimalist TCP/IP stack must implement at least IP, ARP, ICMP, UDP and TCP. Of course, you'll need other things to make it practical, like DHCP which will allow you to have an IP address at all, and detect the router, DNS server, and other useful information.
prajwal wrote:
4. Which module should I port from Linux open-source and which ones are feasible to write by myself (if any) ? (judging by the level of complexity I can deal with by writing XHCI driver) - in a time-frame say 200 hrs of development
I can't really answer this question, TBH.
If you want to implement networking, I'd suggest going with ethernet first, because it's much simpler than Wi-Fi, more people here (including myself) have implemented it, and there are more cards which have free specifications. Something relatively easy to start with is the RTL8139 or Intel i8254x cards.
As for the network stack itself, which isn't much different whether it's ethernet or Wi-Fi, you'd implement it in layers. There would be a link layer, which communicates with the ethernet/wireless driver directly to transmit/receive packets using MAC addresses. On top of the link layer, you would implement IP and ARP. ARP allows you to resolve IP addresses into MAC addresses. Just like your ARP layer can request other devices' MAC addresses, it also has to respond when someone requests your MAC address. On top of IP, you would implement the transport/control protocols, UDP, TCP and ICMP. Then you can implement any application-level protocols you'd like, such as DHCP, DNS, HTTP, NTP, and any others you can think of.
You'll definitely need Wireshark, and a dump of all the packets passing through your code. QEMU's "-net dump,file=file.pcap" option will help a lot here. This will help you verify that the network driver works at all.