110d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly/* 210d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly** Copyright 2009 The Android Open Source Project 310d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly** 410d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly** Licensed under the Apache License, Version 2.0 (the "License"); 510d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly** you may not use this file except in compliance with the License. 610d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly** You may obtain a copy of the License at 710d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly** 810d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly** http://www.apache.org/licenses/LICENSE-2.0 910d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly** 1010d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly** Unless required by applicable law or agreed to in writing, software 1110d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly** distributed under the License is distributed on an "AS IS" BASIS, 1210d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1310d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly** See the License for the specific language governing permissions and 1410d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly** limitations under the License. 1510d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly*/ 1610d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly 1710d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly#include <stdio.h> 1810d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly#include <stdlib.h> 1910d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly#include <unistd.h> 2010d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly#include <sys/socket.h> 2110d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly#include <fcntl.h> 22fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly#include <errno.h> 2310d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly 2410d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly#include <bluetooth/bluetooth.h> 2510d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly#include <bluetooth/rfcomm.h> 2610d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly 2710d31b957a35d4ac084be33b0f136568039c9c14Nick Pellyint main(int argc, char **argv) { 28fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly int fd; 29fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly int ret; 30fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly long flags; 31fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly struct sockaddr_rc addr; 32fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly 33fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly addr.rc_family = AF_BLUETOOTH; 34fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly addr.rc_channel = 19; 35fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly str2ba("00:17:E8:2C:A8:00", &addr.rc_bdaddr); 36fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly 37fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly fd = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); 38fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly flags = fcntl(fd, F_GETFL); 39fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly fcntl(fd, F_SETFL, flags | O_NONBLOCK); 40fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly 41fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly ret = connect(fd, (struct sockaddr *)&addr, sizeof(addr)); 42fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly if (ret < 0) { 43fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly printf("%d errno %d %s\n", __LINE__, errno, strerror(errno)); 44fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly } 45fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly 46fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly sleep(2); 47fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly shutdown(fd, SHUT_RDWR); 48fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly 49fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly 50fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly fd = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); 51fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly 52fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly ret = connect(fd, (struct sockaddr *)&addr, sizeof(addr)); 53fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly if (ret < 0) { 54fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly printf("%d errno %d %s\n", __LINE__, errno, strerror(errno)); 55fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly } 56fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly 57fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly sleep(2); 58fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly 59fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly shutdown(fd, SHUT_RDWR); 60fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly 61fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly sleep(2); 62fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly return 0; 6310d31b957a35d4ac084be33b0f136568039c9c14Nick Pelly} 64