101
100
/* Add the configuration setting */
102
if (ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))) {
101
rc = measured_strings_add(configuration, name, 0, setting);
171
170
/* Add the configuration setting */
172
if (ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))) {
171
rc = measured_strings_add(configuration, name, 0, setting);
180
180
static int read_configuration_file(const char *directory, const char *filename,
181
181
measured_strings_ref configuration)
185
183
printf("%s: Reading configuration file %s/%s\n", NAME, directory, filename);
187
185
/* Construct the full filename */
205
203
if ((read > 0) && (read != '\n') && (read != '\r')) {
206
204
if (index >= BUFFER_SIZE) {
207
205
line[BUFFER_SIZE - 1] = '\0';
208
fprintf(stderr, "%s: Configuration line %u too long: %s\n",
209
NAME, line_number, line);
206
fprintf(stderr, "%s: Configuration line %u too "
207
"long: %s\n", NAME, line_number, line);
211
209
/* No space left in the line buffer */
212
210
return EOVERFLOW;
214
/* Append the character */
215
line[index] = (char) read;
212
/* Append the character */
213
line[index] = (char) read;
219
216
/* On error or new line */
220
217
line[index] = '\0';
222
if (ERROR_OCCURRED(parse_line(configuration, line)))
223
fprintf(stderr, "%s: Configuration error on line %u: %s\n",
224
NAME, line_number, line);
219
if (parse_line(configuration, line) != EOK) {
220
fprintf(stderr, "%s: Configuration error on "
221
"line %u: %s\n", NAME, line_number, line);
277
275
measured_strings_initialize(&net_globals.configuration);
279
277
// TODO: dynamic configuration
280
ERROR_PROPAGATE(read_configuration());
278
rc = read_configuration();
282
ERROR_PROPAGATE(add_module(NULL, &net_globals.modules,
283
LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service));
284
ERROR_PROPAGATE(add_module(NULL, &net_globals.modules,
285
DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service));
286
ERROR_PROPAGATE(add_module(NULL, &net_globals.modules,
287
ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0,
288
connect_to_service));
289
ERROR_PROPAGATE(add_module(NULL, &net_globals.modules,
290
NILDUMMY_NAME, NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0,
291
connect_to_service));
282
rc = add_module(NULL, &net_globals.modules, LO_NAME, LO_FILENAME,
283
SERVICE_LO, 0, connect_to_service);
286
rc = add_module(NULL, &net_globals.modules, DP8390_NAME,
287
DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service);
290
rc = add_module(NULL, &net_globals.modules, ETHERNET_NAME,
291
ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service);
294
rc = add_module(NULL, &net_globals.modules, NILDUMMY_NAME,
295
NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service);
293
299
/* Build specific initialization */
294
300
return net_initialize_build(client_connection);
314
320
static int net_module_start(async_client_conn_t client_connection)
318
325
async_set_client_connection(client_connection);
319
ERROR_PROPAGATE(pm_init());
323
if (ERROR_OCCURRED(net_initialize(client_connection)) ||
324
ERROR_OCCURRED(REGISTER_ME(SERVICE_NETWORKING, &phonehash))) {
331
rc = net_initialize(client_connection);
335
rc = REGISTER_ME(SERVICE_NETWORKING, &phonehash);
335
346
/** Return the configured values.
455
466
setting = measured_strings_find(&netif->configuration, CONF_IO, 0);
456
467
int io = setting ? strtol(setting->value, NULL, 16) : 0;
458
ERROR_PROPAGATE(netif_probe_req_remote(netif->driver->phone, netif->id, irq, io));
469
rc = netif_probe_req_remote(netif->driver->phone, netif->id, irq, io);
460
473
/* Network interface layer startup */
461
474
services_t internet_service;
468
481
int mtu = setting ? strtol(setting->value, NULL, 10) : 0;
470
ERROR_PROPAGATE(nil_device_req(netif->nil->phone, netif->id, mtu,
471
netif->driver->service));
483
rc = nil_device_req(netif->nil->phone, netif->id, mtu,
484
netif->driver->service);
473
488
internet_service = netif->nil->service;
477
492
/* Inter-network layer startup */
478
493
switch (netif->il->service) {
480
ERROR_PROPAGATE(ip_device_req(netif->il->phone, netif->id,
495
rc = ip_device_req(netif->il->phone, netif->id,
487
ERROR_PROPAGATE(netif_start_req_remote(netif->driver->phone, netif->id));
504
return netif_start_req_remote(netif->driver->phone, netif->id);
491
507
/** Read the configuration and start all network interfaces.
524
ERROR_PROPAGATE(measured_strings_initialize(&netif->configuration));
539
rc = measured_strings_initialize(&netif->configuration);
526
543
/* Read configuration files */
527
if (ERROR_OCCURRED(read_netif_configuration(conf_files[i], netif))) {
544
rc = read_netif_configuration(conf_files[i], netif);
528
546
measured_strings_destroy(&netif->configuration);
533
551
/* Mandatory name */
553
571
* Add to the netif names map and start network interfaces
554
572
* and needed modules.
556
if ((ERROR_OCCURRED(char_map_add(&net_globals.netif_names,
557
netif->name, 0, index))) || (ERROR_OCCURRED(start_device(netif)))) {
558
measured_strings_destroy(&netif->configuration);
559
netifs_exclude_index(&net_globals.netifs, index);
574
rc = char_map_add(&net_globals.netif_names, netif->name, 0,
577
measured_strings_destroy(&netif->configuration);
578
netifs_exclude_index(&net_globals.netifs, index);
582
rc = start_device(netif);
584
measured_strings_destroy(&netif->configuration);
585
netifs_exclude_index(&net_globals.netifs, index);
563
589
/* Increment modules' usage */
593
619
int net_message(ipc_callid_t callid, ipc_call_t *call, ipc_call_t *answer,
594
620
int *answer_count)
598
622
measured_string_ref strings;
601
626
*answer_count = 0;
602
627
switch (IPC_GET_METHOD(*call)) {
603
628
case IPC_M_PHONE_HUNGUP:
605
630
case NET_NET_GET_DEVICE_CONF:
606
ERROR_PROPAGATE(measured_strings_receive(&strings, &data,
607
IPC_GET_COUNT(call)));
631
rc = measured_strings_receive(&strings, &data,
632
IPC_GET_COUNT(call));
608
635
net_get_device_conf_req(0, IPC_GET_DEVICE(call), &strings,
609
636
IPC_GET_COUNT(call), NULL);
611
638
/* Strings should not contain received data anymore */
614
ERROR_CODE = measured_strings_reply(strings, IPC_GET_COUNT(call));
641
rc = measured_strings_reply(strings, IPC_GET_COUNT(call));
617
644
case NET_NET_GET_CONF:
618
ERROR_PROPAGATE(measured_strings_receive(&strings, &data,
619
IPC_GET_COUNT(call)));
645
rc = measured_strings_receive(&strings, &data,
646
IPC_GET_COUNT(call));
620
649
net_get_conf_req(0, &strings, IPC_GET_COUNT(call), NULL);
622
651
/* Strings should not contain received data anymore */
625
ERROR_CODE = measured_strings_reply(strings, IPC_GET_COUNT(call));
654
rc = measured_strings_reply(strings, IPC_GET_COUNT(call));
628
657
case NET_NET_STARTUP:
629
658
return startup();
670
700
int main(int argc, char *argv[])
674
if (ERROR_OCCURRED(net_module_start(net_client_connection))) {
675
fprintf(stderr, "%s: net_module_start error %i\n", NAME, ERROR_CODE);
704
rc = net_module_start(net_client_connection);
706
fprintf(stderr, "%s: net_module_start error %i\n", NAME, rc);