summaryrefslogtreecommitdiffstats
path: root/meta-eca/recipes-connectivity/connman/files/connman-init-settings.sh
blob: 9b4f040ae49246c5eacd5b3740a437bdbf2eb841 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/sh
#
# Connection Manager Init Service
#
# Copyright (C) 2012  Intel Corporation. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA


CONNMAN_DIR=/var/lib/connman
CONNMAN_SETTINGS=$CONNMAN_DIR/settings

if [ -s $CONNMAN_SETTINGS ]; then
    exit 0
fi

if [ ! -d $CONNMAN_DIR ]; then
    mkdir -p $CONNMAN_DIR
fi

TETHERING="$1"
TETHERING_AP_PASSPHRASE="$2"
TETHERING_AP_SSID="$3"

if [ -z "$TETHERING" ]; then
    TETHERING="true"
fi

# Create main.conf with those values that we need
MAINCONF=/etc/connman/main.conf
cat > $MAINCONF <<EOF
[General]
TetheringTechnologies=wifi,bluetooth,gadget,ethernet
PersistentTetheringMode=true
EOF

function get_mac
{
    # Get the mac address of the first network interface returned by kernel
    IFACE=`head -n 3 /proc/net/dev|tail -n 1|awk '{ print $1 }'|sed 's/://'`
    if [ -z "$IFACE" -o ! -d /sys/class/net/$IFACE ]; then
	echo 010203040506
    else
	sed 's/://g' /sys/class/net/$IFACE/address
    fi
}

if [ -z "$TETHERING_AP_SSID" ]; then
    MAC=`get_mac`
    TETHERING_AP_SSID=eca-$MAC
fi

if [ -z "$TETHERING_AP_PASSPHRASE" ]; then
    if [ -z "$MAC" ]; then
	MAC=`get_mac`
    fi
    TETHERING_AP_PASSPHRASE=$MAC
fi

cat > $CONNMAN_SETTINGS <<EOF
[global]
OfflineMode=false

[Bluetooth]
Enable=true

[Cellular]
Enable=true

[WiFi]
Enable=true
Tethering=$TETHERING
Tethering.Identifier=$TETHERING_AP_SSID
Tethering.Passphrase=$TETHERING_AP_PASSPHRASE


[Wired]
Enable=true
EOF

if [ $? -eq 0 -a -f $CONNMAN_SETTINGS ]; then
    chmod 0600 $CONNMAN_SETTINGS
fi

exit 0