00001 #ifndef _OASYS_BTSDP_H_
00002 #define _OASYS_BTSDP_H_
00003
00004 #include <config.h>
00005 #ifdef OASYS_BLUETOOTH_ENABLED
00006
00007 #include <bluetooth/bluetooth.h>
00008 #include <bluetooth/sdp.h>
00009 #include <bluetooth/sdp_lib.h>
00010
00011 #include "../debug/Log.h"
00012
00013
00014
00015
00016 #define OASYS_BLUETOOTH_SDP_UUID { 0xDCA3, 0x8352, 0xBF60, 0x11DA, \
00017 0xA23B, 0x0003, 0x931B, 0x7960 }
00018
00019 namespace oasys {
00020
00021
00022 #if 0
00023
00024 typedef struct _sdp_list sdp_list_t;
00025 struct _sdp_list {
00026 sdp_list_t *next;
00027 void *data;
00028 };
00029
00030 #endif
00031
00032
00033 class SDPListHead
00034 {
00035 public:
00036 SDPListHead() :
00037 free_func_(NULL), head_(NULL), current_(NULL)
00038 {
00039 }
00040
00041 SDPListHead(sdp_list_t *head)
00042 : free_func_(NULL), current_(NULL)
00043 {
00044 head_ = head;
00045 }
00046
00047 ~SDPListHead()
00048 {
00049 free_list();
00050 }
00051
00052
00053
00054 void set_free_func(sdp_free_func_t f) { free_func_ = f; }
00055
00056
00057 sdp_list_t* head() { return head_; }
00058 void head(sdp_list_t* head) { free_list(); head_ = head; }
00059
00060
00061
00062
00063 sdp_list_t* next() {
00064 if (current_) {
00065 current_ = current_->next;
00066 return current_;
00067 }
00068 current_ = head_;
00069 return current_;
00070 }
00071
00072 protected:
00073 void free_list()
00074 {
00075
00076 while (head_) {
00077
00078 sdp_list_t *next = head_->next;
00079
00080 if (free_func_)
00081 free_func_(head_->data);
00082
00083 free(head_);
00084
00085 head_ = next;
00086 }
00087 }
00088
00089 sdp_free_func_t free_func_;
00090 sdp_list_t *head_;
00091 sdp_list_t *current_;
00092 };
00093
00098 class BluetoothServiceDiscoveryClient : public Logger
00099 {
00100 public:
00101 BluetoothServiceDiscoveryClient(const char* logpath = "/dtn/bt/sdp/client");
00102 ~BluetoothServiceDiscoveryClient();
00103
00104 bool is_dtn_router(bdaddr_t addr);
00105
00106 void set_local_addr(bdaddr_t& addr) {
00107 bacpy(&local_addr_,&addr);
00108 }
00109
00110 void get_local_addr(bdaddr_t& addr) {
00111 bacpy(&addr,&local_addr_);
00112 }
00113
00114 protected:
00115
00116 sdp_record_t* get_next_service_record();
00117
00118
00119 bool connect();
00120 bool close();
00121
00122
00123 sdp_list_t* do_search();
00124
00125
00126 bdaddr_t remote_addr_;
00127 bdaddr_t local_addr_;
00128 SDPListHead *response_list_;
00129 sdp_session_t *session_handle_;
00130 };
00131
00132 class BluetoothServiceRegistration : public Logger
00133 {
00134 public:
00135
00136
00137
00138
00139 #define OASYS_BLUETOOTH_SDP_UUID { 0xDCA3, 0x8352, 0xBF60, 0x11DA, \
00140 0xA23B, 0x0003, 0x931B, 0x7960 }
00141
00142 #define OASYS_BLUETOOTH_SDP_NAME "dtnd"
00143 #define OASYS_BLUETOOTH_SDP_DESC "Delay Tolerant Networking daemon"
00144 #define OASYS_BLUETOOTH_SDP_PROV "DTNRG"
00145
00146 BluetoothServiceRegistration(bdaddr_t* local = BDADDR_ANY,
00147 const char* logpath = "/dtn/bt/sdp/reg");
00148 ~BluetoothServiceRegistration();
00149
00150 bool success() {return status_;};
00151
00152 protected:
00153 bool register_service();
00154
00155 sdp_session_t* session_handle_;
00156 bool status_;
00157 bdaddr_t local_addr_;
00158 };
00159
00160 }
00161
00162 #endif
00163 #endif