blob: 409da357123bba8a0609ab6f11f2d11e75259e79 [file] [log] [blame]
oliverschmidt19032c62004-06-14 22:30:32 +00001/*
oliverschmidt9e652ff2004-07-11 12:24:52 +00002 * Copyright (c) 2004, Adam Dunkels.
oliverschmidt19032c62004-06-14 22:30:32 +00003 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following
12 * disclaimer in the documentation and/or other materials provided
13 * with the distribution.
oliverschmidt9e652ff2004-07-11 12:24:52 +000014 * 3. All advertising materials mentioning features or use of this
15 * software must display the following acknowledgement:
16 * This product includes software developed by Adam Dunkels.
17 * 4. The name of the author may not be used to endorse or promote
oliverschmidt19032c62004-06-14 22:30:32 +000018 * products derived from this software without specific prior
19 * written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 * This file is part of the Contiki desktop environment
34 *
oliverschmidte31aaa92006-06-28 23:10:43 +000035 * $Id: config.c,v 1.13 2006/06/28 23:10:44 oliverschmidt Exp $
oliverschmidt19032c62004-06-14 22:30:32 +000036 *
37 */
38
oliverschmidt19032c62004-06-14 22:30:32 +000039
40#include <string.h>
oliverschmidt1a1e6282006-05-25 00:11:10 +000041#include <unistd.h>
oliverschmidt19032c62004-06-14 22:30:32 +000042
oliverschmidt9e652ff2004-07-11 12:24:52 +000043#include "uiplib.h"
44#include "resolv.h"
oliverschmidtd5011942005-05-13 00:00:16 +000045#include "uip_arp.h"
oliverschmidt9e652ff2004-07-11 12:24:52 +000046
oliverschmidt2fa33232005-01-26 21:33:29 +000047#include "program-handler.h"
oliverschmidt63a664b2005-04-12 21:50:57 +000048#include "kfs.h"
oliverschmidt2fa33232005-01-26 21:33:29 +000049
oliverschmidt9e652ff2004-07-11 12:24:52 +000050#include "config.h"
51
oliverschmidt19032c62004-06-14 22:30:32 +000052
oliverschmidtd5011942005-05-13 00:00:16 +000053static config_t config = {0,
oliverschmidt30a08982006-05-30 20:57:35 +000054#ifdef __APPLE2__
oliverschmidtd5011942005-05-13 00:00:16 +000055 "SSFire.sav", 5,
oliverschmidt30a08982006-05-30 20:57:35 +000056#else /* __APPLE2__ */
57 "Bounce.sav", 5,
58#endif /* __APPLE2__ */
oliverschmidt356f3662005-05-22 14:04:00 +000059 "Uther.drv", 0,
oliverschmidt1a1e6282006-05-25 00:11:10 +000060 "",
oliverschmidtd5011942005-05-13 00:00:16 +000061 {0xA8C0, 0x8000}, {0xFFFF, 0x00FF},
62 {0xA8C0, 0x0100}, {0xA8C0, 0x0100},
63 0xA2};
oliverschmidt19032c62004-06-14 22:30:32 +000064
oliverschmidt76872e82004-12-26 14:13:34 +000065/*-----------------------------------------------------------------------------------*/
oliverschmidt2fa33232005-01-26 21:33:29 +000066static void
oliverschmidt76872e82004-12-26 14:13:34 +000067config_load(void)
68{
69 int fd;
oliverschmidt19032c62004-06-14 22:30:32 +000070
oliverschmidt63a664b2005-04-12 21:50:57 +000071 fd = kfs_open("contiki.cfg");
oliverschmidt76872e82004-12-26 14:13:34 +000072 if(fd == -1) {
oliverschmidt2fa33232005-01-26 21:33:29 +000073 return;
oliverschmidt76872e82004-12-26 14:13:34 +000074 }
oliverschmidt63a664b2005-04-12 21:50:57 +000075 kfs_read(fd, &config, sizeof(config));
76 kfs_close(fd);
oliverschmidt76872e82004-12-26 14:13:34 +000077}
78/*-----------------------------------------------------------------------------------*/
oliverschmidt1a1e6282006-05-25 00:11:10 +000079static void
oliverschmidt76872e82004-12-26 14:13:34 +000080config_apply(void)
81{
oliverschmidt19032c62004-06-14 22:30:32 +000082#ifdef __APPLE2ENH__
oliverschmidt76872e82004-12-26 14:13:34 +000083
84 ctk_draw_setbackground(config.bkgnd);
85
oliverschmidt19032c62004-06-14 22:30:32 +000086#endif /* __APPLE2ENH__ */
oliverschmidt76872e82004-12-26 14:13:34 +000087
oliverschmidtd5011942005-05-13 00:00:16 +000088 program_handler_setscreensaver(config.screensaver);
89
90 CTK_SCREENSAVER_SET_TIMEOUT(config.timeout * 60);
91
oliverschmidt2fa33232005-01-26 21:33:29 +000092 config_setlanslot(config.slot);
93
94 if(*config.driver) {
95 program_handler_load(config.driver, NULL);
96 }
97
oliverschmidte31aaa92006-06-28 23:10:43 +000098 if(*config.prefix == '/') {
99 config_setprefixok(chdir(config.prefix) == 0);
oliverschmidt1a1e6282006-05-25 00:11:10 +0000100 }
101
oliverschmidt76872e82004-12-26 14:13:34 +0000102#ifdef WITH_UIP
103
104 uip_sethostaddr(config.ipaddr);
105
oliverschmidt19032c62004-06-14 22:30:32 +0000106#ifdef WITH_ETHERNET
oliverschmidt76872e82004-12-26 14:13:34 +0000107
108 uip_setnetmask(config.netmask);
109 uip_setdraddr(config.gateway);
oliverschmidtd5011942005-05-13 00:00:16 +0000110 uip_ethaddr.addr[5] = config.maclsb;
oliverschmidt76872e82004-12-26 14:13:34 +0000111
oliverschmidt19032c62004-06-14 22:30:32 +0000112#endif /* WITH_ETHERNET */
113
oliverschmidt76872e82004-12-26 14:13:34 +0000114 resolv_conf(config.dnsserver);
oliverschmidt19032c62004-06-14 22:30:32 +0000115
oliverschmidt76872e82004-12-26 14:13:34 +0000116#endif /* WITH_UIP */
117}
oliverschmidt19032c62004-06-14 22:30:32 +0000118/*-----------------------------------------------------------------------------------*/
119LOADER_INIT_FUNC(config_init, arg)
120{
121 arg_free(arg);
oliverschmidt2fa33232005-01-26 21:33:29 +0000122 config_load();
123 config_apply();
oliverschmidt9e652ff2004-07-11 12:24:52 +0000124 LOADER_UNLOAD();
oliverschmidt19032c62004-06-14 22:30:32 +0000125}
126/*-----------------------------------------------------------------------------------*/