Changeset 1820

Show
Ignore:
Timestamp:
06/01/11 12:46:28 (2 years ago)
Author:
matthijs
Message:

fonbase: Unify the config.sh scripts for 2.0g and 2.0n.

There is no a single script for both targets, instead of two highly
similar but slightly different scripts. For 2.0n, this doesn't change
much (e.g., the script still does more or less the same). For 2.0g, the
changes are bigger. Mostly the bridge-mode related changes are available
to 2.0g now, as well as some other minor changes (but this does not
actually make bridge mode work on 2.0g yet).

References: #836

Location:
trunk/fon/fonbase
Files:
2 added
1 removed
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/fon/fonbase/files/lib/fon/config.sh

    r1819 r1820  
    55 
    66lan_ifname="br-lan" 
    7 wifi_ifname=ra1 
    8 case "$(cat /etc/fon_device)" in 
     7fon_device=$(cat /etc/fon_device) 
     8case "$fon_device" in 
    99        fonera20n) 
    1010                lan_devs="eth0.1" 
    1111                mgmt_ifname="$lan_ifname" 
    1212                wan_ifname="eth0.2" 
     13                wan_auto=0 
     14                wifi_device="rt3052" 
    1315                wifi_ifname_mac="ra1" 
    14                 wan_auto=0 
     16                wifi_ifname="ra1" 
     17                private_wifi_ifname="ra0" 
     18                wan_wifi_ifname="apcli0" 
    1519        ;; 
    1620        fonera20) 
     
    1923                wan_ifname="eth0.1" 
    2024                wan_auto=0 
     25                wifi_device="wifi0" 
     26                wifi_ifname="ath0" 
     27                private_wifi_ifname="ath1" 
     28                wan_wifi_ifname="ath2" 
    2129        ;; 
    2230        *) 
     
    2836 
    2937get_serial() { 
    30         return dd if=$(find_mtd_part boardconfig) bs=$((0x1026)) skip=1 count=1 2>/dev/null | head -c10 
     38        case "$fon_device" in 
     39                fonera20n) 
     40                        dd if=$(find_mtd_part boardconfig) bs=$((0x1026)) skip=1 count=1 2>/dev/null | head -c10 
     41                        ;; 
     42                fonera20) 
     43                        dd if=$(find_mtd_part boardconfig) bs=$((0x88)) skip=1 count=1 2>/dev/null | head -c10 
     44                        ;; 
     45        esac 
    3146} 
    3247 
     
    106121        } 
    107122        [ "$proto" == "wifi" ] && { 
    108                 uci_set "network" "wan" "ifname" "apcli0" 
     123                uci_set "network" "wan" "ifname" "$wan_wifi_ifname" 
    109124                proto=`uci get fon.wan.wmode` 
    110125        } 
     
    157172 
    158173config_wireless() { 
    159         E=`cat /proc/gpio_switch` 
    160174        local mode channel ssid encryption crypto wmode 
    161175        export wifi_run=1 
    162176        config_get channel advanced channel 
    163177        config_get mode advanced bgmode 
    164         config_get ht advanced ht 
    165         config_get country advanced country 
    166         uci_add "wireless" "wifi-device" "rt3052" 
    167         uci_set "wireless" "rt3052" "type" "rt3052" 
    168         uci_set "wireless" "rt3052" "channel" "$channel" 
    169         uci_set "wireless" "rt3052" "ht" "${ht:-40}" 
    170         uci_set "wireless" "rt3052" "country" "${country:-ES}" 
    171         uci_set "wireless" "rt3052" "mode" "$mode" 
    172         uci_set "wireless" "rt3052" "disabled" "${E:-0}" 
     178        uci_add "wireless" "wifi-device" "$wifi_device" 
     179        uci_set "wireless" "$wifi_device" "channel" "$channel" 
     180        case $fon_device in 
     181                fonera20n) 
     182                        config_get ht advanced ht 
     183                        config_get country advanced country 
     184                        uci_set "wireless" "$wifi_device" "type" "rt3052" 
     185                        uci_set "wireless" "$wifi_device" "ht" "${ht:-40}" 
     186                        uci_set "wireless" "$wifi_device" "country" "${country:-ES}" 
     187                        uci_set "wireless" "$wifi_device" "mode" "$mode" 
     188                        local wifi_switch=`cat /proc/gpio_switch` 
     189                        uci_set "wireless" "$wifi_device" "disabled" "${wifi_switch:-0}" 
     190                        ;; 
     191                fonera20) 
     192                        config_get diversity advanced diversity 
     193                        config_get rtxant advanced rtxant 
     194                        case "$mode" in 
     195                                B|b) mode=11b;; 
     196                                G|g) mode=11g;; 
     197                                *) mode=auto;; 
     198                        esac 
     199                        uci_set "wireless" "$wifi_device" "type" "atheros" 
     200                        uci_set "wireless" "$wifi_device" "mode" "$mode" 
     201                        uci_set "wireless" "$wifi_device" "diversity" "$diversity" 
     202                        uci_set "wireless" "$wifi_device" "rxantenna" "$rtxant" 
     203                        uci_set "wireless" "$wifi_device" "txantenna" "$rtxant" 
     204                        uci_remove "wireless" "$wifi_device" "disabled" 2> /dev/null 
     205                        ;; 
     206        esac 
    173207         
    174208        uci_remove "wireless" "public" 
    175209        uci_add "wireless" "wifi-iface" "public" 
    176         uci_set "wireless" "public" "device" "rt3052" 
    177         uci_set "wireless" "public" "ifname" "ra1" 
     210        uci_set "wireless" "public" "device" "$wifi_device" 
     211        uci_set "wireless" "public" "ifname" "$wifi_ifname" 
    178212        uci_set "wireless" "public" "network" "hotspotwifi" 
     213        uci_set "wireless" "public" "mode" "ap" 
    179214        uci_set "wireless" "public" "ssid" "off" 
    180215        uci_set "wireless" "public" "hidden" "0" 
    181216        uci_set "wireless" "public" "encryption" "none" 
     217 
    182218        config_get ssid private essid 
    183219        config_get encryption private encryption 
    184220        config_get wpa_crypto private wpa_crypto 
    185221        uci_add "wireless" "wifi-iface" "private" 
    186         uci_set "wireless" "private" "device" "rt3052" 
    187         uci_set "wireless" "private" "ifname" "ra0" 
     222        uci_set "wireless" "private" "device" "$wifi_device" 
     223        uci_set "wireless" "private" "ifname" "$private_wifi_ifname" 
    188224        uci_set "wireless" "private" "network" "lan" 
     225        uci_set "wireless" "private" "mode" "ap" 
    189226        uci_set "wireless" "private" "ssid" "$ssid" 
    190227        uci_set "wireless" "private" "hidden" "0" 
    191228        case "$encryption" in 
    192229                wpa*|WPA*|Mixed|mixed) 
     230                        case "$fon_device" in 
     231                                # The ra_wifi and madwifi / hostapd 
     232                                # driver scripts accept their wpa 
     233                                # parameters in different formats. 
     234                                # Perhaps this should be unified 
     235                                # sometime. 
     236                                fonera20n) 
     237                                        uci_set "wireless" "private" "encryption" "$encryption" 
     238                                        uci_set "wireless" "private" "wpa_crypto" "$wpa_crypto" 
     239                                        ;; 
     240                                fonera20) 
     241                                        case "$encryption" in 
     242                                                WPA|WPA1|wpa|wpa1) enc=psk;; 
     243                                                WPA2|wpa2) enc=psk2;; 
     244                                                Mixed|mixed) enc=psk-mixed;; 
     245                                        esac 
     246                                        uci_set "wireless" "private" "encryption" "$enc${wpa_crypto:+/$wpa_crypto}" 
     247                                        ;; 
     248                        esac 
    193249                        pwd=`/sbin/uci get fon.private.password` 
    194                         uci_set "wireless" "private" "encryption" "$encryption" 
    195250                        uci_set "wireless" "private" "key" "$pwd" 
    196                         uci_set "wireless" "private" "wpa_crypto" "$wpa_crypto" 
    197251                ;; 
    198252                WEP|wep) 
     
    212266                config_get ssid wan ssid 
    213267                config_get auth wan auth 
    214                 config_get crypto wan crypto 
    215268                config_get channel wan channel 
    216269                uci_add "wireless" "wifi-iface" "uplink" 
    217                 uci_set "wireless" "uplink" "device" "rt3052" 
    218                 uci_set "wireless" "uplink" "ifname" "apcli0" 
     270                uci_set "wireless" "uplink" "device" "$wifi_device" 
     271                uci_set "wireless" "uplink" "ifname" "$wan_wifi_ifname" 
    219272                uci_set "wireless" "uplink" "network" "wan" 
    220273                uci_set "wireless" "uplink" "mode" "sta" 
    221274                uci_set "wireless" "uplink" "ssid" "$ssid" 
    222275                uci_set "wireless" "uplink" "hidden" "0" 
    223                 uci_set "wireless" "rt3052" "channel" "$channel" 
     276                # TODO: Is this needed just for 2.0n? 
     277                [ "$fon_device" = "fonera20n" ] && uci_set "wireless" "$wifi_device" "channel" "$channel" 
    224278                case "$auth" in 
    225279                        wpa*|WPA*|Mixed|mixed) 
    226                                 case "$auth" in 
    227                                         WPA|WPA1|wpa|wpa1) enc=WPAPSK;; 
    228                                         *) enc=WPA2PSK;; 
     280                                case "$fon_device" in 
     281                                        fonera20n) 
     282                                                case "$auth" in 
     283                                                        WPA|WPA1|wpa|wpa1) enc=WPAPSK;; 
     284                                                        *) enc=WPA2PSK;; 
     285                                                esac 
     286                                                config_get crypto wan crypto 
     287                                                case "$crypto" in 
     288                                                        aes|AES) crypt=AES;; 
     289                                                        *) crypt=TKIP;; 
     290                                                esac 
     291                                                uci_set "wireless" "uplink" "wpa_crypto" "$crypt" 
     292                                                ;; 
     293                                        fonera20) 
     294                                                case "$auth" in 
     295                                                        WPA|WPA1|wpa|wpa1) enc=psk;; 
     296                                                        WPA2|wpa2) enc=psk2;; 
     297                                                        Mixed|mixed) enc=psk-mixed;; 
     298                                                esac 
     299                                                ;; 
    229300                                esac 
    230                                 case "$crypto" in 
    231                                         aes|AES) crypt=AES;; 
    232                                         *) crypt=TKIP;; 
    233                                 esac 
     301                                uci_set "wireless" "uplink" "encryption" "$enc" 
    234302                                pwd=`/sbin/uci get fon.wan.psk` 
    235                                 uci_set "wireless" "uplink" "encryption" "$enc" 
    236303                                uci_set "wireless" "uplink" "key" "$pwd" 
    237                                 uci_set "wireless" "uplink" "wpa_crypto" "$crypt" 
    238304                        ;; 
    239305                        WEP|wep) 
     
    263329 
    264330config_fon() { 
    265         serial=`dd if=$(find_mtd_part boardconfig) bs=$((0x1026)) skip=1 count=1 2>/dev/null | head -c10` 
     331        serial=`get_serial` 
    266332        uci_set "fon" "private" "password"  "$serial" 
    267333        uci_set "system" "fon" "serial"  "$serial"