From 905033dc11714a0471d8fd790720304f6937613a Mon Sep 17 00:00:00 2001 From: Maksim Yevmenkin Date: Mon, 2 Feb 2009 18:08:22 +0000 Subject: [PATCH] Fix client mode. Pick up service availability changes. Obtained from: NetBSD MFC after: 1 month --- usr.sbin/bluetooth/btpand/btpand.c | 7 +++++-- usr.sbin/bluetooth/btpand/btpand.h | 4 ++++ usr.sbin/bluetooth/btpand/server.c | 29 ++++++++++------------------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/usr.sbin/bluetooth/btpand/btpand.c b/usr.sbin/bluetooth/btpand/btpand.c index 57ee1331b3c2..99a3bc7eacd4 100644 --- a/usr.sbin/bluetooth/btpand/btpand.c +++ b/usr.sbin/bluetooth/btpand/btpand.c @@ -54,8 +54,8 @@ uint16_t service_class; bdaddr_t local_bdaddr; /* -d */ bdaddr_t remote_bdaddr; /* -a */ -uint16_t l2cap_psm = 15; /* -p */ -int l2cap_mode = 0; /* -m */ +uint16_t l2cap_psm; /* -p */ +int l2cap_mode; /* -m */ int server_limit; /* -n */ @@ -177,6 +177,9 @@ main(int argc, char *argv[]) if (interface_name == NULL) interface_name = "/dev/tap"; + if (l2cap_psm == 0) + l2cap_psm = L2CAP_PSM_BNEP; + if (bdaddr_any(&remote_bdaddr) && server_limit == 0) { if (service_class == SDP_SERVICE_CLASS_PANU) server_limit = 1; diff --git a/usr.sbin/bluetooth/btpand/btpand.h b/usr.sbin/bluetooth/btpand/btpand.h index 23a9c76b8dae..c5f7204ab403 100644 --- a/usr.sbin/bluetooth/btpand/btpand.h +++ b/usr.sbin/bluetooth/btpand/btpand.h @@ -51,6 +51,10 @@ #define L2CAP_PSM_INVALID(psm) (((psm) & 0x0101) != 0x0001) #endif +#ifndef L2CAP_PSM_BNEP +#define L2CAP_PSM_BNEP 15 +#endif + typedef struct channel channel_t; typedef struct pfilter pfilter_t; typedef struct mfilter mfilter_t; diff --git a/usr.sbin/bluetooth/btpand/server.c b/usr.sbin/bluetooth/btpand/server.c index 5600c3b14403..0843d0c70926 100644 --- a/usr.sbin/bluetooth/btpand/server.c +++ b/usr.sbin/bluetooth/btpand/server.c @@ -1,4 +1,4 @@ -/* $NetBSD: server.c,v 1.1 2008/08/17 13:20:57 plunky Exp $ */ +/* $NetBSD: server.c,v 1.2 2009/01/24 17:29:28 plunky Exp $ */ /*- * Copyright (c) 2008 Iain Hibbert @@ -28,11 +28,12 @@ /* $FreeBSD$ */ #include -__RCSID("$NetBSD: server.c,v 1.1 2008/08/17 13:20:57 plunky Exp $"); +__RCSID("$NetBSD: server.c,v 1.2 2009/01/24 17:29:28 plunky Exp $"); #include #include +#include #include #include #include @@ -42,7 +43,7 @@ __RCSID("$NetBSD: server.c,v 1.1 2008/08/17 13:20:57 plunky Exp $"); static struct event server_ev; static int server_fd; -static int server_load; +static int server_avail; static void * server_ss; static uint32_t server_handle; @@ -73,13 +74,13 @@ server_update(int count) log_debug("count %d", count); - server_load = (count - 1) * 100 / server_limit; - log_info("server_load: %d%%", server_load); + server_avail = UINT8_MAX - (count - 1) * UINT8_MAX / server_limit; + log_info("Service Availability: %d/%d", server_avail, UINT8_MAX); - if (server_load > 99 && server_fd != -1) + if (server_avail == 0 && server_fd != -1) server_close(); - if (server_load < 100 && server_fd == -1) + if (server_avail > 0 && server_fd == -1) server_open(); if (service_name) @@ -257,19 +258,9 @@ server_register(void) } memset(&p, 0, sizeof(p)); - p.psm = l2cap_psm; - - if (server_load < 1) p.load_factor = 0; - else if (server_load <= 17) p.load_factor = 1; - else if (server_load <= 33) p.load_factor = 2; - else if (server_load <= 50) p.load_factor = 3; - else if (server_load <= 67) p.load_factor = 4; - else if (server_load <= 83) p.load_factor = 5; - else if (server_load <= 99) p.load_factor = 6; - else p.load_factor = 7; - - if (l2cap_mode != 0) p.security_description = 0x0001; + p.load_factor = server_avail; + p.security_description = (l2cap_mode == 0 ? 0x0000 : 0x0001); if (server_handle) rv = sdp_change_service(server_ss, server_handle,