1/*
2** Copyright 2009 The Android Open Source Project
3**
4** Licensed under the Apache License, Version 2.0 (the "License");
5** you may not use this file except in compliance with the License.
6** You may obtain a copy of the License at
7**
8**     http://www.apache.org/licenses/LICENSE-2.0
9**
10** Unless required by applicable law or agreed to in writing, software
11** distributed under the License is distributed on an "AS IS" BASIS,
12** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13** See the License for the specific language governing permissions and
14** limitations under the License.
15*/
16
17#include <stdio.h>
18#include <stdlib.h>
19#include <unistd.h>
20#include <sys/socket.h>
21#include <fcntl.h>
22#include <errno.h>
23
24#include <bluetooth/bluetooth.h>
25#include <bluetooth/rfcomm.h>
26
27int main(int argc, char **argv) {
28    int fd;
29    int ret;
30    long flags;
31    struct sockaddr_rc addr;
32
33    addr.rc_family = AF_BLUETOOTH;
34    addr.rc_channel = 19;
35    str2ba("00:17:E8:2C:A8:00", &addr.rc_bdaddr);
36
37    fd = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
38    flags = fcntl(fd, F_GETFL);
39    fcntl(fd, F_SETFL, flags | O_NONBLOCK);
40
41    ret = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
42    if (ret < 0) {
43        printf("%d errno %d %s\n", __LINE__, errno, strerror(errno));
44    }
45
46    sleep(2);
47    shutdown(fd, SHUT_RDWR);
48
49
50    fd = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
51
52    ret = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
53    if (ret < 0) {
54        printf("%d errno %d %s\n", __LINE__, errno, strerror(errno));
55    }
56
57    sleep(2);
58
59    shutdown(fd, SHUT_RDWR);
60
61    sleep(2);
62    return 0;
63}
64