The Pedigree Project  0.1
net.cc
1 /*
2  * Copyright (c) 2007 Kevin Wolf
3  *
4  * This program is free software. It comes without any warranty, to
5  * the extent permitted by applicable law. You can redistribute it
6  * and/or modify it under the terms of the Do What The Fuck You Want
7  * To Public License, Version 2, as published by Sam Hocevar. See
8  * http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9  */
10 
11 #include <cdi/lists.h>
12 #include <cdi/net.h>
13 #include <cdi/pci.h>
14 #include <stdbool.h>
15 #include <stddef.h>
16 #include "cdi-osdep.h"
17 #include "cdi.h"
18 #include "pedigree/kernel/compiler.h"
19 #include "pedigree/kernel/processor/types.h"
20 
21 static unsigned long netcard_highest_id = 0;
22 static cdi_list_t netcard_list;
23 // FIXME: Sollten wahrscheinlich pro device sein und nicht nur pro driver
24 static cdi_list_t ethernet_packet_receivers;
25 
26 static bool bListsDefined = false;
27 
28 typedef unsigned long dword;
29 
30 extern "C"
31 {
32  void cdi_cpp_net_register(void* void_pdev, struct cdi_net_device* dev);
33  struct cdi_net_device* cdi_net_get_device(int num);
34 };
35 
36 /*
37 static void rpc_send_packet
38  (pid_t pid, dword cid, size_t data_size, void* data);
39 static void rpc_register_receiver
40  (pid_t pid, dword cid, size_t data_size, void* data);
41 */
42 
46 EXPORTED_PUBLIC void cdi_net_driver_init(struct cdi_net_driver* driver)
47 {
48  driver->drv.type = CDI_NETWORK;
49  cdi_driver_init(reinterpret_cast<struct cdi_driver*>(driver));
50 
51  if(!bListsDefined)
52  {
53  netcard_list = cdi_list_create();
54  ethernet_packet_receivers = cdi_list_create();
55  bListsDefined = true;
56  }
57 
58 // register_message_handler(RPC_ETHERNET_SEND_PACKET, rpc_send_packet);
59 // register_message_handler(RPC_ETHERNET_REGISTER_RECEIVER, rpc_register_receiver);
60 }
61 
65 EXPORTED_PUBLIC void cdi_net_driver_destroy(struct cdi_net_driver* driver)
66 {
67  cdi_driver_destroy(reinterpret_cast<struct cdi_driver*>(driver));
68 }
69 
73 EXPORTED_PUBLIC void cdi_net_device_init(struct cdi_net_device* device)
74 {
75  device->number = netcard_highest_id;
76 
77  // Zur Liste der Netzwerkkarten hinzufügen
78  cdi_list_push(netcard_list, device);
79 
80  // Beim tcpip Modul registrieren
81  void *pDev = 0;
82  cdi_device_type_t type = device->dev.bus_data->bus_type;
83  if(type == CDI_PCI)
84  {
85  pDev = reinterpret_cast<struct cdi_pci_device*>(device->dev.bus_data)->meta.backdev;
86  }
87  if(!pDev)
88  return;
89  cdi_cpp_net_register(pDev, device);
90 
91  ++netcard_highest_id;
92 }
93 
98 EXPORTED_PUBLIC struct cdi_net_device* cdi_net_get_device(int num)
99 {
100  for (size_t i = 0; i < cdi_list_size(netcard_list); i++)
101  {
102  struct cdi_net_device *device = reinterpret_cast<struct cdi_net_device*>(cdi_list_get(netcard_list, i));
103  if (device->number == num)
104  return device;
105  }
106  return NULL;
107 }