#!/bin/sh

pppstats -a && exit 0

MAC=2c:d2:e7:19:b6:bc

#MOD=5
#while [ $MOD -gt 0 ] ; 
#    do  lsusb | grep "0cf3:3005"  && hciconfig | grep "D0:DF:9A:85" && break ;
#        modprobe -r btusb ; modprobe -r ath3k ; 
#        modprobe ath3k && echo '04ca 3002' > /sys/bus/usb/drivers/ath3k/new_id ;
#        modprobe -r ath3k ; modprobe btusb ;
#        sleep 1; MOD=$((MOD-1))
#done;
rfkill unblock bluetooth
hciconfig hci0 reset
killall bluetoothd
sleep 1
bluetoothd
HCI=5
while [ $HCI -gt 0 ] ;
    do sleep 1; hciconfig hci0 | grep "RUNNING" && break ;
       hciconfig hci0 reset;
       HCI=$((HCI-1))
done;
RFDEV=0
while [ $RFDEV -lt 5 ] ;
    do rfcomm release $RFDEV ;
    rfcomm bind $RFDEV $MAC 1;
    rfcomm show $RFDEV ;
    if [ $? -eq 0 ] ;
	then RFDEV=$((RFDEV+9)) ;
    fi ;
    RFDEV=$((RFDEV+1))
done ;
CALL=5
while [ $CALL -gt 0 ] ;
    do pppd call ks-rf rfcomm$((RFDEV-10)) ;
       sleep 5 ;
       ( pppstats -a && exit 0 ) || killall pppd;
       CALL=$((CALL-1));
    done;

