| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | #include <fs/devfs.h> |
|---|
| 20 | #include <fs/vfs.h> |
|---|
| 21 | #include <init.h> |
|---|
| 22 | #include <net/network.h> |
|---|
| 23 | #include <net/socket.h> |
|---|
| 24 | #include <slab.h> |
|---|
| 25 | |
|---|
| 26 | struct Cache* netDeviceCache; |
|---|
| 27 | |
|---|
| 28 | #define NETWORK_MAJOR 128 |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | struct NetDevice* currDevice; |
|---|
| 32 | |
|---|
| 33 | struct NetDevice* NetDeviceAlloc() |
|---|
| 34 | { |
|---|
| 35 | return (struct NetDevice*)MemCacheAlloc(netDeviceCache); |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | int NetDeviceSend(struct NetDevice* device, struct SocketBuffer* buffer) |
|---|
| 41 | { |
|---|
| 42 | if (!device->ops || !device->ops->send) |
|---|
| 43 | return -ENOTIMPL; |
|---|
| 44 | |
|---|
| 45 | if (device-> state & NET_DEVICE_QUEUE_RUNNING) |
|---|
| 46 | return device->ops->send(device, buffer); |
|---|
| 47 | else{ |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | ListAddTail(&buffer->next, &device->sendList); |
|---|
| 52 | } |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | int NetDeviceIoCtl(struct File* file, unsigned long code, BYTE* data) |
|---|
| 56 | { |
|---|
| 57 | struct NetDevice* netDevice=currDevice; |
|---|
| 58 | |
|---|
| 59 | if (code >= 0x40000000) |
|---|
| 60 | { |
|---|
| 61 | if (netDevice->protoOps->ioctl) |
|---|
| 62 | return netDevice->protoOps->ioctl(netDevice, code, data); |
|---|
| 63 | else |
|---|
| 64 | return -ENOTIMPL; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | printf("NetDeviceIoCtl\n"); |
|---|
| 68 | return 0; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | struct FileOps netFileOps= |
|---|
| 72 | { |
|---|
| 73 | .ioctl = NetDeviceIoCtl, |
|---|
| 74 | }; |
|---|
| 75 | |
|---|
| 76 | int NetDeviceRegister(struct NetDevice* device) |
|---|
| 77 | { |
|---|
| 78 | char buf[32]; |
|---|
| 79 | |
|---|
| 80 | currDevice=device; |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | sprintf(buf, "Network/%s%d", device->name, 0); |
|---|
| 84 | |
|---|
| 85 | DevAddDevice(buf, NETWORK_MAJOR, 0, DEVICE_CHAR, &netFileOps); |
|---|
| 86 | INIT_LIST_HEAD(&device->sendList); |
|---|
| 87 | device->state = NET_DEVICE_UP | NET_DEVICE_QUEUE_RUNNING; |
|---|
| 88 | |
|---|
| 89 | return 0; |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | int NetDeviceInit() |
|---|
| 93 | { |
|---|
| 94 | netDeviceCache=MemCacheCreate("Network device cache", sizeof(struct NetDevice), NULL, NULL, 0); |
|---|
| 95 | return 0; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | NetInit(NetDeviceInit); |
|---|