tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: /etc/rc.d/bluetooth



On Fri, 20 May 2011 18:22:14 +0100 (BST)
Iain Hibbert <plunky%rya-online.net@localhost> wrote:

> Hi
> 
> People have said in the past that the Bluetooth support is too complicated
> to start up, in that you need too much knowledge of how it works. (I do
> agree, though note that many services are like that, its just that those
> people are usually experts at network and RAID setup already :)
> 
> Anyway, I wrote a /etc/rc.d/bluetooth startup script that combines
> functionality and sets up the controllers with sensible useful defaults,
> so that setting just "bluetooth=YES" should be enough to get you going..
> 
> comments, before I start obsoleting the complex methods?
> 
> iain
> 
> #!/bin/sh
> #
> # $NetBSD: bluetooth$
> #
> 
> # PROVIDE: bluetooth
> # REQUIRE: DAEMON
> # BEFORE:  LOGIN
> 
> $_rc_subr_loaded . /etc/rc.subr
> 
> name="bluetooth"
> rcvar=${name}
> start_cmd="bluetooth_start"
> stop_cmd="bluetooth_stop"
> 
> # defaults (can be overridden by rc.conf)
> btattach_cmd="/usr/sbin/btattach"
> btattach_conf="/etc/bluetooth/btattach.conf"
> btconfig_cmd="/usr/sbin/btconfig"
> bthcid_cmd="/usr/sbin/bthcid"
> bthcid=YES
> btdevctl_cmd="/usr/sbin/btdevctl"
> btdevctl_conf="/etc/bluetooth/btdevctl.conf"
> sdpd_cmd="/usr/sbin/sdpd"
> sdpd=YES
> 
> required_files="${btattach_conf} ${btdevctl_conf}"
> 
> bluetooth_start()
> {
>       #
>       # attach Bluetooth serial controllers
>       #
>       while read type tty speed flags; do
>               case ${type} in
>               \#*|"")
>                       continue
>                       ;;
>               esac
> 
>               echo -n " $(basename ${tty})"
>               ${btattach_cmd} ${flags} ${type} ${tty} ${speed}
>       done < ${btattach_conf}
> 
>       #
>       # enable Bluetooth controllers.
>       #
>       # If ${btconfig_devices} is set, it is treated as a list of devices
>       # to configure. Otherwise, all available devices will be configured
>       #
>       # For each device we are configuring, enable it with maximum security
>       # settings (not discoverable, not connectable, auth and encryption
>       # required for all connections), relaxed link policy settings and
>       # the link master role, set a class of device for Computer, then apply
>       # any options from the 'btconfig_<dev>' or 'btconfig_args' variables
>       # on top of settings relaxing the security requirements, so that these
>       # can be overridden (btconfig parses all command line options before
>       # acting)
>       #
>       for dev in ${btconfig_devices:-$(${btconfig_cmd} -l)}; do
>               echo -n " ${dev}"
>               eval args=\${btconfig_${dev}:-\${btconfig_args}}
>               ${btconfig_cmd} ${dev} enable -iscan -pscan auth encrypt
>               ${btconfig_cmd} ${dev} switch hold sniff park master
>               ${btconfig_cmd} ${dev} class 0x000100
>               ${btconfig_cmd} ${dev} iscan pscan -auth -encrypt ${args}
>       done
> 
>       #
>       # start Bluetooth Link Key/PIN Code manager
>       #
>       if checkyesno bthcid; then
>               echo -n " bthcid"
>               ${bthcid_cmd} ${bthcid_flags}
>       fi
> 
>       #
>       # attach local Bluetooth drivers
>       #
>       while read -r service addr dev junk; do
>               case ${service} in
>               \#*|"")
>                       continue
>                       ;;
>               esac
> 
>               if [ -z ${dev} -o ${junk} ]; then
>                       echo "${name}: invalid entry"
>                       return 1
>               fi
> 
>               echo -n " ${addr}/${service}"
>               ${btdevctl_cmd} -A -a ${addr} -d ${dev} -s ${service}
>       done < ${btdevctl_conf}
> 
>       #
>       # start Bluetooth Service Discovery server
>       #
>       if checkyesno sdpd; then
>               echo -n " sdpd"
>               ${sdpd_cmd} ${sdpd_flags}
>       fi
> 
>       echo "."
> }
> 
> bluetooth_stop()
> {
>       #
>       # disable Bluetooth controllers, detaching local Bluetooth drivers
>       #
>       for dev in ${btconfig_devices:-$(${btconfig_cmd} -l)}; do
>               echo -n " ${dev}"
>               ${btconfig_cmd} ${dev} disable
>       done
> 
>       #
>       # halt Service Discovery server, Link Key/PIN Code manager,
>       # and detach Bluetooth serial controllers
>       #
>       p1=$(check_pidfile /var/run/bthcid.pid ${bthcid_cmd})
>       p2=$(check_process ${sdpd_cmd})
>       p3=$(check_process ${btattach_cmd})
>       if [ -n "${p1}${p2}${p3}" ]; then
>               for pid in ${p1} ${p2} ${p3}; do
>                       kill ${sig_stop} ${pid}
>               done
>               wait_for_pids ${p1} ${p2} ${p3}
>       fi
> 
>       echo "."
> }
> 
> load_rc_config ${name}
> run_rc_command "$1"

very nice idea! i love when something works out of the box, even
if i know how to configure it.

-- 
NetBSD - Simplicity is prerequisite for reliability


Home | Main Index | Thread Index | Old Index