/*-
* Copyright (c) 2008-2009 Iain Hibbert
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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.
*/
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2008-2009 Iain Hibbert. All rights reserved.");
__RCSID("$NetBSD: btpand.c,v 1.9 2024/06/04 06:24:58 plunky Exp $");
case 'c': /* control socket path */
control_path = optarg;
break;
case 'd': /* local address */
if (!bt_devaddr(optarg, &local_bdaddr))
err(EXIT_FAILURE, "%s", optarg);
break;
case 'i': /* tap interface name */
if (strchr(optarg, '/') == NULL) {
asprintf(&ep, "/dev/%s", optarg);
interface_name = ep;
} else {
interface_name = optarg;
}
break;
case 'l': /* limit server sessions */
ul = strtoul(optarg, &ep, 10);
if (*optarg == '\0' || *ep != '\0' || ul == 0)
errx(EXIT_FAILURE, "%s: invalid session limit", optarg);
server_limit = ul;
break;
case 'm': /* link mode */
if (strcasecmp(optarg, "auth") == 0)
l2cap_mode = L2CAP_LM_AUTH;
else if (strcasecmp(optarg, "encrypt") == 0)
l2cap_mode = L2CAP_LM_ENCRYPT;
else if (strcasecmp(optarg, "secure") == 0)
l2cap_mode = L2CAP_LM_SECURE;
else if (strcasecmp(optarg, "none"))
errx(EXIT_FAILURE, "%s: unknown mode", optarg);
break;
case 'p': /* protocol/service multiplexer */
ul = strtoul(optarg, &ep, 0);
if (*optarg == '\0' || *ep != '\0'
|| ul > 0xffff || L2CAP_PSM_INVALID(ul))
errx(EXIT_FAILURE, "%s: invalid PSM", optarg);
l2cap_psm = (uint16_t)ul;
break;
case 's': /* service */
case 'S': /* service (no SDP) */
for (ul = 0; ul < __arraycount(services); ul++) {
if (strcasecmp(optarg, services[ul].type) == 0)
break;
}
if (ul == __arraycount(services))
errx(EXIT_FAILURE, "%s: unknown service", optarg);
/*
* fork() now so that the setup can be done in the child process
* (as kqueue is not inherited) but block in the parent until the
* setup is finished so we can return an error if necessary.
*/
switch(fork()) {
case -1: /* bad */
err(EXIT_FAILURE, "fork() failed");
/*NOTREACHED*/