nokia 9300 & gentoo bluetooth connect script

here is a simple snippet to use your nokia 9300i as a modem assuming you have all the right bluetooth tools on your machine. this script was only tested with gentoo, not that it would make any difference:

# this script runs as either root or sudo - 
# this script connects to a 9300 (a, b or i) via bluetooth
# this script also assumes that you have scripts gprs, gprs-connect-chat & gprs-disconnet-chat
# located in /etc/ppp/peers
# creating a pause function for user input to run script non-automaticaly

# simplified pause function
# had a bigger pause function but was edited out
function pause(){
    read -p "$*"

# info store and clean up

if [ -f ${HCI_INFO} ]; then
    rm -rfd ${HCI_INFO} && touch ${HCI_INFO}

if [ -f ${HID_INFO} ]; then
    rm -rfd ${HID_INFO} && touch ${HID_INFO}

if [ -f ${ETH_INFO} ]; then
    rm -rfd ${ETH_INFO} && touch ${ETH_INFO}

if [ -f ${RFC_INFO} ]; then
    rm -rfd ${RFC_INFO} && touch ${RFC_INFO}

# local info
    LOCAL_BID=`hcitool dev | egrep hci0`
    echo "local bid:" " ${LOCAL_BID}"
    printf "\n"

# remote hosts info
    hcitool scan | egrep -v "Scanning ..." >> ${HCI_INFO}
    # -s means contain data
    if [ ! -s ${HCI_INFO} ]; then
        printf "hcitool scan is coming back blank\n"
	printf "double check that bluetooth devices are on\n"
	printf "exiting\n"
	exit 1
    printf "remote bid from hcitool:\n"
    cat ${HCI_INFO}
    printf "\n"

# channel search
    printf "enter bid from specified device (from list above, mac addy looking number):"
    read BID_HID
    # -z means string is null - (length is zero)
    if [ -z ${BID_HID} ]; then
        printf "must input data here.\n"
	printf "\n"
	printf "exiting\n"
	exit 1
    sdptool browse ${BID_HID} | grep Dial-Up -A 14 >> ${HID_INFO}
    printf "dial-up networking info from device:\n"
    cat ${HID_INFO}
    printf "\n"

# bind channel to rfcomm device
    BID_ID=`cat ${HCI_INFO} | grep ${BID_HID} | awk '{print $1}'`
    CHANNEL=`cat ${HID_INFO} | grep Channel | awk '{print$2}'`
    printf "checking and removing previous rfcomm binds for new bind\n"
    rfcomm >> ${RFC_INFO}
    if [ -s ${RFC_INFO} ]; then
        rfcomm release rfcomm0
    rfcomm bind 0 ${BID_ID} ${CHANNEL}
    printf "\nrfcomm binding info:\n"
    printf "\n"

# pausing for review
    pause 'pausing so you can see the data thusfar.....'

# beginning pppd stuff
# make sure that all net ifaces are down
    printf "make sure that at this point all ifaces are down\n"
    printf "\n"
    /sbin/ifconfig | egrep "Link encap" | egrep -v Loopback >> ${ETH_INFO}
#   doing a ! -s for temp    
#    if [ -s ${ETH_INFO} ]; then
    if [ ! -s ${ETH_INFO} ]; then

        printf "there is a network adapter still up:\n"
        cat ${ETH_INFO}
	exit 1
    pause 'about to connect - press enter to continue....'

# beginning pppd messages & logs
    pppd call gprs

    Leave a Reply

    Your email address will not be published. Required fields are marked *