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 "bootstruct.h"
9#include "pci.h"
10#include "device_inject.h"
11#include "platform.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
25static void set_eth_builtin(pci_dt_t *eth_dev);
26static void set_wifi_airport(pci_dt_t *wlan_dev);
27static int devprop_add_network_template(struct DevPropDevice *device, uint16_t vendor_id);
28
29
30void Networking_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6);
31
32uint32_t builtin_set = 0;
33
34void Networking_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)
35{
36pci_dt_t* current = arg1;
37
38if(current->class_id == PCI_CLASS_NETWORK_ETHERNET)
39{
40// LAN
41
42bool do_eth_devprop = true;
43getBoolForKey(kEthernetBuiltIn, &do_eth_devprop, DEFAULT_BOOT_CONFIG);
44
45if (do_eth_devprop)
46{
47set_eth_builtin(current);
48}
49}
50else if(current->class_id == PCI_CLASS_NETWORK_OTHER)
51{
52// WIFI
53bool do_wifi_devprop = true;
54getBoolForKey(kEnableWifi, &do_wifi_devprop, DEFAULT_BOOT_CONFIG);
55
56if (do_wifi_devprop)
57 set_wifi_airport(current);
58
59}
60
61}
62
63void Networking_start(void);
64void Networking_start(void)
65{
66register_hook_callback("PCIDevice", &Networking_hook);
67}
68
69/* a fine place for this code */
70
71static int devprop_add_network_template(struct DevPropDevice *device, uint16_t vendor_id)
72{
73uint8_t builtin = 0x0;
74
75if(device)
76{
77 uint32_t devices_number;
78
79if((vendor_id != 0x168c) && (builtin_set == 0))
80{
81builtin_set = 1;
82builtin = 0x01;
83}
84
85if(!devprop_add_value(device, "built-in", (uint8_t*)&builtin, 1))
86{
87return 0;
88}
89
90 if (!(devices_number = (uint32_t)get_env(envDeviceNumber))) {
91 devices_number = 1;
92 }
93
94
95 safe_set_env(envDeviceNumber,devices_number+1);
96
97return 1;
98}
99else
100{
101return 0;
102}
103
104}
105
106static void set_eth_builtin(pci_dt_t *eth_dev)
107{
108char *devicepath = get_pci_dev_path(eth_dev);
109 if (!devicepath) {
110 return ;
111 }
112struct DevPropDevice *device;
113 struct DevPropString *string = (struct DevPropString *)(uint32_t)get_env(envEFIString);
114
115verbose("LAN Controller [%04x:%04x] :: %s\n", eth_dev->vendor_id, eth_dev->device_id, devicepath);
116
117if (!string)
118 {
119string = devprop_create_string();
120 if (!string) return;
121 safe_set_env(envEFIString,(uint32_t)string);
122}
123
124device = devprop_add_device(string, devicepath);
125if(device)
126{
127verbose("Setting up lan keys\n");
128devprop_add_network_template(device, eth_dev->vendor_id);
129 devprop_generate_string(string);
130}
131}
132
133
134struct wifi_cards
135{
136uint16_tvendor_id;
137uint16_tdevice_id;
138char*model;
139};
140
141struct wifi_cards known_wifi_cards[] =
142{
143{0x14e4, 0x4315, "Dell Wireless 1395"},
144{0x14e4, 0x432b, "Dell Wireless 1510"},
145{0x168C, 0x002B, "Atheros 9285 8802.11 b/g/n Wireless Network Adapter"},
146};
147
148static void set_wifi_airport(pci_dt_t *wlan_dev)
149{
150char tmp[16];
151
152char *devicepath = get_pci_dev_path(wlan_dev);
153 if (!devicepath) {
154 return ;
155 }
156struct DevPropDevice *device ;
157 struct DevPropString *string = (struct DevPropString *)(uint32_t)get_env(envEFIString);
158
159verbose("Wifi Controller [%04x:%04x] :: %s\n", wlan_dev->vendor_id, wlan_dev->device_id, devicepath);
160
161if (!string)
162 {
163string = devprop_create_string();
164 if (!string) return;
165 safe_set_env(envEFIString,(uint32_t)string);
166}
167
168device = devprop_add_device(string, devicepath);
169if(device)
170{
171sprintf(tmp, "Airport");
172devprop_add_value(device, "AAPL,slot-name", (uint8_t *) tmp, strlen(tmp) + 1);
173devprop_add_value(device, "device_type", (uint8_t *) tmp, strlen(tmp) + 1);
174
175
176unsigned int i = 0;
177for( ; i < sizeof(known_wifi_cards) / sizeof(known_wifi_cards[0]); i++)
178{
179if(wlan_dev->vendor_id == known_wifi_cards[i].vendor_id &&
180 wlan_dev->device_id == known_wifi_cards[i].device_id)
181{
182verbose("Setting up wifi keys\n");
183
184devprop_add_value(device, "model", (uint8_t*)known_wifi_cards[i].model, (strlen(known_wifi_cards[i].model) + 1));
185
186return;
187
188}
189}
190}
191}
192

Archive Download this file

Revision: 1977