Chameleon

Chameleon Svn Source Tree

Root/branches/cparm/i386/modules/Networking/Networking.c

1/*
2 * Copyright (c) 2009 Evan Lojewski. All rights reserved.
3 *
4 */
5
6#include "libsaio.h"
7#include "modules.h"
8#include "boot.h"
9#include "bootstruct.h"
10#include "pci.h"
11#include "device_inject.h"
12
13#ifndef DEBUG_ETHERNET
14#define DEBUG_ETHERNET 0
15#endif
16
17#if DEBUG_ETHERNET
18#define DBG(x...) printf(x)
19#else
20#define DBG(x...)
21#endif
22#define kEnableWifi"EnableWifi"
23#define kEthernetBuiltIn"EthernetBuiltIn"
24#define kEnableNetworking"EnableNetworkModule"
25
26static void set_eth_builtin(pci_dt_t *eth_dev);
27static void set_wifi_airport(pci_dt_t *wlan_dev);
28static int devprop_add_network_template(struct DevPropDevice *device, uint16_t vendor_id);
29
30uint32_t builtin_set = 0;
31
32void Networking_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)
33{
34pci_dt_t* current = arg1;
35
36if(current->class_id == PCI_CLASS_NETWORK_ETHERNET)
37{
38// LAN
39
40bool do_eth_devprop = true;
41getBoolForKey(kEthernetBuiltIn, &do_eth_devprop, &bootInfo->bootConfig);
42
43if (do_eth_devprop)
44{
45set_eth_builtin(current);
46}
47}
48else if(current->class_id == PCI_CLASS_NETWORK_OTHER)
49{
50// WIFI
51bool do_wifi_devprop = true;
52getBoolForKey(kEnableWifi, &do_wifi_devprop, &bootInfo->bootConfig);
53
54if (do_wifi_devprop)
55set_wifi_airport(current);
56
57}
58
59}
60
61void Networking_start()
62{
63bool enable = true;
64getBoolForKey(kEnableNetworking, &enable, &bootInfo->bootConfig) ;
65
66if (enable) {
67register_hook_callback("PCIDevice", &Networking_hook);
68}
69}
70
71/* a fine place for this code */
72
73static int devprop_add_network_template(struct DevPropDevice *device, uint16_t vendor_id)
74{
75uint8_t builtin = 0x0;
76
77if(device)
78{
79
80if((vendor_id != 0x168c) && (builtin_set == 0))
81{
82builtin_set = 1;
83builtin = 0x01;
84}
85
86if(!devprop_add_value(device, "built-in", (uint8_t*)&builtin, 1))
87{
88return 0;
89}
90
91devices_number++;
92return 1;
93}
94else
95{
96return 0;
97}
98
99}
100
101static void set_eth_builtin(pci_dt_t *eth_dev)
102{
103char *devicepath = get_pci_dev_path(eth_dev);
104struct DevPropDevice *device /*= (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice))*/;
105
106verbose("LAN Controller [%04x:%04x] :: %s\n", eth_dev->vendor_id, eth_dev->device_id, devicepath);
107
108if (!string)
109string = devprop_create_string();
110
111device = devprop_add_device(string, devicepath);
112if(device)
113{
114verbose("Setting up lan keys\n");
115devprop_add_network_template(device, eth_dev->vendor_id);
116stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length);
117if(stringdata)
118{
119memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);
120stringlength = string->length;
121}
122}
123}
124
125
126struct wifi_cards
127{
128uint16_tvendor_id;
129uint16_tdevice_id;
130char*model;
131};
132
133struct wifi_cards known_wifi_cards[] =
134{
135{0x14e4, 0x4315, "Dell Wireless 1395"},
136{0x14e4, 0x432b, "Dell Wireless 1510"},
137{0x168C, 0x002B, "Atheros 9285 8802.11 b/g/n Wireless Network Adapter"},
138};
139
140static void set_wifi_airport(pci_dt_t *wlan_dev)
141{
142char tmp[16];
143
144char *devicepath = get_pci_dev_path(wlan_dev);
145struct DevPropDevice *device /*= (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice))*/;
146
147verbose("Wifi Controller [%04x:%04x] :: %s\n", wlan_dev->vendor_id, wlan_dev->device_id, devicepath);
148
149if (!string)
150string = devprop_create_string();
151
152device = devprop_add_device(string, devicepath);
153if(device)
154{
155sprintf(tmp, "Airport");
156devprop_add_value(device, "AAPL,slot-name", (uint8_t *) tmp, strlen(tmp) + 1);
157devprop_add_value(device, "device_type", (uint8_t *) tmp, strlen(tmp) + 1);
158
159
160unsigned int i = 0;
161for( ; i < sizeof(known_wifi_cards) / sizeof(known_wifi_cards[0]); i++)
162{
163if(wlan_dev->vendor_id == known_wifi_cards[i].vendor_id &&
164 wlan_dev->device_id == known_wifi_cards[i].device_id)
165{
166verbose("Setting up wifi keys\n");
167
168devprop_add_value(device, "model", (uint8_t*)known_wifi_cards[i].model, (strlen(known_wifi_cards[i].model) + 1));
169
170// NOTE: I would set the subsystem id and subsystem vendor id here,
171// however, those values seem to be ovverriden in the boot process.
172// A batter method would be injecting the DTGP dsdt method
173// and then injectinve the subsystem id there.
174
175stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length);
176if(stringdata)
177{
178memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);
179stringlength = string->length;
180}
181
182return;
183
184}
185}
186}
187}
188

Archive Download this file

Revision: 1468