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
12#ifndef DEBUG_ETHERNET
13#define DEBUG_ETHERNET 0
14#endif
15
16#if DEBUG_ETHERNET
17#define DBG(x...) printf(x)
18#else
19#define DBG(x...)
20#endif
21#define kEnableWifi"EnableWifi"
22#define kEthernetBuiltIn"EthernetBuiltIn"
23
24static void set_eth_builtin(pci_dt_t *eth_dev);
25static void set_wifi_airport(pci_dt_t *wlan_dev);
26static int devprop_add_network_template(struct DevPropDevice *device, uint16_t vendor_id);
27
28
29void Networking_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6);
30
31uint32_t builtin_set = 0;
32
33void Networking_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)
34{
35pci_dt_t* current = arg1;
36
37if(current->class_id == PCI_CLASS_NETWORK_ETHERNET)
38{
39// LAN
40
41bool do_eth_devprop = true;
42getBoolForKey(kEthernetBuiltIn, &do_eth_devprop, DEFAULT_BOOT_CONFIG);
43
44if (do_eth_devprop)
45{
46set_eth_builtin(current);
47}
48}
49else if(current->class_id == PCI_CLASS_NETWORK_OTHER)
50{
51// WIFI
52bool do_wifi_devprop = true;
53getBoolForKey(kEnableWifi, &do_wifi_devprop, DEFAULT_BOOT_CONFIG);
54
55if (do_wifi_devprop)
56 set_wifi_airport(current);
57
58}
59
60}
61
62void Networking_start(void);
63void Networking_start(void)
64{
65register_hook_callback("PCIDevice", &Networking_hook);
66}
67
68/* a fine place for this code */
69
70static int devprop_add_network_template(struct DevPropDevice *device, uint16_t vendor_id)
71{
72uint8_t builtin = 0x0;
73
74if(device)
75{
76
77if((vendor_id != 0x168c) && (builtin_set == 0))
78{
79builtin_set = 1;
80builtin = 0x01;
81}
82
83if(!devprop_add_value(device, "built-in", (uint8_t*)&builtin, 1))
84{
85return 0;
86}
87
88devices_number++;
89return 1;
90}
91else
92{
93return 0;
94}
95
96}
97
98static void set_eth_builtin(pci_dt_t *eth_dev)
99{
100char *devicepath = get_pci_dev_path(eth_dev);
101 if (!devicepath) {
102 return ;
103 }
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);
145 if (!devicepath) {
146 return ;
147 }
148struct DevPropDevice *device /*= (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice))*/;
149
150verbose("Wifi Controller [%04x:%04x] :: %s\n", wlan_dev->vendor_id, wlan_dev->device_id, devicepath);
151
152if (!string)
153string = devprop_create_string();
154
155device = devprop_add_device(string, devicepath);
156if(device)
157{
158sprintf(tmp, "Airport");
159devprop_add_value(device, "AAPL,slot-name", (uint8_t *) tmp, strlen(tmp) + 1);
160devprop_add_value(device, "device_type", (uint8_t *) tmp, strlen(tmp) + 1);
161
162
163unsigned int i = 0;
164for( ; i < sizeof(known_wifi_cards) / sizeof(known_wifi_cards[0]); i++)
165{
166if(wlan_dev->vendor_id == known_wifi_cards[i].vendor_id &&
167 wlan_dev->device_id == known_wifi_cards[i].device_id)
168{
169verbose("Setting up wifi keys\n");
170
171devprop_add_value(device, "model", (uint8_t*)known_wifi_cards[i].model, (strlen(known_wifi_cards[i].model) + 1));
172
173// NOTE: I would set the subsystem id and subsystem vendor id here,
174// however, those values seem to be ovverriden in the boot process.
175// A batter method would be injecting the DTGP dsdt method
176// and then injectinve the subsystem id there.
177
178stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length);
179if(stringdata)
180{
181memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);
182stringlength = string->length;
183}
184
185return;
186
187}
188}
189}
190}
191

Archive Download this file

Revision: 1931