• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
23 #include <bluetooth/bluetooth.h>
24 #include <bluetooth/l2cap.h>
25 
main(int argc,char ** argv)26 int main(int argc, char **argv) {
27    int fd;
28    int ret;
29    long flags;
30    struct sockaddr_l2 addr;
31 
32    addr.l2_family = AF_BLUETOOTH;
33    str2ba("00:01:02:0A:0B:0C", &addr.l2_bdaddr);
34    addr.l2_psm = htobs(1);
35 
36    fd = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);
37    flags = fcntl(fd, F_GETFL);
38    fcntl(fd, F_SETFL, flags | O_NONBLOCK);
39 
40    connect(fd, (struct sockaddr *)&addr, sizeof(addr));
41 
42    sleep(1);
43    shutdown(fd, SHUT_RDWR);
44    sleep(1);
45    close(fd);
46    return 0;
47 }
48