/*-
* Copyright (c) 2006 Itronix Inc.
* All rights reserved.
*
* Written by Iain Hibbert for Itronix Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of Itronix Inc. may not be used to endorse
* or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*****************************************************************************
*
* bthub autoconf(9) routines
*
* A Hub is attached to each Bluetooth Controller as it is enabled
*/
static int
bthub_match(device_t self, cfdata_t cfdata, void *arg)
{
if (!pmf_device_register(self, NULL, NULL)) {
/*
* XXX this should not be allowed to happen, but
* avoiding it needs a pretty big rearrangement of
* device attachments.
*/
aprint_error_dev(self, "couldn't establish power handler\n");
}
}
static int
bthub_detach(device_t self, int flags)
{
pmf_device_deregister(self);
return config_detach_children(self, flags);
}
/*****************************************************************************
*
* bthub access functions to control device
*/
int
bthubioctl(dev_t devno, unsigned long cmd, void *data, int flag, struct lwp *l)
{
prop_dictionary_t dict;
int err;
switch(cmd) {
case BTDEV_ATTACH:
case BTDEV_DETACH:
/* load dictionary */
err = prop_dictionary_copyin_ioctl(data, cmd, &dict);
if (err == 0) {
err = bthub_pioctl(devno, cmd, dict, flag, l);
prop_object_release(dict);
}
break;
default:
err = EPASSTHROUGH;
break;
}
return err;
}
static int
bthub_pioctl(dev_t devno, unsigned long cmd, prop_dictionary_t dict,
int flag, struct lwp *l)
{
prop_data_t laddr, raddr;
prop_string_t service;
prop_dictionary_t prop;
prop_object_t obj;
device_t dev, self;
deviter_t di;
int unit;
/* validate local address */
laddr = prop_dictionary_get(dict, BTDEVladdr);
if (prop_data_size(laddr) != sizeof(bdaddr_t))
return EINVAL;
/* locate the relevant bthub */
for (unit = 0 ; ; unit++) {
if (unit == bthub_cd.cd_ndevs)
return ENXIO;
self = device_lookup(&bthub_cd, unit);
if (self == NULL)
continue;