00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "config.h"
00018
00019 #ifdef OASYS_BLUETOOTH_ENABLED
00020
00021 #include "Bluetooth.h"
00022 #include "RFCOMMClient.h"
00023 #include <errno.h>
00024
00025 extern int errno;
00026
00027 namespace oasys {
00028
00029 int
00030 RFCOMMClient::rc_connect(bdaddr_t remote_addr)
00031 {
00032 int res = -1;
00033
00034 set_remote_addr(remote_addr);
00035
00036 for (channel_ = 1; channel_ <= 30; channel_++) {
00037
00038 if ((res = bind()) != 0) {
00039
00040 close();
00041
00042 if (errno != EADDRINUSE) {
00043
00044 if ( params_.silent_connect_ == false )
00045 log_err("error binding to %s:%d: %s",
00046 bd2str(local_addr_), channel_, strerror(errno));
00047
00048
00049 if (errno == EBADFD) {
00050
00051 }
00052
00053 break;
00054 }
00055
00056 if ( params_.silent_connect_ == false )
00057 log_debug("can't bind to %s:%d: %s",
00058 bd2str(local_addr_), channel_, strerror(errno));
00059
00060 } else {
00061
00062
00063
00064 if ((res = connect()) == 0) {
00065
00066
00067 if ( params_.silent_connect_ == false )
00068 log_debug("connected to %s:%d",
00069 bd2str(remote_addr_), channel_);
00070
00071 return res;
00072
00073 } else {
00074
00075 close();
00076
00077
00078 if ( params_.silent_connect_ == false )
00079 log_debug("can't connect to %s:%d: %s",
00080 bd2str(remote_addr_), channel_, strerror(errno));
00081
00082
00083 if (errno == EBADFD) {
00084
00085 }
00086
00087 }
00088 }
00089 }
00090
00091 log_err("Scanned all RFCOMM channels but unable to connect to %s",
00092 bd2str(remote_addr_));
00093 return -1;
00094 }
00095
00096 int
00097 RFCOMMClient::rc_connect()
00098 {
00099 ASSERT(bacmp(&remote_addr_,BDADDR_ANY)!=0);
00100 return rc_connect(remote_addr_);
00101 }
00102
00103
00104 }
00105
00106 #endif