Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

system-bluetooth: Commit

system/bluetooth


Commit MetaInfo

Revision4b5b3bcfc601d8ac802372dd09f317ecd4457969 (tree)
Time2011-12-19 15:35:49
AuthorChih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Log Message

bluedroid: fix several issues to enable a bluetooth device

* set_bluetooth_power(): check the rfkill state before set it. If the

state is already the expected value, don't write to it. This avoids
the permission issue after wakeup for external bluetooth dongle.

* bt_enable(): try to disable and re-enable eeepc-bluetooth if unable

to turn on it, since the rfkill id may has changed.

Change-Id: Ib21637acf17ab2f3f8d4379ebd570f0cf85189da

Change Summary

Incremental Difference

--- a/bluedroid/bluetooth.c
+++ b/bluedroid/bluetooth.c
@@ -82,7 +82,6 @@ static int init_rfkill() {
8282 }
8383
8484 static int check_bluetooth_power() {
85- int sz;
8685 int fd = -1;
8786 int ret = -1;
8887 char buffer;
@@ -97,8 +96,7 @@ static int check_bluetooth_power() {
9796 errno);
9897 goto out;
9998 }
100- sz = read(fd, &buffer, 1);
101- if (sz != 1) {
99+ if (read(fd, &buffer, 1) != 1) {
102100 LOGE("read(%s) failed: %s (%d)", rfkill_state_path, strerror(errno),
103101 errno);
104102 goto out;
@@ -119,14 +117,14 @@ out:
119117 }
120118
121119 static int set_bluetooth_power(int on) {
122- int sz;
123120 int fd = -1;
124- int ret = -1;
121+ int ret = check_bluetooth_power();
125122 const char buffer = (on ? '1' : '0');
126123
127- if (rfkill_state_path[0] == '\0') {
128- if (init_rfkill()) goto out;
129- }
124+ if (ret < 0)
125+ return ret;
126+ else if (ret == on)
127+ return 0;
130128
131129 fd = open(rfkill_state_path, O_WRONLY);
132130 if (fd < 0) {
@@ -134,8 +132,7 @@ static int set_bluetooth_power(int on) {
134132 strerror(errno), errno);
135133 goto out;
136134 }
137- sz = write(fd, &buffer, 1);
138- if (sz < 0) {
135+ if (write(fd, &buffer, 1) != 1) {
139136 LOGE("write(%s) failed: %s (%d)", rfkill_state_path, strerror(errno),
140137 errno);
141138 goto out;
@@ -147,7 +144,7 @@ out:
147144 return ret;
148145 }
149146
150-static inline int create_hci_sock() {
147+static int create_hci_sock() {
151148 int sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
152149 if (sk < 0) {
153150 LOGE("Failed to create bluetooth hci socket: %s (%d)",
@@ -163,8 +160,6 @@ int bt_enable() {
163160 int hci_sock = -1;
164161 int attempt;
165162
166- if (set_bluetooth_power(1) < 0) goto out;
167-
168163 LOGI("Starting hciattach daemon");
169164 if (property_set("ctl.start", "hciattach") < 0) {
170165 LOGE("Failed to start hciattach");
@@ -174,13 +169,19 @@ int bt_enable() {
174169
175170 // Try for 10 seconds, this can only succeed once hciattach has sent the
176171 // firmware and then turned on hci device via HCIUARTSETPROTO ioctl
177- for (attempt = 1000; attempt > 0; attempt--) {
172+ for (attempt = 10; attempt > 0; --attempt) {
173+ int res = set_bluetooth_power(1);
174+ usleep(900000);
175+ if (res < 0) {
176+ bt_disable();
177+ continue;
178+ }
178179 hci_sock = create_hci_sock();
179180 if (hci_sock < 0) goto out;
180181
181182 ret = ioctl(hci_sock, HCIDEVUP, HCI_DEV_ID);
182183
183- LOGI("bt_enable: ret: %d, errno: %d", ret, errno);
184+ LOGI("bt_enable: ret: %d, errno: %s (%d)", ret, strerror(errno), errno);
184185 if (!ret) {
185186 break;
186187 } else if (errno == EALREADY) {
Show on old repository browser