#!/bin/sh loggerName=tiWlanApp.elf WLAN_IF="tiwlan0" WLAN_DIAG_PATH=/var/run/diag/tiwlan WLAN_DIAG_INTERFACE=$WLAN_DIAG_PATH/interface WLAN_DIAG_FCC=$WLAN_DIAG_PATH/fccmode WLAN_DIAG_CONSTAT=$WLAN_DIAG_PATH/constatus WLAN_DIAG_RSSI=$WLAN_DIAG_PATH/rssi WLAN_PATH=/opt/ti-wireless/WL6.1.6.0.3/debug WLAN_CONFIG=/home/tool/config/wlan.json WLAN_SUPPL_PATH=/home/tool/config/wlan/suppl WPA_SUPPLICANT_CONF=/home/tool/config/wlan/suppl/wpa_supplicant.txt WLAN_INI="tiwlan.ini" WL1271_INI="wl1271-tiwlan.ini" WL1273_INI="wl1273-tiwlan.ini" WL1273_ETSI_INI="TIWI5-LSR-ETSI.ini" WL1273_FCC_INI="TIWI5-LSR-FCC.ini" WL1273_INI_WORK="TIWI-INI.work" # Tix Revision # AAx Revision C # ABx Revision D WPA_PSK=/opt/ti-wireless/WL6.1.6.0.3/wpa/WPA_WPA2_PSK.txt WPA_EAP_PEAP=/opt/ti-wireless/WL6.1.6.0.3/wpa/EAP_PEAP.txt WPA_EAP_TLS=/opt/ti-wireless/WL6.1.6.0.3/wpa/EAP_TLS.txt WPA_EAP_TTLS=/opt/ti-wireless/WL6.1.6.0.3/wpa/EAP_TTLS.txt WLAN_CERT_PATH="\/home\/tool\/config\/wlan\/cert\/" # sed 's/-$//' loescht letztes Zeichen einer Zeile # sed 's/"//g' loescht die Hochkommas # Sonderzeichen (& / \) in Strings müssen für sed behandelt werden ( escapen -> sed -e 's/[\/&]/\\&/g' ) # da der WebGui-Parser das Backslash Zeichen schon escaped -> hier rausnehmen! # # Beachte letzte Zeichen in einer Zeile -> mit Kommma und Leerzeichen oder nicht ..! f_parse_bssid(){ bssid=`grep '"bssid":' $WLAN_CONFIG | awk '{print $2}' | sed 's/.$//' | sed 's/"//g'` sed -i "s/#bssid\b.*/bssid=$bssid/g" $WPA_SUPPLICANT_CONF } f_parse_ssid(){ ssid=`grep '"ssid":' $WLAN_CONFIG | awk -F: '{print $2}' | cut -c2-` ssid_esc=$(echo $ssid | sed -e 's/[/&]/\\&/g') sed -i "s/\bssid\b.*/ssid=$ssid_esc/g" $WPA_SUPPLICANT_CONF } f_parse_anonymous_identity(){ anonymous_identity=`grep '"anonymous_identity":' $WLAN_CONFIG | awk -F: '{print $2}' | cut -c2- | sed 's/.$//' | sed 's/.$//'` anonymous_identity_esc=$(echo $anonymous_identity | sed -e 's/[/&]/\\&/g') sed -i "s/#anonymous_identity.*/anonymous_identity=$anonymous_identity_esc/" $WPA_SUPPLICANT_CONF } f_parse_passphrase(){ passphrase=`grep '"passphrase":' $WLAN_CONFIG | awk -F: '{print $2}' | cut -c2- | sed 's/.$//' | sed 's/.$//'` #passphrase_esc=$(echo $passphrase | sed -e 's/[\/&]/\\&/g') passphrase_esc=$(echo $passphrase | sed -e 's/[/&]/\\&/g') # sed -i "s/psk.*/psk=$passphrase_esc/g" $WPA_SUPPLICANT_CONF sed -i "/ssid/!s/psk.*/psk=$passphrase_esc/g" $WPA_SUPPLICANT_CONF } f_parse_password(){ password=`grep '"password":' $WLAN_CONFIG| awk -F: '{print $2}' | cut -c2- | sed 's/.$//' | sed 's/.$//'` password_esc=$(echo $password | sed -e 's/[/&]/\\&/g') sed -i "s/password.*/password=$password_esc/g" $WPA_SUPPLICANT_CONF } f_parse_private_key_passwd() { # nach cut stehen am Ende ein Komma ',' und ein Leerzeichen -> 2 Zeichen entfernen ( die 2 letzten sed Befehle ) private_key_passwd=`grep '"private_key_passwd":' $WLAN_CONFIG | awk -F: '{print $2}' | cut -c2- | sed 's/.$//' | sed 's/.$//'` private_key_passwd_esc=$(echo $private_key_passwd | sed -e 's/[/&]/\\&/g') sed -i "s/\bprivate_key_passwd\b.*/private_key_passwd=$private_key_passwd_esc/g" $WPA_SUPPLICANT_CONF } f_parse_identity(){ identity=`grep '"username":' $WLAN_CONFIG | awk -F: '{print $2}' | cut -c2-` identity_esc=$(echo $identity | sed -e 's/[/&]/\\&/g') sed -i "s/\bidentity\b.*/identity=$identity_esc/g" $WPA_SUPPLICANT_CONF } f_parse_client_cert(){ client_cert=`grep '"client_cert":' $WLAN_CONFIG | awk -F: '{print $2}' | cut -c2- | sed 's/.$//' | sed 's/.$//' | sed 's/"//g'` client_cert_esc=$(echo $client_cert | sed -e 's/[/&]/\\&/g') client_cert=\"$WLAN_CERT_PATH$client_cert_esc\" sed -i "s/client_cert.*/client_cert=$client_cert/g" $WPA_SUPPLICANT_CONF } f_parse_private_key(){ private_key=`grep '"private_key":' $WLAN_CONFIG | awk -F: '{print $2}' | cut -c2- | sed 's/.$//' | sed 's/.$//' | sed 's/"//g'` private_key_esc=$(echo $private_key | sed -e 's/[/&]/\\&/g') private_key=\"$WLAN_CERT_PATH$private_key_esc\" sed -i "s/\bprivate_key\b.*/private_key=$private_key/g" $WPA_SUPPLICANT_CONF } f_parse_ca_cert_opt(){ ca_cert_opt=`grep '"ca_cert":' $WLAN_CONFIG | awk -F: '{print $2}' | cut -c2- | sed 's/.$//' | sed 's/.$//' | sed 's/"//g'` ca_cert_opt_esc=$(echo $ca_cert_opt | sed -e 's/[/&]/\\&/g') ca_cert_opt=\"$WLAN_CERT_PATH$ca_cert_opt_esc\" sed -i "s/#ca_cert.*/ca_cert=$ca_cert_opt/g" $WPA_SUPPLICANT_CONF } f_parse_ca_cert(){ ca_cert=`grep '"ca_cert":' $WLAN_CONFIG | awk -F: '{print $2}' | cut -c2- | sed 's/.$//' | sed 's/.$//' | sed 's/"//g'` ca_cert_esc=$(echo $ca_cert | sed -e 's/[/&]/\\&/g') ca_cert=\"$WLAN_CERT_PATH$ca_cert_esc\" sed -i "s/ca_cert.*/ca_cert=$ca_cert/g" $WPA_SUPPLICANT_CONF } f_del_tkip(){ sed -i 's/\bpairwise=\b.*/pairwise=CCMP/' $WPA_SUPPLICANT_CONF sed -i 's/\bgroup=\b.*/group=CCMP/' $WPA_SUPPLICANT_CONF } f_start_wpasupplicant(){ cd $WLAN_PATH # wpa_suppl Logdatei jedesmal neu anlegen Size=`du -k /var/log/wpa_supp.log | awk '{print $1}'` logger -s -t $loggerName "wpa_supplicant log Size <$Size kB>" if [ $Size -gt 10000 ]; then rm -r /var/log/wpa_supp.log > /dev/null 2>&1 fi ./wpa_supplicant -t -Dwext -itiwlan0 -c $WLAN_SUPPL_PATH/wpa_supplicant.txt -ddddd >> /var/log/wpa_supp.log & if [ "$?" -eq "0" ]; then logger -s -t $loggerName "start wpa_supplicant success" else logger -s -t $loggerName "Error: start wpa_supplicant failed (Neustart versuchen) exit 1" f_exit $ExitCode2 fi sleep 5 } wl_start(){ # ggf dhcp client pid abschiessen PID=`ps | grep "[u]dhcpc -i tiwlan0" | awk '{print $1}'` kill -SIGUSR2 $PID &> /dev/null kill -SIGTERM $PID &> /dev/null PID=`ps | grep "[u]dhcpc -i tiwlan0" | awk '{print $1}'` kill -SIGUSR2 $PID &> /dev/null kill -SIGTERM $PID &> /dev/null PID=`ps | grep "[u]dhcpc -i tiwlan0" | awk '{print $1}'` kill -SIGUSR2 $PID &> /dev/null kill -SIGTERM $PID &> /dev/null cat $WLAN_CONFIG | grep '"interface": true' if [ "$?" -eq "0" ]; then echo true > $WLAN_DIAG_INTERFACE # hostname setzen host_name=`grep '"hostname":' $WLAN_CONFIG | awk '{print $2}' | sed 's/"//g' | sed 's/.$//'` echo $host_name > /etc/hostname hostname $host_name # nvs_map.bin einlesen # #################### cd $WLAN_PATH /usr/bin/python nvsmap.py if [ "$?" -eq "0" ]; then logger -s -t $loggerName "nvs_map Success" else logger -s -t $loggerName "nvs_map Failed" fi # Auswahl regulatory-domain ########################### RegDom=`cat $WLAN_CONFIG | grep "regulatory-domain" | awk '{print $2}' | sed 's/"//g' | sed 's/,//' ` # Alte Dateien loeschen rm tiwlan.ini rm $WL1273_INI_WORK case "$RegDom" in ETSI) # ETSI - European Telecommunications Standards Institute logger -s -t $loggerName "Regulatory Domain ETSI" cp $WL1273_ETSI_INI $WL1273_INI_WORK ;; FCC) # FCC - Federal Communication Commission logger -s -t $loggerName "Regulatory Domain FCC" cp $WL1273_FCC_INI $WL1273_INI_WORK ;; TI) # Texas Instruments File logger -s -t $loggerName "Texas Instruments tiwlan-dual.ini" cp $WL1273_INI $WL1273_INI_WORK ;; esac # Link fuer das Ini-File setzen ln -s $WL1273_INI_WORK $WLAN_INI INI=$WL1273_INI_WORK # Auswahl dot11NetworkType -> 2 - A only mode, 3 - B/G mode, 4 - A/G Dual mode ############################################################################### Band=`cat $WLAN_CONFIG | grep "band" | awk '{print $2}' | sed 's/"//g' | sed 's/,//' ` case "$Band" in 802.11b/g) logger -s -t $loggerName "802.11b/g" sed -i 's/.*dot11NetworkType.*/dot11NetworkType = 3 /g' $INI ;; 802.11a/g) logger -s -t $loggerName "802.11a/g" sed -i 's/.*dot11NetworkType.*/dot11NetworkType = 4 /g' $INI ;; 802.11a) logger -s -t $loggerName "802.11a" sed -i 's/.*dot11NetworkType.*/dot11NetworkType = 2 /g' $INI ;; esac cd $WLAN_PATH lsmod | grep 'sdio' if [ "$?" -ne "0" ]; then insmod sdio.ko if [ "$?" -eq "0" ]; then logger -s -t $loggerName "sdio.ko Success" else echo "sdio.ko Failed" if [ "$?" -ne 0 ]; then logger -s -t $loggerName "sdio" fi fi fi sleep 1 insmod tiwlan_drv.ko if [ "$?" -eq "0" ]; then logger -s -t $loggerName "tiwlan_drv.ko Success" else logger -s -t $loggerName "tiwlan_drv.ko Failed" if [ "$?" -ne 0 ]; then rmmod -f tiwlan_drv fi fi sleep 1 ./tiwlan_loader if [ "$?" -eq "0" ]; then logger -s -t $loggerName "loading firmware Success" else logger -s -t $loggerName "loading firmware Failed" if [ "$?" -ne 0 ]; then rmmod -f tiwlan_drv rmmod -f sdio fi fi sleep 1 ifconfig $WLAN_IF up # Wenn IP Konfiguration auf manuell steht, # gleich hier dem IF die Adresse verpassen .... cat $WLAN_CONFIG | grep 'man' if [ "$?" -eq "0" ]; then IPADDR=`cat $WLAN_CONFIG | grep ipadr | awk '{print $2}' | sed 's/"//g' | sed 's/,//'` SUBNET=`cat $WLAN_CONFIG | grep subnet | awk '{print $2}' | sed 's/"//g' | sed 's/,//'` GATEWAY=`cat $WLAN_CONFIG | grep gateway | awk '{print $2}' | sed 's/"//g' | sed 's/,//'` ifconfig $WLAN_IF $IPADDR netmask $SUBNET up route add default gw $GATEWAY netmask 0.0.0.0 # statische route anlegen # route add -net 10.23.233.200 netmask 255.255.255.0 gw 10.23.233.1 dev tiwlan0 fi method=`grep '"method":' $WLAN_CONFIG | grep -v "dhcp" | grep -v "man" | awk '{print $2}' | sed 's/"//g' | sed 's/,//' ` case "$method" in WPA/WPA2-Personal) logger -s -t $loggerName "WPA/WPA2-Personal" # wpa_supplicant.conf kopieren & konfigurieren cp $WPA_PSK $WPA_SUPPLICANT_CONF f_parse_ssid f_parse_passphrase cat $WLAN_CONFIG | grep '"tkip": false' > /dev/null 2>&1 if [ "$?" -eq "0" ]; then f_del_tkip fi # Supplicant starten f_start_wpasupplicant ;; # WPA/WPA2-Personal) WPA/WPA2-Enterprise) logger -s -t $loggerName "WPA/WPA2-Enterprise" # EAP Methode Eap=`grep '"auth":' $WLAN_CONFIG | awk '{print $2}' | sed 's/"//g' | sed 's/,//' ` case "$Eap" in 13) logger -s -t $loggerName "EAP-TLS" rm $WPA_SUPPLICANT_CONF cp $WPA_EAP_TLS $WPA_SUPPLICANT_CONF f_parse_ssid f_parse_identity f_parse_private_key_passwd cat $WLAN_CONFIG | grep '"tkip": false' > /dev/null 2>&1 if [ "$?" -eq "0" ]; then f_del_tkip fi # client_cert client_cert=`grep '"client_cert":' $WLAN_CONFIG | awk '{print $2}' | sed 's/"//g' | sed 's/,//'` sed -i 's/client_cert.*/client_cert="'$WLAN_CERT_PATH''$client_cert'"/g' $WPA_SUPPLICANT_CONF # private_key private_key=`grep '"private_key":' $WLAN_CONFIG | awk '{print $2}' | sed 's/"//g' | sed 's/,//'` sed -i 's/\bprivate_key\b.*/private_key="'$WLAN_CERT_PATH''$private_key'"/g' $WPA_SUPPLICANT_CONF # ca_cert Optional cat $WLAN_CONFIG | grep '"ca_cert": ""' &> /dev/null if [ "$?" -ne "0" ]; then ca_cert=`grep '"ca_cert":' $WLAN_CONFIG | awk '{print $2}' | sed 's/"//g' | sed 's/,//'` sed -i 's/#ca_cert.*/ca_cert="'$WLAN_CERT_PATH''$ca_cert'"/g' $WPA_SUPPLICANT_CONF fi ;; 21) logger -s -t $loggerName "EAP-TTLS" cp $WPA_EAP_TTLS $WPA_SUPPLICANT_CONF f_parse_ssid f_parse_identity f_parse_password cat $WLAN_CONFIG | grep '"tkip": false' > /dev/null 2>&1 if [ "$?" -eq "0" ]; then f_del_tkip fi # ca_cert ca_cert=`grep '"ca_cert":' $WLAN_CONFIG | awk '{print $2}' | sed 's/"//g' | sed 's/,//'` sed -i 's/ca_cert.*/ca_cert="'$ca_cert'"/' $WPA_SUPPLICANT_CONF # optional anonymous_identity cat $WLAN_CONFIG | grep '"anonymous_identity": ""' > /dev/null 2>&1 if [ "$?" -ne "0" ]; then f_parse_anonymous_identity fi ;; 25) logger -s -t $loggerName "EAP-PEAP" # wpa_supplicant.conf kopieren & konfigurieren cp $WPA_EAP_PEAP $WPA_SUPPLICANT_CONF f_parse_ssid f_parse_identity f_parse_password cat $WLAN_CONFIG | grep '"tkip": false' > /dev/null 2>&1 if [ "$?" -eq "0" ]; then f_del_tkip fi # optional anonymous_identity cat $WLAN_CONFIG | grep '"anonymous_identity": ""' > /dev/null 2>&1 if [ "$?" -ne "0" ]; then f_parse_anonymous_identity fi # CA-Zertifikat cat $WLAN_CONFIG | grep '"ca_cert": ""' > /dev/null 2>&1 if [ "$?" -ne "0" ]; then ca_cert=`grep '"ca_cert":' $WLAN_CONFIG | awk '{print $2}' | sed 's/"//g' | sed 's/,//'` sed -i 's/#ca_cert.*/ca_cert="'$ca_cert'"/' $WPA_SUPPLICANT_CONF fi ;; esac # Supplicant starten f_start_wpasupplicant ;; #WPA/WPA2-Enterprise) *) logger -s -t $loggerName "wlan method nicht bekannt <$method> " ;; # default esac else echo false > $WLAN_DIAG_INTERFACE fi # export VALGRIND_LIB=/opt/debug/valgrind/lib/valgrind # process="/opt/debug/valgrind/bin/./valgrind /home/tool/bin/$name" /opt/ti-wireless/WL6.1.6.0.3/debug/tiWlanApp.elf & # Wlan Interrupts ändern ######################## #chrt -fp 45 `ps | grep "irq/309-tiwlan0" -m 1 | awk '{print $1}'` #chrt -fp 45 `ps | grep "irq/86-TIWLAN_S" -m 1 | awk '{print $1}'` } # wl_start wl_restart(){ wl_stop sleep 5 wl_start } # wl_restart wl_stop(){ dbus-send --system --type=signal /WlanObj com.rexroth.akku.WlanInterface.changed_connection int32:4 rm /var/run/diag/tiwlan/* rm /var/run/cli.log PID=`ps | grep "[t]iWlanApp.elf" | awk '{print $1}'` kill -SIGTERM $PID > /dev/null 2>&1 PID=`ps | grep "[w]pa_supplicant" | awk '{print $1}'` kill -SIGTERM $PID > /dev/null 2>&1 PID=`ps | grep "[u]dhcpc -i tiwlan0" | awk '{print $1}'` kill -SIGUSR2 $PID &> /dev/null kill -SIGTERM $PID &> /dev/null rmmod -f tiwlan_drv rmmod -f sdio cp $WLAN_SUPPL_PATH/wpa_supplicant.txt $WLAN_SUPPL_PATH/wpa_supplicant.backup.txt cp $WLAN_SUPPL_PATH/wpa_supplicant_default.txt $WLAN_SUPPL_PATH/wpa_supplicant.txt echo false > $WLAN_DIAG_INTERFACE echo 4 > $WLAN_DIAG_CONSTAT echo 0 > $WLAN_DIAG_RSSI } # wl_stop case "$1" in start) logger -s -t $loggerName "Wlan Start" wl_start ;; stop) logger -s -t $loggerName "Wlan Stop" wl_stop ;; restart) logger -s -t $loggerName "Wlan Restart" wl_restart ;; *) logger -s -t $loggerName "Invalid Command" ;; esac logger -s -t $loggerName "Install Skript tiwlan ready!"