Fix client mode. Pick up service availability changes.

Obtained from:	NetBSD
MFC after:	1 month
This commit is contained in:
Maksim Yevmenkin 2009-02-02 18:08:22 +00:00
parent 8216b39e2b
commit 905033dc11
3 changed files with 19 additions and 21 deletions

View File

@ -54,8 +54,8 @@ uint16_t service_class;
bdaddr_t local_bdaddr; /* -d <addr> */
bdaddr_t remote_bdaddr; /* -a <addr> */
uint16_t l2cap_psm = 15; /* -p <psm> */
int l2cap_mode = 0; /* -m <mode> */
uint16_t l2cap_psm; /* -p <psm> */
int l2cap_mode; /* -m <mode> */
int server_limit; /* -n <limit> */
@ -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;

View File

@ -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;

View File

@ -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 <sys/cdefs.h>
__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 <sys/ioctl.h>
#include <bluetooth.h>
#include <inttypes.h>
#include <errno.h>
#include <sdp.h>
#include <unistd.h>
@ -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,