1/*
2 * client.c
3 */
4
5/*-
6 * Copyright (c) 2006 Maksim Yevmenkin <m_evmenkin@yahoo.com>
7 * All rights reserved.
8 *
--- 14 unchanged lines hidden (view full) ---
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * $Id: client.c,v 1.7 2006/09/07 21:06:53 max Exp $
31 * $FreeBSD: head/usr.sbin/bluetooth/bthidd/client.c 162494 2006-09-21 02:32:28Z emax $
32 */
33
34#include <sys/queue.h>
35#include <assert.h>
36#include <bluetooth.h>
37#include <errno.h>
38#include <fcntl.h>
39#include <stdio.h>
40#include <stdlib.h>
41#include <string.h>
42#include <syslog.h>
43#include <unistd.h>
44#include <usbhid.h>
45#include "bthid_config.h"
46#include "bthidd.h"
47
48static int32_t client_socket(bdaddr_p bdaddr, int32_t psm);
49
50/*
51 * Get next config entry and create outbound connection (if required)
52 *
53 * XXX Do only one device at a time. At least one of my devices (3COM
54 * Bluetooth PCCARD) rejects Create_Connection command if another
55 * Create_Connection command is still pending. Weird...
56 */
--- 150 unchanged lines hidden (view full) ---
207 return (0);
208}
209
210/*
211 * Create bound non-blocking socket and initiate connect
212 */
213
214static int
215client_socket(bdaddr_p bdaddr, int32_t psm)
216{
217 struct sockaddr_l2cap l2addr;
218 int32_t s, m;
219
220 s = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BLUETOOTH_PROTO_L2CAP);
221 if (s < 0)
222 return (-1);
223
--- 14 unchanged lines hidden (view full) ---
238 l2addr.l2cap_psm = 0;
239
240 if (bind(s, (struct sockaddr *) &l2addr, sizeof(l2addr)) < 0) {
241 close(s);
242 return (-1);
243 }
244
245 memcpy(&l2addr.l2cap_bdaddr, bdaddr, sizeof(l2addr.l2cap_bdaddr));
246 l2addr.l2cap_psm = psm;
247
248 if (connect(s, (struct sockaddr *) &l2addr, sizeof(l2addr)) < 0 &&
249 errno != EINPROGRESS) {
250 close(s);
251 return (-1);
252 }
253
254 return (s);
255}
256
2 * client.c
3 */
4
5/*-
6 * Copyright (c) 2006 Maksim Yevmenkin <m_evmenkin@yahoo.com>
7 * All rights reserved.
8 *
--- 14 unchanged lines hidden (view full) ---
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * $Id: client.c,v 1.7 2006/09/07 21:06:53 max Exp $
31 * $FreeBSD: head/usr.sbin/bluetooth/bthidd/client.c 162494 2006-09-21 02:32:28Z emax $
32 */
33
34#include <sys/queue.h>
35#include <assert.h>
36#include <bluetooth.h>
37#include <errno.h>
38#include <fcntl.h>
39#include <stdio.h>
40#include <stdlib.h>
41#include <string.h>
42#include <syslog.h>
43#include <unistd.h>
44#include <usbhid.h>
45#include "bthid_config.h"
46#include "bthidd.h"
47
48static int32_t client_socket(bdaddr_p bdaddr, int32_t psm);
49
50/*
51 * Get next config entry and create outbound connection (if required)
52 *
53 * XXX Do only one device at a time. At least one of my devices (3COM
54 * Bluetooth PCCARD) rejects Create_Connection command if another
55 * Create_Connection command is still pending. Weird...
56 */
--- 150 unchanged lines hidden (view full) ---
207 return (0);
208}
209
210/*
211 * Create bound non-blocking socket and initiate connect
212 */
213
214static int
215client_socket(bdaddr_p bdaddr, int32_t psm)
216{
217 struct sockaddr_l2cap l2addr;
218 int32_t s, m;
219
220 s = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BLUETOOTH_PROTO_L2CAP);
221 if (s < 0)
222 return (-1);
223
--- 14 unchanged lines hidden (view full) ---
238 l2addr.l2cap_psm = 0;
239
240 if (bind(s, (struct sockaddr *) &l2addr, sizeof(l2addr)) < 0) {
241 close(s);
242 return (-1);
243 }
244
245 memcpy(&l2addr.l2cap_bdaddr, bdaddr, sizeof(l2addr.l2cap_bdaddr));
246 l2addr.l2cap_psm = psm;
247
248 if (connect(s, (struct sockaddr *) &l2addr, sizeof(l2addr)) < 0 &&
249 errno != EINPROGRESS) {
250 close(s);
251 return (-1);
252 }
253
254 return (s);
255}
256