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