| BT_DEV(3) | Library Functions Manual | BT_DEV(3) | 
bt_devaddr, bt_devname,
  bt_devenum, bt_devinfo,
  bt_devopen, bt_devsend,
  bt_devrecv, bt_devreq,
  bt_devfilter,
  bt_devfilter_pkt_set,
  bt_devfilter_pkt_clr,
  bt_devfilter_pkt_tst,
  bt_devfilter_evt_set,
  bt_devfilter_evt_clr,
  bt_devfilter_evt_tst,
  bt_devinquiry —
#include <bluetooth.h>
int
  
  bt_devaddr(const
    char *name, bdaddr_t
    *bdaddr);
int
  
  bt_devname(char
    *name, const bdaddr_t
    *bdaddr);
int
  
  bt_devenum(int
    (*cb)(int, const struct bt_devinfo *, void *),
    void *arg);
int
  
  bt_devinfo(const
    char *name, struct
    bt_devinfo *info);
int
  
  bt_devopen(const
    char *name, int
    flags);
ssize_t
  
  bt_devsend(int
    s, uint16_t opcode,
    void *param,
    size_t plen);
ssize_t
  
  bt_devrecv(int
    s, void *buf,
    size_t size,
    time_t timeout);
int
  
  bt_devreq(int
    s, struct bt_devreq
    *req, time_t
    timeout);
int
  
  bt_devfilter(int
    s, const struct
    bt_devfilter *new, struct
    bt_devfilter *old);
void
  
  bt_devfilter_pkt_set(struct
    bt_devfilter *filter,
    uint8_t type);
void
  
  bt_devfilter_pkt_clr(struct
    bt_devfilter *filter,
    uint8_t type);
int
  
  bt_devfilter_pkt_tst(const
    struct bt_devfilter *filter,
    uint8_t type);
void
  
  bt_devfilter_evt_set(struct
    bt_devfilter *filter,
    uint8_t event);
void
  
  bt_devfilter_evt_clr(struct
    bt_devfilter *filter,
    uint8_t event);
int
  
  bt_devfilter_evt_tst(const
    struct bt_devfilter *filter,
    uint8_t event);
int
  
  bt_devinquiry(const
    char *name, time_t
    timeout, int
    max_rsp, struct
    bt_devinquiry **iip);
bt_devaddr(name,
    bdaddr)bt_devaddr()
      will return 1 if the NUL-terminated name string
      refers to a Bluetooth device present in the system, otherwise 0. The name
      may be given as a device name (eg “ubt0”) or Bluetooth
      device address (eg “00:11:22:33:44:55”) and the actual
      device address will be written to bdaddr if not
      NULL.bt_devname(name,
    bdaddr)bt_devname()
      returns 1 if the bdaddr refers to a Bluetooth device
      present in the system, otherwise 0. The name buffer,
      if given, should have space for at least
      HCI_DEVNAME_SIZE bytes and the string will be
      NUL-terminated.bt_devenum(cb,
    arg)NULL) will be called with the
      arg argument provided, a fully populated
      bt_devinfo structure and, where the device is
      enabled, a socket handle as returned by
      bt_devopen(). The callback function can halt the
      enumeration by returning a non-zero value, and
      bt_devenum() returns the number of successfully
      enumerated devices.bt_devinfo(name,
    info)
        char        devname[HCI_DEVNAME_SIZE];
        int         enabled;    /* device is enabled */
        /* device information */
        bdaddr_t    bdaddr;
        uint8_t     features[HCI_FEATURES_SIZE];
        uint16_t    acl_size;   /* max ACL data size */
        uint16_t    acl_pkts;   /* total ACL packet buffers */
        uint16_t    sco_size;   /* max SCO data size */
        uint16_t    sco_pkts;   /* total SCO packet buffers */
        /* flow control */
        uint16_t    cmd_free;   /* available CMD packet buffers */
        uint16_t    acl_free;   /* available ACL packet buffers */
        uint16_t    sco_free;   /* available SCO packet buffers */
        /* statistics */
        uint32_t    cmd_sent;
        uint32_t    evnt_recv;
        uint32_t    acl_recv;
        uint32_t    acl_sent;
        uint32_t    sco_recv;
        uint32_t    sco_sent;
        uint32_t    bytes_recv;
        uint32_t    bytes_sent;
        /* device settings */
        uint16_t    link_policy_info;
        uint16_t    packet_type_info;
        uint16_t    role_switch_info;
    
    Because a Bluetooth device must be enabled in order to retrieve information, the enabled flag should be tested to be non-zero before relying on further data.
bt_devopen(name,
    flags)NULL, enabled to receive packets from any device.
      The socket should be closed using
      close(2) after use. Any
      combination of the following flags may be used to
      pre-set the socket options:
    BTOPT_DIRECTIONBTOPT_TIMESTAMPThe default filter on the socket will only allow the HCI Event packets “Command Status” and “Command Complete” to be received.
bt_devsend(s,
    opcode, param,
    plen)bt_devsend() will return the number of bytes
      successfully written.bt_devrecv(s,
    buf, size,
    timeout)bt_devrecv() will return the number of bytes
      successfully received unless the provided buffer could not contain the
      entire packet, or if a timeout was requested with a non-negative
      timeout value.bt_devreq(s,
    req, timeout)
struct bt_devreq {
        uint16_t        opcode;
        uint8_t         event;
        void           *cparam;
        size_t          clen;
        void           *rparam;
        size_t          rlen;
};
    
    bt_devreq() sends an HCI command
        packet with the given opcode and command
        parameters of clen bytes at
        cparam then waits up to
        timeout seconds for the command to return a
        “Command Complete” event. In the case where the command
        returns “Command Status” and an additional event, and
        where the status indicates that the command is in progress,
        bt_devreq() will wait for the additional
        event specified in the request. If required, any
        response will be copied into the buffer of rlen
        bytes at rparam, and rlen
        will be adjusted to indicate the number of bytes stored.
        bt_devreq() temporarily modifies the socket
        filter.
bt_devfilter(s,
    new, old)bt_devfilter_pkt_set(filter,
    type)bt_devfilter_pkt_clr(filter,
    type)bt_devfilter_pkt_tst(filter,
    type)bt_devfilter_evt_set(filter,
    event)bt_devfilter_evt_clr(filter,
    event)bt_devfilter_evt_tst(filter,
    event)bt_devinquiry(name,
    timeout, max_rsp,
    iip)NULL is passed.
      The inquiry length will be timeout seconds, and the
      number of responses (up to a limit of max_rsp) will
      be returned. A pointer to an array of bt_devinquiry
      structures, defined as:
    
struct bt_devinquiry {
        bdaddr_t        bdaddr;
        uint8_t         pscan_rep_mode;
        uint8_t         pscan_period_mode;
        uint8_t         dev_class[3];
        uint16_t        clock_offset;
        int8_t          rssi;
        uint8_t         data[240];
};
    
    will be stored in the location given by iip and this should be released after use with free(3).
| October 25, 2011 | NetBSD 9.4 |