]> Joshua Wise's Git repositories - netwatch.git/blame - net/net.c
add dolog hooks into lwip
[netwatch.git] / net / net.c
CommitLineData
3b3161a1 1#include <pci.h>
6c744a5a
JW
2#include <io.h>
3#include <video_defines.h>
4#include <smram.h>
4d898e0b 5#include <pci-bother.h>
3b3161a1 6#include <output.h>
14e7cde4 7#include <minilib.h>
9552cf46 8#include <lwip/init.h>
4d898e0b 9#include "net.h"
14e7cde4 10#include "../aseg/keyboard.h"
3b3161a1 11
7a914840 12static struct nic *_nic = 0x0;
3e6d6106 13
7a914840
JW
14extern struct pci_driver a3c90x_driver;
15
99182958
JW
16static char test[1024] = {0};
17
50d89a31
JP
18static char packet[4096] = {0};
19
20typedef struct packet_t {
21 char from[6];
22 char to[6];
23 unsigned short ethertype;
14e7cde4
JP
24 unsigned short datalen;
25 unsigned char command;
50d89a31
JP
26 char data[];
27} packet_t;
28
6c744a5a
JW
29static unsigned char vga_read(unsigned char idx)
30{
31 outb(CRTC_IDX_REG, idx);
32 return inb(CRTC_DATA_REG);
33}
34
35static unsigned int vga_base()
36{
37 return (((unsigned int) vga_read(CRTC_START_ADDR_MSB_IDX)) << 9)
38 + (((unsigned int) vga_read(CRTC_START_ADDR_LSB_IDX)) << 1);
39}
40
14e7cde4
JP
41void handle_command(packet_t * p)
42{
43 uint16_t dl = htons(p->datalen);
44 int i;
45
46 outputf("NIC: Command: 0x%x, %d bytes", p->command, dl);
47
31e64b08
JP
48 switch (p->command) {
49 case 0x42:
14e7cde4
JP
50 for (i = 0; i < dl; i++)
51 kbd_inject_key(p->data[i]);
31e64b08
JP
52 break;
53 case 0xFE:
54 outb(0xCF9, 0x4); /* Reboot */
55 break;
14e7cde4
JP
56 }
57}
58
7a914840 59void eth_poll()
3b3161a1 60{
99182958 61 int i;
6c744a5a
JW
62// static int c;
63 static short pos = 0x0;
64 unsigned short base = vga_base();
65 unsigned char *p = (unsigned char *)0xB8000;
66 smram_state_t old_state;
99182958
JW
67
68 if (!_nic)
69 return;
70
50d89a31
JP
71 if (_nic->poll(_nic, 0)) {
72 _nic->packet = packet;
73 _nic->poll(_nic, 1);
74
75 packet_t * p = (packet_t *) packet;
76
14e7cde4
JP
77 outputf("NIC: Packet: %d 0x%x", _nic->packetlen, htons(p->ethertype));
78 if (htons(p->ethertype) == 0x1338) {
79 if (htons(p->datalen) + sizeof(packet_t) > _nic->packetlen) {
80 outputf("NIC: Malformed packet");
81 } else {
82 handle_command(p);
83 }
50d89a31
JP
84 }
85 }
6c744a5a
JW
86 smram_tseg_set_state(SMRAM_TSEG_OPEN);
87 old_state = smram_save_state();
99182958 88
6c744a5a
JW
89// if ((c++) % 2)
90// return;
d3411e0d
JW
91
92 if (((base + 80*25*2)%0x8000) < base)
93 {
94 if ((pos > ((base + 80*25*2)%0x8000)) && (pos < base))
95 pos = base;
96 } else if ((pos > base + 80*25*2) || (pos < base))
97 pos = base;
6c744a5a
JW
98
99 test[0] = pos >> 8;
100 test[1] = pos & 0xFF;
101 test[2] = base >> 8;
102 test[3] = base & 0xFF;
103
104 smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
99182958 105
6c744a5a 106 for (i = 4; i < 1024; i++)
99182958 107 {
6c744a5a
JW
108 test[i] = p[pos++];
109 pos %= 0x8000;
99182958 110 }
6c744a5a 111 smram_restore_state(old_state);
99182958 112 _nic->transmit("\x00\x03\x93\x87\x84\x8C", 0x1337, 1024, test);
3b3161a1
JW
113}
114
7a914840 115int eth_register(struct nic *nic)
3b3161a1 116{
7a914840
JW
117 if (_nic)
118 return -1;
119 _nic = nic;
120 return 0;
3b3161a1
JW
121}
122
123void eth_init()
124{
c25f3f39
JW
125 /* Required for DMA to work. :( */
126 smram_tseg_set_state(SMRAM_TSEG_OPEN);
127 pci_probe_driver(a3c90x_driver);
9552cf46 128 lwip_init();
3b3161a1 129}
This page took 0.041495 seconds and 4 git commands to generate.