Initial version of treble support.
Defines the initial HIDL interface that will be used in place of the
old antradio.so bindings. An example server implementation is provided
as a starting point. Chip vendors are expected to implement and
maintain their own server implementations. The client of the interface
will be the new version of ANTHALService.
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..aaca436
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,4 @@
+optional_subdirs = [
+ "interfaces",
+ "example-server",
+]
diff --git a/Android.mk b/Android.mk
deleted file mode 100644
index 113b6ff..0000000
--- a/Android.mk
+++ /dev/null
@@ -1,99 +0,0 @@
-#
-# Copyright (C) 2009 Dynastream Innovations
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-ifneq ($(BOARD_ANT_WIRELESS_DEVICE),)
-
-LOCAL_PATH := $(call my-dir)
-
-#
-# ANT native library
-#
-
-include $(CLEAR_VARS)
-
-# For known qualcomm smd devices we remap the chip name to "qualcomm-smd"
-
-ifeq ($(BOARD_ANT_WIRELESS_DEVICE),"wcn3680")
-
-BOARD_ANT_WIRELESS_DEVICE := "qualcomm-smd"
-
-endif
-
-ifeq ($(BOARD_ANT_WIRELESS_DEVICE),"wl12xx")
-
-ANT_DIR := src/bluez_hci
-
-else ifeq ($(BOARD_ANT_WIRELESS_DEVICE),"bcm433x")
-
-ANT_DIR := src/bluez_hci
-
-else ifeq ($(BOARD_ANT_WIRELESS_DEVICE),"cg29xx")
-
-ANT_DIR := src/vfs
-
-else ifeq ($(BOARD_ANT_WIRELESS_DEVICE),"qualcomm-smd")
-
-ANT_DIR := src/vfs
-
-else ifeq ($(BOARD_ANT_WIRELESS_DEVICE),"qualcomm-uart")
-
-ANT_DIR := src/bt-vendor_vfs
-
-else ifeq ($(BOARD_ANT_WIRELESS_DEVICE),"qualcomm-hidl")
-
-ANT_DIR := src/qcomm-hidl
-
-else ifeq ($(BOARD_ANT_WIRELESS_DEVICE),"vfs-prerelease")
-
-ANT_DIR := src/vfs
-
-else
-
-$(error Unsupported BOARD_ANT_WIRELESS_DEVICE := $(BOARD_ANT_WIRELESS_DEVICE))
-
-endif # BOARD_ANT_WIRELESS_DEVICE type
-
-COMMON_DIR := src/common
-
-include $(LOCAL_PATH)/$(ANT_DIR)/Android.mk
-
-#
-# ANT Application
-#
-
-include $(CLEAR_VARS)
-
-LOCAL_C_INCLUDES:= \
- $(LOCAL_PATH)/src/common/inc \
- $(LOCAL_PATH)/app
-
-LOCAL_CFLAGS:= -g -c -W -Wall -O2
-
-LOCAL_SRC_FILES:= \
- app/ant_app.c
-
-LOCAL_SHARED_LIBRARIES := \
- libantradio \
- libcutils
-
-LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
-LOCAL_MODULE_TAGS := debug
-LOCAL_MODULE:=antradio_app
-
-include $(BUILD_EXECUTABLE)
-
-
-endif # BOARD_ANT_WIRELESS_DEVICE defined
diff --git a/NOTICE b/NOTICE
index 0dafa6b..4538360 100644
--- a/NOTICE
+++ b/NOTICE
@@ -1,5 +1,5 @@
ANT Android System Package
-Copyright 2009-2012 Dynastream Innovations
+Copyright 2009-2018 Dynastream Innovations
This product includes software developed at
Dynastream Innovations (http://www.dynastream.com/).
\ No newline at end of file
diff --git a/README.md b/README.md
deleted file mode 100644
index d040c04..0000000
--- a/README.md
+++ /dev/null
@@ -1,15 +0,0 @@
-# Linux ANT HAL library #
-
-This repository contains the source to build the ANT HAL library (libantradio.so) for use on Linux based platforms, including Android. Android makefiles are included to configure the build for a specific ANT part which is set in the board config.
-
-## Branches ##
-
-### master ###
-Versions that have been tested and are suitable for consumer devices.
-
-### features/_branch name_ ###
-The latest, untested, development versions of new features and fixes. These are made available for silicon vendors to verify code changes on new parts/boards not yet available to ANT Wireless engineers.
-
-### Third party submissions ###
-If you have code changes (new features, improvements or bug fixes), you should submit a pull request to master. These will be considered, and added to master if accepted, or a features branch if further verification is required.
-
diff --git a/app/ant_app.c b/app/ant_app.c
deleted file mode 100644
index b0090ba..0000000
--- a/app/ant_app.c
+++ /dev/null
@@ -1,326 +0,0 @@
-/*
- * ANT Stack testing appication
- *
- * Copyright 2009 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#define _GNU_SOURCE
-
-#include <stdio.h>
-#include <pthread.h>
-#include <string.h>
-#include <errno.h>
-#include <math.h>
-#include <signal.h>
-
-#include "ant_native.h"
-#include "ant_types.h"
-#include "ant_log.h"
-#undef LOG_TAG
-#define LOG_TAG "antradio_app"
-
-/* transient stage */
-typedef ANTStatus ant_status;
-
-void app_ANT_rx_callback(ANT_U8 ucLen, ANT_U8* pucData);
-void app_ANT_state_callback(ANTRadioEnabledStatus uiNewState);
-
-static int Ant_Create(void)
-{
- ANTStatus antStatus;
-
- //register_antsig_handlers();
-
- antStatus = ant_init();
- if (antStatus)
- {
- printf("failed to init ANT rx stacki\n");
- goto CLEANUP;
- }
-
- antStatus = set_ant_rx_callback(app_ANT_rx_callback);
- if (antStatus)
- {
- printf("failed to set ANT rx callback");
- goto CLEANUP;
- }
-
- antStatus = set_ant_state_callback(app_ANT_state_callback);
- if (antStatus)
- {
- printf("failed to set ANT rx callback");
- goto CLEANUP;
- }
- return antStatus;
-
-CLEANUP:
- return ANT_STATUS_FAILED;
-}
-
-void ProcessCommand(char cCmd)
-{
- ANT_U8 TxMessage[256];
- switch (cCmd)
- {
- case 'V':
- TxMessage[0] = 0x02; //Size
- TxMessage[1] = 0x4D; //MESG_REQUEST_ID
- TxMessage[2] = 0x00; //Ch0
- TxMessage[3] = 0x3E;
- ant_tx_message(4,TxMessage);
- break;
- case 'R':
- TxMessage[0] = 0x01; //Size
- TxMessage[1] = 0x4A; //MESG_RESET_ID
- TxMessage[2] = 0x00; //Ch0
- ant_tx_message(3,TxMessage);
- break;
- case 'K':
- printf("Hard Reset returned: %d\n", ant_radio_hard_reset());
- break;
-
- case 'H':
- //Normally we will not blindly send commands like this and actually check for responses before sending the next command, but this is just for a quick test.
- ProcessCommand('R'); //Reset chip
- ProcessCommand('A'); //Assign channel
- ProcessCommand('F'); //Set RF Freq
- ProcessCommand('I'); //Set Channel ID
- ProcessCommand('P'); //Set Channel Period
- ProcessCommand('O'); //Open Channel
- break;
-
- case 'A':
- TxMessage[0] = 0x03; //Size
- TxMessage[1] = 0x42; //MESG_ASSIGN_ID
- TxMessage[2] = 0x00; //Ch0
- TxMessage[3] = 0x00; //Assignment Params (Rx channel)
- TxMessage[4] = 0x01; //Network 1 (ANT+)
- ant_tx_message(5,TxMessage);
- break;
-
- case 'F':
- TxMessage[0] = 0x02; //Size
- TxMessage[1] = 0x45; //MESG_CHANNEL_RADIO_FREQ_ID
- TxMessage[2] = 0x00; //Ch0
- TxMessage[3] = 57; //2.457GHz
- ant_tx_message(4,TxMessage);
- break;
-
- case 'I':
- TxMessage[0] = 0x05; //Size
- TxMessage[1] = 0x51; //MESG_CHANNEL_ID_ID
- TxMessage[2] = 0x00; //Ch0
- TxMessage[3] = 0x00; //Wildcard Device Number
- TxMessage[4] = 0x00; //Wildcard Device Number
- TxMessage[5] = 0x78; //Set HRM Device Type
- TxMessage[6] = 0x00; //Wildcard Transmission Type
- ant_tx_message(7,TxMessage);
- break;
-
- case 'P':
- TxMessage[0] = 0x03; //Size
- TxMessage[1] = 0x43; //MESG_CHANNEL_MESG_PERIOD_ID
- TxMessage[2] = 0x00; //Ch0
- TxMessage[3] = 0x86; //
- TxMessage[4] = 0x1F; // HRM MESG Peroid 0x1F86 (8070)
- ant_tx_message(5,TxMessage);
- break;
-
- case 'O':
- TxMessage[0] = 0x01; //Size
- TxMessage[1] = 0x4B; //MESG_OPEN_CHANNEL__ID
- TxMessage[2] = 0x00; //Ch0
- ant_tx_message(3,TxMessage);
- break;
- case 'E':
- printf("Enable returned: %d\n", ant_enable_radio());
- break;
- case 'D':
- printf("Disable returned: %d\n", ant_disable_radio());
- break;
- case 'S':
- printf("State is: %d\n", ant_radio_enabled_status());
- break;
- case '1':
- TxMessage[0] = 0x0A; //Size
- TxMessage[1] = 0x01; //Enable
- TxMessage[2] = 0x00; //Code upload
- TxMessage[3] = 0x00;
- TxMessage[4] = 0x00;
- TxMessage[5] = 0x00;
- TxMessage[6] = 0x00;
- TxMessage[7] = 0x00;
- TxMessage[8] = 0x00;
- TxMessage[9] = 0x00;
- TxMessage[10] = 0x00;
- //ANT_CORE_Send_VS_Command(0xFDD0, 11, TxMessage);
- printf("Not Implemented\n");
- break;
-
- case '2':
- TxMessage[0] = 0x00; //Size
- //ANT_CORE_Send_VS_Command(0xFF22, 1, TxMessage);
- printf("Not Implemented\n");
- break;
-
-
- case 'X':
- printf("Exiting\n");
- break;
-
- default:
- printf("Invalid command: %#02x\n", cCmd);
- break;
- }
-}
-
-
-void app_ANT_rx_callback(ANT_U8 ucLen, ANT_U8* pucData)
-{
- ANT_U8 i;
-
- for(i=0; i <ucLen; i++)
- printf("[%02X]",pucData[i]);
- switch (pucData[1])
- {
- case 0x3E:
- printf(" ANT FW Version:%s\n", &(pucData[2]));
- break;
- case 0x6F:
- printf(" Chip Reset\n");
- break;
- case 0x40:
- if (pucData[3] != 0x01)
- {
- printf(" Response (Ch:%d Mesg:%02X) ", pucData[2], pucData[3]);
- if (pucData[4] == 0)
- printf("Success\n");
- else
- printf("Error - %02X\n", pucData[4]);
- }
- else
- {
- printf(" Event (Ch:%d) %02X\n", pucData[2], pucData[4]);
- }
- break;
- case 0x4E:
- if (pucData[2] == 0) //we are using channel 0 for HRM
- {
- // We are just assuming this is a HRM message and pulling the BPM out, refer to the ANT+ HRM profile documentation for proper/complete decoding instructions.
- printf(" BPM: %u\n", pucData[10]);
- }
- break;
-
- default:
-
- break;
- }
- return;
-}
-
-void app_ANT_state_callback(ANTRadioEnabledStatus uiNewState)
-{
- const char *pcState;
- switch (uiNewState) {
- case RADIO_STATUS_UNKNOWN:
- pcState = "UNKNOWN";
- break;
- case RADIO_STATUS_ENABLING:
- pcState = "ENABLING";
- break;
- case RADIO_STATUS_ENABLED:
- pcState = "ENABLED";
- break;
- case RADIO_STATUS_DISABLING:
- pcState = "DISABLING";
- break;
- case RADIO_STATUS_DISABLED:
- pcState = "DISABLED";
- break;
- case RADIO_STATUS_NOT_SUPPORTED:
- pcState = "NOT SUPPORTED";
- break;
- case RADIO_STATUS_SERVICE_NOT_INSTALLED:
- pcState = "SERVICE NOT INSTALLED";
- break;
- case RADIO_STATUS_SERVICE_NOT_CONNECTED:
- pcState = "SERVICE NOT CONNECTED";
- break;
- case RADIO_STATUS_RESETTING:
- pcState = "RESETTING";
- break;
- case RADIO_STATUS_RESET:
- pcState = "RESET";
- break;
- default:
- printf("State change to: %d is an undefined state\n", uiNewState);
- return;
- }
- printf("State change to: %s\n", pcState);
-}
-
-int main(void)
-{
- char buffer[1024];
- int ret = 0;
-
- if (Ant_Create())
- {
- printf("failed to init ANT\n");
- goto out;
- }
-
- printf("===ANT Test===\n");
- printf("Using libantradio version:\n");
- printf("%s\n", ant_get_lib_version());
- printf("\n");
- printf("Press V to get Version\n");
- printf("Press R to Reset\n");
- printf("Press K to hard reset\n");
- printf("Press H to setup an ANT+ HRM rx channel\n");
- printf("\n");
- printf("Press A to Assign channel\n");
- printf("Press F to set radio Frequency\n");
- printf("Press I to set channel Id\n");
- printf("Press P to set channel Peroid\n");
- printf("Press O to Open channel\n");
- printf("\n");
- printf("Press E to Enable ANT\n");
- printf("Press D to Disable ANT\n");
- printf("Press S to get State\n");
- printf("\n");
- printf("Press X to eXit\n");
-
- while (1)
- {
- memset(&buffer,0,sizeof(buffer));
- fgets(buffer, sizeof(buffer), stdin);
- ProcessCommand(buffer[0]);
- if (buffer[0] == 'X')
- goto done;
- }
-
-done:
- ProcessCommand('R');
- sleep(1);
- ProcessCommand('D');
- ant_deinit();
-
-
-out:
- return ret;
-}
-
diff --git a/app/ant_app.h b/app/ant_app.h
deleted file mode 100644
index 1806975..0000000
--- a/app/ant_app.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2009 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __ANT_APP_H
-#define __ANT_APP_H
-
-
-
-#endif
diff --git a/example-server/Android.bp b/example-server/Android.bp
new file mode 100644
index 0000000..7dc1614
--- /dev/null
+++ b/example-server/Android.bp
@@ -0,0 +1,23 @@
+/*
+ * The example server is a standalone daemon, however
+ * vendor implementations may combine with other hal server daemons.
+ */
+cc_binary {
+ name: "com.dsi.ant@1.0-example",
+ relative_install_path: "hw",
+ proprietary: true,
+ srcs: [
+ "src/Ant.cpp",
+ "src/Server.cpp"
+ ],
+ shared_libs: [
+ "libhidlbase",
+ "libhidltransport",
+ "libutils",
+ "liblog",
+ "com.dsi.ant@1.0",
+ ],
+ init_rc: [
+ "com.dsi.ant@1.0-example.rc",
+ ],
+}
diff --git a/example-server/README.txt b/example-server/README.txt
new file mode 100644
index 0000000..246b9f9
--- /dev/null
+++ b/example-server/README.txt
@@ -0,0 +1,11 @@
+This folder contains an example implementation of a HAL client for ant.
+
+This example expects to be able to use a unix domain socket located at
+/dev/socket/ant. The sepolicy directory shows example policy to use
+as a starting point for the vendor policy, and vintf contains a fragment
+that should be added to the vendor manifest.xml in order to advertise
+that the service is provided.
+
+Note that the example policy does not currently contain the pieces that
+are needed to actually open and use the socket.
+
diff --git a/example-server/com.dsi.ant@1.0-example.rc b/example-server/com.dsi.ant@1.0-example.rc
new file mode 100644
index 0000000..8595b8c
--- /dev/null
+++ b/example-server/com.dsi.ant@1.0-example.rc
@@ -0,0 +1,4 @@
+service ant_hal_service /vendor/bin/hw/com.dsi.ant@1.0-example
+ class hal
+ user system
+ group system
diff --git a/example-server/sepolicy/ant_example_server.te b/example-server/sepolicy/ant_example_server.te
new file mode 100644
index 0000000..31fa595
--- /dev/null
+++ b/example-server/sepolicy/ant_example_server.te
@@ -0,0 +1,10 @@
+type ant_hidl_example, domain;
+type ant_hidl_example_exec, exec_type, vendor_file_type, file_type;
+
+init_daemon_domain(ant_hidl_example);
+hal_server_domain(ant_hidl_example, hal_dsi_ant);
+
+# Any other permissions needed by the server go here.
+# For example, to allow opening the proper socket/char devices
+# needed to communicate with the hardware
+
diff --git a/example-server/sepolicy/file_contexts b/example-server/sepolicy/file_contexts
new file mode 100644
index 0000000..0547ba0
--- /dev/null
+++ b/example-server/sepolicy/file_contexts
@@ -0,0 +1,2 @@
+/vendor/bin/hw/com\.dsi\.ant\@1\.0-example u:object_r:ant_hidl_example_exec:s0
+
diff --git a/example-server/src/Ant.cpp b/example-server/src/Ant.cpp
new file mode 100644
index 0000000..2c25e97
--- /dev/null
+++ b/example-server/src/Ant.cpp
@@ -0,0 +1,465 @@
+/*
+ * ANT Android Host Stack
+ *
+ * Copyright 2018 Dynastream Innovations
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "Ant Hidl Example"
+
+#include <cassert>
+#include <cstring>
+
+#include <limits>
+#include <sstream>
+#include <stdexcept>
+
+#include <sys/eventfd.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include <poll.h>
+
+#include "log/log.h"
+
+#include "Ant.h"
+
+// NOTE: Code here holds mutex locks while making callbacks. This is fine in this case since
+// all of the callback methods are marked as oneway in the hal and therefore are non-blocking.
+
+namespace com {
+namespace dsi {
+namespace ant {
+namespace V1_0 {
+namespace example {
+
+// Convenience typedef, since we only use one type of mutex.
+typedef std::lock_guard<std::mutex> lock;
+
+// Header for framing ANT messages to go to the chip.
+struct MsgHeader {
+ uint8_t channel_id;
+ uint8_t payload_len;
+
+ static const size_t max_payload = std::numeric_limits<uint8_t>::max();
+};
+
+// Error classes. This implementation uses the upper 16 bits of a status code
+// to indicate a class, and the lower 16 bits as an associated errno value.
+// It assumes that all errno values fit, which is currently the case in the
+// errno.h header used by android.
+// see translateStatus to understand exactly what each error code means.
+enum errors : uint16_t {
+ GENERIC_ERR,
+ SOCKET_ERR,
+ CONNECT_ERR,
+ EFD_ERR,
+ NOFD_ERR,
+ LARGEMSG_ERR,
+};
+
+// Convenience to not need the fully scoped name every time.
+static const Status STATUS_OK = (Status)CommonStatusCodes::OK;
+
+// Example implementation uses an UNIX domain socket, which allows for
+// adb reverse-forwarding to be used.
+static const sockaddr_un socket_addr = {
+ AF_UNIX,
+ "/dev/socket/ant",
+ };
+
+static const int poll_timeout_ms = 1000 * 5;
+
+// Implementation properties are constant.
+static const ImplProps props = {
+ "ant.hidl.example.1.0",
+ OptionFlags::USE_KEEPALIVE | OptionFlags::USE_ANT_FLOW_CONTROL,
+};
+
+// Bit manipulation for status codes.
+
+static Status makeStatus(uint32_t cls, uint32_t err_code)
+{ return ((cls << 16)|(err_code & 0xffff)); }
+
+static uint16_t getErrClass(Status status)
+{ return (uint16_t)((status >> 16) & 0xffff); }
+
+static uint16_t getErrCode(Status status)
+{ return (uint16_t)(status & 0xffff); }
+
+// Convenience stuff for file descriptors.
+static bool isValidFd(int fd) { return fd >= 0; }
+
+static int invalid_fd = -1;
+
+class MessageReader {
+public:
+ MessageReader(int fd) : fd(fd), read_idx(0) {}
+ int checkForMessages(const sp<IAntCallbacks> &callbacks);
+
+private:
+ int fd;
+ uint8_t read_buf[sizeof(MsgHeader) + MsgHeader::max_payload];
+ size_t read_idx;
+};
+
+int MessageReader::checkForMessages(const sp<IAntCallbacks> &callbacks) {
+
+ // First consume any new data that is available.
+ ssize_t read_result = read(
+ fd,
+ &read_buf[read_idx],
+ sizeof(read_buf) - read_idx);
+
+ if (read_result < 0) {
+ switch(errno) {
+ case EAGAIN:
+ case EINTR:
+ // These errors are okay, act like no data read.
+ read_result = 0;
+ break;
+ default:
+ return errno;
+ };
+ }
+
+ read_idx += read_result;
+
+ // Now dispatch all read messages.
+
+ // Alias the front of the buffer as a message header.
+ MsgHeader *header = (MsgHeader*)read_buf;
+
+ size_t full_size = header->payload_len + sizeof(MsgHeader);
+ while (read_idx >= sizeof(MsgHeader) && read_idx >= full_size) {
+
+ assert((header->channel_id == Ant::command_channel_id) ||
+ (header->channel_id == Ant::data_channel_id));
+
+ if (callbacks != NULL) {
+ hidl_vec<uint8_t> msg;
+ msg.setToExternal(read_buf + sizeof(MsgHeader), header->payload_len);
+ callbacks->onMessageReceived(msg);
+ }
+
+ if (read_idx > full_size) {
+ // There's (part of) another message, move it to the front of the buffer.
+ std::memmove(read_buf, read_buf + full_size, read_idx - full_size);
+ }
+ read_idx -= full_size;
+ full_size = header->payload_len + sizeof(MsgHeader);
+ }
+
+ return STATUS_OK;
+}
+
+Ant::Ant():
+ transport_fd(invalid_fd),
+ shutdown_fd(invalid_fd),
+ stop_polling(true)
+ {}
+
+// Methods from IAnt follow.
+Return<void> Ant::getProperties(getProperties_cb _hidl_cb) {
+ _hidl_cb(props);
+ return Void();
+}
+
+Return<void> Ant::setCallbacks(const sp<IAntCallbacks>& callbacks) {
+ // Keep a reference to the old value around until we are outside of the
+ // locked scope. See RefBase.h for why this is needed.
+ sp<IAntCallbacks> old;
+ {
+ lock l(state_mtx);
+ old = this->callbacks;
+ this->callbacks = callbacks;
+ }
+
+ return Void();
+}
+
+Return<void> Ant::translateStatus(Status status, translateStatus_cb _hidl_cb) {
+ std::ostringstream err;
+ uint16_t err_class = getErrClass(status);
+ uint16_t err_code = getErrCode(status);
+
+ switch(err_class) {
+ case GENERIC_ERR:
+ break;
+ case SOCKET_ERR:
+ err << "Socket creation failed.";
+ break;
+ case CONNECT_ERR:
+ err << "Socket connect failed.";
+ break;
+ case EFD_ERR:
+ err << "Event fd not created.";
+ break;
+ case NOFD_ERR:
+ err << "Transport not open.";
+ break;
+ case LARGEMSG_ERR:
+ err << "Provided message too big.";
+ break;
+ default:
+ err << "Unknown Error Class (" << err_class << ").";
+ break;
+ };
+
+ if (err_code) {
+ // Add a space between class and error string, only if a class string was
+ // added (ie. length > 0)
+ if (err.tellp() > 0) {
+ err << " ";
+ }
+ err << strerror(err_code);
+ }
+
+ _hidl_cb(err.str());
+ return Void();
+}
+
+Return<Status> Ant::enable() {
+ // Early returns are used to bail out here, this is okay in this case though
+ // since disable will always be used to recover, and we deal with any inconsistent state there.
+
+ ALOGV("Enabling");
+
+ lock l(state_mtx);
+
+ stop_polling = false;
+
+ // Open the local socket that is adb-forwarded somewhere. Actual implementations
+ // would maybe open a character device here.
+ // The socket is non-blocking since the poll loop waits for data anyways.
+ transport_fd = socket(AF_UNIX, SOCK_STREAM|SOCK_NONBLOCK, 0);
+ if (!isValidFd(transport_fd)) {
+ return makeStatus(SOCKET_ERR, errno);
+ }
+
+ if (connect(transport_fd, (const sockaddr*)&socket_addr, sizeof(socket_addr)) < 0) {
+ return makeStatus(CONNECT_ERR, errno);
+ }
+
+ // Setup the shutdown handle, which is an event-fd that can be used to interrupt
+ // the poll thread when it is stuck in a poll().
+ shutdown_fd = eventfd(0, EFD_NONBLOCK);
+ if (!isValidFd(shutdown_fd)) {
+ return makeStatus(EFD_ERR, errno);
+ }
+
+ // If all state was setup succesfully then the poll thread can be started.
+ poll_thread = std::thread(&Ant::pollThreadEntry, this);
+
+ return STATUS_OK;
+}
+
+Return<Status> Ant::disable() {
+ ALOGV("Disabling");
+
+ // Used to capture the value of the poll thread.
+ std::thread old_poll;
+
+ {
+ // Use a scope block, since we need to be unlocked while joining the thread.
+ lock l(state_mtx);
+
+ std::swap(old_poll, poll_thread);
+ if (isValidFd(shutdown_fd)) {
+ uint64_t shutdown_evt = 1;
+ if (write(shutdown_fd, &shutdown_evt, sizeof(shutdown_evt)) < 0) {
+ ALOGW("Shutdown sending signal failed. %s", strerror(errno));
+ }
+ }
+
+ stop_polling = true;
+ }
+
+ if (old_poll.get_id() != std::thread::id()) {
+ // NOTE: if it's possible for the poll thread to get stuck it might
+ // be better to do a timed wait on a future<void> set by the threads exit.
+ // If a timeout occurs the thread should be detached instead of joined.
+ old_poll.join();
+ }
+
+ // At this point the poll thread should be stopped, meaning it's safe to start
+ // cleaning up files. The state lock is still held to make sure we don't close
+ // the handles on any message writes in progress.
+
+ lock l2(state_mtx);
+
+ if (isValidFd(shutdown_fd)) {
+ if (close(shutdown_fd) < 0) {
+ ALOGW("Could not cleanly close event_fd. %s", strerror(errno));
+ }
+ }
+ shutdown_fd = invalid_fd;
+
+ if (isValidFd(transport_fd)) {
+ if (close(transport_fd) < 0) {
+ ALOGW("Could not cleanly close transport_fd. %s", strerror(errno));
+ }
+ }
+ transport_fd = invalid_fd;
+
+ return STATUS_OK;
+}
+
+void Ant::pollThreadEntry() {
+ bool should_quit = false;
+ MessageReader reader(transport_fd);
+ // This remains empty as long as no error occured.
+ std::string err_msg;
+
+ struct poll_fds_t {
+ pollfd transport;
+ pollfd shutdown;
+ } poll_fds;
+
+ // Static setup for poll loop.
+ // The only non-error event that matters is the data ready event.
+ poll_fds.transport.fd = transport_fd;
+ poll_fds.transport.events = POLLIN;
+ poll_fds.shutdown.fd = shutdown_fd;
+ poll_fds.shutdown.events = POLLIN;
+
+ class poll_err : public std::runtime_error {};
+
+ // Error cases just bail straight out of the thread
+ while(!should_quit) {
+ // Clear out previous events.
+ poll_fds.transport.revents = 0;
+ poll_fds.shutdown.revents = 0;
+
+ int poll_result = poll((pollfd*)&poll_fds, sizeof(poll_fds)/sizeof(pollfd), poll_timeout_ms);
+
+ // Now that poll is done grab the state lock, the rest should be quick, since all
+ // operations are non-blocking.
+ lock l(state_mtx);
+
+ should_quit = stop_polling;
+
+ // Only care to differentiate error case, and ignore EINTR errors.
+ if (poll_result < 0 && errno != EINTR) {
+ err_msg = std::string("Poll call failed. ") + strerror(errno);
+ break;
+ }
+
+ if (poll_fds.transport.revents) {
+ if (poll_fds.transport.revents != POLLIN) {
+ std::ostringstream err_bld("Poll error flags on transport file: ");
+ err_bld << (int)poll_fds.transport.revents;
+ err_msg = err_bld.str();
+ break;
+ }
+
+ int read_result = reader.checkForMessages(callbacks);
+ if (read_result != STATUS_OK) {
+ err_msg = std::string("Could not read available data") + strerror(read_result);
+ break;
+ }
+ }
+
+ if (poll_fds.shutdown.revents) {
+ if (poll_fds.shutdown.revents != POLLIN) {
+ std::ostringstream err_bld("Poll error flags on shutdown file: ");
+ err_bld << (int)poll_fds.shutdown.revents;
+ err_msg = err_bld.str();
+ break;
+ }
+
+ // No need to read, the eventfd is only signaled when shutting down.
+ should_quit = true;
+ }
+ }
+
+ if (!err_msg.empty()) {
+ lock l(state_mtx);
+ if (callbacks != NULL) {
+ callbacks->onTransportDown(err_msg);
+ }
+ }
+
+ return;
+}
+
+Status Ant::writeMsg(const hidl_vec<uint8_t> &msg, uint8_t channel_id) {
+ if (msg.size() > MsgHeader::max_payload) {
+ return makeStatus(LARGEMSG_ERR, 0);
+ }
+
+ // Lock is held for full function to make sure the fd isn't changed on us.
+ // This should never take long, higher level flow control should ensure
+ // we never block waiting for space in write buffers.
+ lock l(state_mtx);
+ if (!isValidFd(transport_fd)) {
+ return makeStatus(NOFD_ERR, 0);
+ }
+
+ Status retval = STATUS_OK;
+
+ MsgHeader header = {
+ channel_id,
+ (uint8_t)msg.size(),
+ };
+
+ iovec vecs[] = {
+ { (uint8_t*)&header, sizeof(header) },
+ // Cast away the constness of the data.
+ // This is okay because we are only sourcing the data for a write,
+ // but is required because the struct in the writev api is non-const
+ // in order to be shared with readv calls.
+ { const_cast<uint8_t*>(msg.data()), msg.size() },
+ };
+ size_t num_vecs = sizeof(vecs)/sizeof(vecs[0]);
+
+ // Continue until the last chunk has been fully written.
+ while(vecs[num_vecs - 1].iov_len > 0) {
+ ssize_t written = writev(transport_fd, vecs, num_vecs);
+
+ if (written < 0) {
+ if (errno == EINTR) {
+ // EINTR is okay, it means no data was written though.
+ written = 0;
+ } else {
+ retval = makeStatus(GENERIC_ERR, errno);
+ // Abort writing the remainder.
+ break;
+ }
+ }
+
+ // Adjust write to resume with unwritten portion.
+ for (size_t i = 0; i < num_vecs; i++) {
+ if ((size_t)written <= vecs[i].iov_len) {
+ // Chunk was partially written, pointer adjustment needed.
+ vecs[i].iov_len -= written;
+ vecs[i].iov_base = ((uint8_t*)vecs[i].iov_base) + written;
+ // Remaining chunks are unchanged.
+ break;
+ }
+
+ // Chunk fully written, move onto next.
+ vecs[i].iov_len = 0;
+ written -= vecs[i].iov_len;
+ }
+ }
+
+ return retval;
+}
+
+} // namespace example
+} // namespace V1_0
+} // namespace ant
+} // namespace dsi
+} // namespace com
diff --git a/example-server/src/Ant.h b/example-server/src/Ant.h
new file mode 100644
index 0000000..5a36c12
--- /dev/null
+++ b/example-server/src/Ant.h
@@ -0,0 +1,89 @@
+/*
+ * ANT Android Host Stack
+ *
+ * Copyright 2018 Dynastream Innovations
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef COM_DSI_ANT_V1_0_ANT_H
+#define COM_DSI_ANT_V1_0_ANT_H
+
+#include <mutex>
+#include <thread>
+
+#include <com/dsi/ant/1.0/IAnt.h>
+#include <hidl/Status.h>
+
+namespace com {
+namespace dsi {
+namespace ant {
+namespace V1_0 {
+namespace example {
+
+using ::android::hardware::hidl_array;
+using ::android::hardware::hidl_memory;
+using ::android::hardware::hidl_string;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::sp;
+
+struct Ant : public IAnt {
+
+public:
+
+ // These need to be declared here because they are used in the inline versions
+ // of sendData/CommandMessage.
+ static const uint8_t command_channel_id = 0x0C;
+ static const uint8_t data_channel_id = 0x0E;
+
+ // Methods from IAnt follow.
+ Return<void> getProperties(getProperties_cb _hidl_cb) override;
+ Return<void> setCallbacks(const sp<IAntCallbacks>& callbacks) override;
+ Return<void> translateStatus(Status status, translateStatus_cb _hidl_cb) override;
+ Return<Status> enable() override;
+ Return<Status> disable() override;
+
+ Return<Status> sendDataMessage(const hidl_vec<uint8_t>& msg) override
+ { return writeMsg(msg, data_channel_id); }
+ Return<Status> sendCommandMessage(const hidl_vec<uint8_t>& msg) override
+ { return writeMsg(msg, command_channel_id); }
+
+ Ant();
+
+private:
+
+ sp<IAntCallbacks> callbacks;
+ // File handle used for communicating with the ant chip.
+ int transport_fd;
+ // File handle used to signal the poll thread when shutting down.
+ int shutdown_fd;
+ std::thread poll_thread;
+ // This is set to indicate that the poll thread should exit.
+ bool stop_polling;
+ // Coarse mutex for all internal state.
+ std::mutex state_mtx;
+
+ void pollThreadEntry();
+ Status writeMsg(const hidl_vec<uint8_t> &msg, uint8_t channel_id);
+};
+
+
+} // namespace example
+} // namespace V1_0
+} // namespace ant
+} // namespace dsi
+} // namespace com
+
+#endif // COM_DSI_ANT_V1_0_ANT_H
diff --git a/example-server/src/Server.cpp b/example-server/src/Server.cpp
new file mode 100644
index 0000000..9ea376b
--- /dev/null
+++ b/example-server/src/Server.cpp
@@ -0,0 +1,50 @@
+/*
+ * ANT Android Host Stack
+ *
+ * Copyright 2018 Dynastream Innovations
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "Ant Hidl Example"
+
+#include "Ant.h"
+
+#include "log/log.h"
+#include <hidl/HidlTransportSupport.h>
+
+using com::dsi::ant::V1_0::example::Ant;
+using namespace android;
+using namespace android::hardware;
+
+/* Handle 1 data + 1 command + power control. */
+static const uint32_t THREAD_POOL_SIZE = 3;
+
+int main(void) {
+ /*
+ * This is fairly standard daemon code based on
+ * defaultPassthroughServiceImplementation()
+ */
+ ALOGI("Starting example ANT HIDL daemon");
+ configureRpcThreadpool(THREAD_POOL_SIZE, true);
+
+ Ant ant;
+ status_t status = ant.registerAsService();
+ if (status != OK) {
+ ALOGE("Unable to register service: %d", status);
+ return -1;
+ }
+
+ joinRpcThreadpool();
+}
+
diff --git a/example-server/vintf/manifest.xml b/example-server/vintf/manifest.xml
new file mode 100644
index 0000000..12e07cf
--- /dev/null
+++ b/example-server/vintf/manifest.xml
@@ -0,0 +1,10 @@
+<hal format="hidl">
+ <name>com.dsi.ant</name>
+ <transport>hwbinder</transport>
+ <version>1.0</version>
+ <interface>
+ <name>IAnt</name>
+ <instance>default</instance>
+ </interface>
+</hal>
+
diff --git a/interfaces/Android.bp b/interfaces/Android.bp
new file mode 100644
index 0000000..7aef46b
--- /dev/null
+++ b/interfaces/Android.bp
@@ -0,0 +1,3 @@
+subdirs = [
+ "*"
+]
diff --git a/interfaces/ant/1.0/Android.bp b/interfaces/ant/1.0/Android.bp
new file mode 100644
index 0000000..e5ea3d5
--- /dev/null
+++ b/interfaces/ant/1.0/Android.bp
@@ -0,0 +1,96 @@
+// This file is autogenerated by hidl-gen. Do not edit manually.
+
+filegroup {
+ name: "com.dsi.ant@1.0_hal",
+ srcs: [
+ "types.hal",
+ "IAnt.hal",
+ "IAntCallbacks.hal",
+ ],
+}
+
+genrule {
+ name: "com.dsi.ant@1.0_genc++",
+ tools: ["hidl-gen"],
+ cmd: "$(location hidl-gen) -o $(genDir) -Lc++-sources -randroid.hidl:system/libhidl/transport -rcom.dsi:external/ant-wireless/hidl/interfaces com.dsi.ant@1.0",
+ srcs: [
+ ":com.dsi.ant@1.0_hal",
+ ],
+ out: [
+ "com/dsi/ant/1.0/types.cpp",
+ "com/dsi/ant/1.0/AntAll.cpp",
+ "com/dsi/ant/1.0/AntCallbacksAll.cpp",
+ ],
+}
+
+genrule {
+ name: "com.dsi.ant@1.0_genc++_headers",
+ tools: ["hidl-gen"],
+ cmd: "$(location hidl-gen) -o $(genDir) -Lc++-headers -randroid.hidl:system/libhidl/transport -rcom.dsi:external/ant-wireless/hidl/interfaces com.dsi.ant@1.0",
+ srcs: [
+ ":com.dsi.ant@1.0_hal",
+ ],
+ out: [
+ "com/dsi/ant/1.0/types.h",
+ "com/dsi/ant/1.0/hwtypes.h",
+ "com/dsi/ant/1.0/IAnt.h",
+ "com/dsi/ant/1.0/IHwAnt.h",
+ "com/dsi/ant/1.0/BnHwAnt.h",
+ "com/dsi/ant/1.0/BpHwAnt.h",
+ "com/dsi/ant/1.0/BsAnt.h",
+ "com/dsi/ant/1.0/IAntCallbacks.h",
+ "com/dsi/ant/1.0/IHwAntCallbacks.h",
+ "com/dsi/ant/1.0/BnHwAntCallbacks.h",
+ "com/dsi/ant/1.0/BpHwAntCallbacks.h",
+ "com/dsi/ant/1.0/BsAntCallbacks.h",
+ ],
+}
+
+cc_library {
+ name: "com.dsi.ant@1.0",
+ defaults: ["hidl-module-defaults"],
+ generated_sources: ["com.dsi.ant@1.0_genc++"],
+ generated_headers: ["com.dsi.ant@1.0_genc++_headers"],
+ export_generated_headers: ["com.dsi.ant@1.0_genc++_headers"],
+ vendor_available: true,
+ vndk: {
+ enabled: true,
+ },
+ shared_libs: [
+ "libhidlbase",
+ "libhidltransport",
+ "libhwbinder",
+ "liblog",
+ "libutils",
+ "libcutils",
+ ],
+ export_shared_lib_headers: [
+ "libhidlbase",
+ "libhidltransport",
+ "libhwbinder",
+ "libutils",
+ ],
+}
+
+cc_library {
+ name: "com.dsi.ant@1.0_vendor",
+ defaults: ["hidl-module-defaults"],
+ generated_sources: ["com.dsi.ant@1.0_genc++"],
+ generated_headers: ["com.dsi.ant@1.0_genc++_headers"],
+ export_generated_headers: ["com.dsi.ant@1.0_genc++_headers"],
+ vendor: true,
+ shared_libs: [
+ "libhidlbase",
+ "libhidltransport",
+ "libhwbinder",
+ "liblog",
+ "libutils",
+ "libcutils",
+ ],
+ export_shared_lib_headers: [
+ "libhidlbase",
+ "libhidltransport",
+ "libhwbinder",
+ "libutils",
+ ],
+}
diff --git a/interfaces/ant/1.0/Android.mk b/interfaces/ant/1.0/Android.mk
new file mode 100644
index 0000000..bf21f0e
--- /dev/null
+++ b/interfaces/ant/1.0/Android.mk
@@ -0,0 +1,198 @@
+# This file is autogenerated by hidl-gen. Do not edit manually.
+
+LOCAL_PATH := $(call my-dir)
+
+################################################################################
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := com.dsi.ant-V1.0-java
+LOCAL_MODULE_CLASS := JAVA_LIBRARIES
+
+intermediates := $(call local-generated-sources-dir, COMMON)
+
+HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
+
+LOCAL_JAVA_LIBRARIES := \
+ android.hidl.base-V1.0-java \
+
+
+#
+# Build types.hal (ImplProps)
+#
+GEN := $(intermediates)/com/dsi/ant/V1_0/ImplProps.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+ $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+ -Ljava \
+ -randroid.hidl:system/libhidl/transport \
+ -rcom.dsi:external/ant-wireless/hidl/interfaces \
+ com.dsi.ant@1.0::types.ImplProps
+
+$(GEN): $(LOCAL_PATH)/types.hal
+ $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+#
+# Build types.hal (OptionFlags)
+#
+GEN := $(intermediates)/com/dsi/ant/V1_0/OptionFlags.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+ $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+ -Ljava \
+ -randroid.hidl:system/libhidl/transport \
+ -rcom.dsi:external/ant-wireless/hidl/interfaces \
+ com.dsi.ant@1.0::types.OptionFlags
+
+$(GEN): $(LOCAL_PATH)/types.hal
+ $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+#
+# Build IAnt.hal
+#
+GEN := $(intermediates)/com/dsi/ant/V1_0/IAnt.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/IAnt.hal
+$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/IAntCallbacks.hal
+$(GEN): $(LOCAL_PATH)/IAntCallbacks.hal
+$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/types.hal
+$(GEN): $(LOCAL_PATH)/types.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+ $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+ -Ljava \
+ -randroid.hidl:system/libhidl/transport \
+ -rcom.dsi:external/ant-wireless/hidl/interfaces \
+ com.dsi.ant@1.0::IAnt
+
+$(GEN): $(LOCAL_PATH)/IAnt.hal
+ $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+#
+# Build IAntCallbacks.hal
+#
+GEN := $(intermediates)/com/dsi/ant/V1_0/IAntCallbacks.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/IAntCallbacks.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+ $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+ -Ljava \
+ -randroid.hidl:system/libhidl/transport \
+ -rcom.dsi:external/ant-wireless/hidl/interfaces \
+ com.dsi.ant@1.0::IAntCallbacks
+
+$(GEN): $(LOCAL_PATH)/IAntCallbacks.hal
+ $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+include $(BUILD_JAVA_LIBRARY)
+
+
+################################################################################
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := com.dsi.ant-V1.0-java-static
+LOCAL_MODULE_CLASS := JAVA_LIBRARIES
+
+intermediates := $(call local-generated-sources-dir, COMMON)
+
+HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
+
+LOCAL_STATIC_JAVA_LIBRARIES := \
+ android.hidl.base-V1.0-java-static \
+
+
+#
+# Build types.hal (ImplProps)
+#
+GEN := $(intermediates)/com/dsi/ant/V1_0/ImplProps.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+ $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+ -Ljava \
+ -randroid.hidl:system/libhidl/transport \
+ -rcom.dsi:external/ant-wireless/hidl/interfaces \
+ com.dsi.ant@1.0::types.ImplProps
+
+$(GEN): $(LOCAL_PATH)/types.hal
+ $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+#
+# Build types.hal (OptionFlags)
+#
+GEN := $(intermediates)/com/dsi/ant/V1_0/OptionFlags.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+ $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+ -Ljava \
+ -randroid.hidl:system/libhidl/transport \
+ -rcom.dsi:external/ant-wireless/hidl/interfaces \
+ com.dsi.ant@1.0::types.OptionFlags
+
+$(GEN): $(LOCAL_PATH)/types.hal
+ $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+#
+# Build IAnt.hal
+#
+GEN := $(intermediates)/com/dsi/ant/V1_0/IAnt.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/IAnt.hal
+$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/IAntCallbacks.hal
+$(GEN): $(LOCAL_PATH)/IAntCallbacks.hal
+$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/types.hal
+$(GEN): $(LOCAL_PATH)/types.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+ $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+ -Ljava \
+ -randroid.hidl:system/libhidl/transport \
+ -rcom.dsi:external/ant-wireless/hidl/interfaces \
+ com.dsi.ant@1.0::IAnt
+
+$(GEN): $(LOCAL_PATH)/IAnt.hal
+ $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+#
+# Build IAntCallbacks.hal
+#
+GEN := $(intermediates)/com/dsi/ant/V1_0/IAntCallbacks.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/IAntCallbacks.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+ $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+ -Ljava \
+ -randroid.hidl:system/libhidl/transport \
+ -rcom.dsi:external/ant-wireless/hidl/interfaces \
+ com.dsi.ant@1.0::IAntCallbacks
+
+$(GEN): $(LOCAL_PATH)/IAntCallbacks.hal
+ $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+include $(BUILD_STATIC_JAVA_LIBRARY)
+
+
+
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/interfaces/ant/1.0/IAnt.hal b/interfaces/ant/1.0/IAnt.hal
new file mode 100644
index 0000000..f837d23
--- /dev/null
+++ b/interfaces/ant/1.0/IAnt.hal
@@ -0,0 +1,105 @@
+/*
+ * ANT Android Host Stack
+ *
+ * Copyright 2018 Dynastream Innovations
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.dsi.ant@1.0;
+
+import IAntCallbacks;
+
+interface IAnt {
+
+ /**** Administrative Methods ****/
+
+ /** Retrieve the static properties of the HAL implementation. */
+ getProperties() generates (ImplProps properties);
+
+ /**
+ * Set up callbacks from HAL implementation to ANTHALService.
+ * The callbacks will be set before any of the other methods below are called.
+ * NULL may also be passed here during shutdown to unregister the callbacks.
+ */
+ setCallbacks(IAntCallbacks callbacks);
+
+ /**
+ * Translate a non-0 status code to a string value. This is used by the ANTHALService
+ * to log operational errors to logcat for debugging purposes.
+ */
+ translateStatus(Status status) generates (string translation);
+
+
+
+ /**** Interface state/power control ****/
+
+ /* General Notes
+ *
+ * The ANTHALService will guarantee that calls to enable and disable are mutually exclusive.
+ * If the ANTHALService detects an error condition it will attempt recovery by disabling
+ * and then re-enabling the interface. This includes cases where enable failed,
+ * so it is strongly suggested that disable is able to recover from an inconsistent state.
+ *
+ * If an asynchronous failure condition is detected then the HAL implementation should
+ * report it through the registered callbacks.
+ */
+
+ /**
+ * Enable the ANT stack and transport.
+ *
+ * This will acquire any needed resources and power up the appropriate subsystems.
+ * The implementation must block until this is complete.
+ */
+ enable() generates (Status status);
+
+ /**
+ * Disable the ANT stack and transport.
+ *
+ * This is called when the ANT protocol is no longer in used. The implementation should power
+ * down any subsystems and release any acquired resources. The implementation must block until
+ * this is complete.
+ */
+ disable() generates (Status status);
+
+
+
+ /**** Message Transport Methods ****/
+
+ /* General Notes
+ *
+ * The ANTHALService will guarantee that these methods will not be called while an enable or
+ * disable is in progress.
+ *
+ * The ANT stack uses two separate channels for message transactions, one for data and one for
+ * commands. For a single channel a new send call will not be made until the previous returns.
+ * However, the HAL implementation must be able to handle a message being sent concurrently on
+ * both channels.
+ *
+ * Any non 0 status returned by these will be treated as a fatal error and cause the host stack
+ * to attempt full recovery of the chip.
+ */
+
+ /**
+ * Send a message on the data channel. The provided message will be raw payload, any required framing must be
+ * added by the HAL implementation.
+ */
+ sendDataMessage(vec<uint8_t> msg) generates (Status status);
+
+ /**
+ * Send a message on the command channel. The provided message will be raw payload, any required framing must be
+ * added by the HAL implementation.
+ */
+ sendCommandMessage(vec<uint8_t> msg) generates (Status status);
+};
+
diff --git a/interfaces/ant/1.0/IAntCallbacks.hal b/interfaces/ant/1.0/IAntCallbacks.hal
new file mode 100644
index 0000000..ffb3919
--- /dev/null
+++ b/interfaces/ant/1.0/IAntCallbacks.hal
@@ -0,0 +1,38 @@
+/*
+ * ANT Android Host Stack
+ *
+ * Copyright 2018 Dynastream Innovations
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.dsi.ant@1.0;
+
+/**
+ * Callbacks to allow the HAL implementation to notify the ANTHALService of events.
+ */
+interface IAntCallbacks {
+
+ /**
+ * Indicate that a message was received on either the data or command channel.
+ */
+ oneway onMessageReceived(vec<uint8_t> data);
+
+ /**
+ * Indicate that a failure condition was detected. The ANTHALService will attempt
+ * a recovery process. The cause parameter is an optional string describing the
+ * failure condition.
+ */
+ oneway onTransportDown(string cause);
+};
+
diff --git a/interfaces/ant/1.0/types.hal b/interfaces/ant/1.0/types.hal
new file mode 100644
index 0000000..8f23078
--- /dev/null
+++ b/interfaces/ant/1.0/types.hal
@@ -0,0 +1,63 @@
+/*
+ * ANT Android Host Stack
+ *
+ * Copyright 2018 Dynastream Innovations
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.dsi.ant@1.0;
+
+/**
+ * Status codes returned from most interface functions. The only requirement is that 0 indicates success.
+ * Otherwise all values are specific to the HAL implementation.
+ */
+typedef int32_t Status;
+
+/**
+ * Status code 0 is used to indicate success. All other status codes are vendor-defined and
+ * can be converted to a string description using translateStatus in IAnt.
+ */
+enum CommonStatusCodes : Status {
+ OK = 0,
+};
+
+/**
+ * Various flags that can be used by the server to modify the behavior of the ANTHALService.
+ * These should be static for a given implementation.
+ */
+enum OptionFlags : uint32_t {
+ /**
+ * This flag indicates that keep alive should be used. When the ANT transport is idle
+ * for an extended period of time the ANTHALService will use a ping message to verify
+ * that the stack is still responding.
+ */
+ USE_KEEPALIVE = 1 << 0,
+ /**
+ * Whether the data channel flow control is encapsulated in ANT message. The value to
+ * set for this depends on the ANT protocol stack implementation being used.
+ */
+ USE_ANT_FLOW_CONTROL = 1 << 1,
+};
+
+/**
+ * A set of properties describing the vendor implementation of the HAL. These will be requested
+ * by the ANTHALService on startup.
+ */
+struct ImplProps {
+ /** A version string describing the implementation. Should be unique for every public release */
+ string version;
+ /** Flags to modify ANTHALService behavior */
+ bitfield<OptionFlags> options;
+};
+
diff --git a/interfaces/ant/Android.bp b/interfaces/ant/Android.bp
new file mode 100644
index 0000000..bbb3e4b
--- /dev/null
+++ b/interfaces/ant/Android.bp
@@ -0,0 +1,4 @@
+// This is an autogenerated file, do not edit.
+subdirs = [
+ "1.0",
+]
diff --git a/interfaces/current.txt b/interfaces/current.txt
new file mode 100644
index 0000000..d8e65dc
--- /dev/null
+++ b/interfaces/current.txt
@@ -0,0 +1 @@
+# The initial interface is not finalized yet so there are currently no hashes here.
diff --git a/interfaces/update-makefiles.sh b/interfaces/update-makefiles.sh
new file mode 100644
index 0000000..06eff1e
--- /dev/null
+++ b/interfaces/update-makefiles.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+source $ANDROID_BUILD_TOP/system/tools/hidl/update-makefiles-helper.sh
+
+do_makefiles_update \
+ "com.dsi:external/ant-wireless/hidl/interfaces" \
+ "android.hidl:system/libhidl/transport"
+
diff --git a/sepolicy/README.txt b/sepolicy/README.txt
new file mode 100644
index 0000000..838de0a
--- /dev/null
+++ b/sepolicy/README.txt
@@ -0,0 +1,4 @@
+The policy files in this directory must be merged with the platform policy files.
+
+for the public policy this is either system/sepolicy/public or BOARD_PLAT_PUBLIC_SEPOLICY
+for the private policy this is either system/sepolicy/private or BOARD_PLAT_PRIVATE_SEPOLICY
diff --git a/sepolicy/private/hwservice_contexts b/sepolicy/private/hwservice_contexts
new file mode 100644
index 0000000..5d915dd
--- /dev/null
+++ b/sepolicy/private/hwservice_contexts
@@ -0,0 +1 @@
+com.dsi.ant::IAnt u:object_r:hal_dsi_ant_hwservice:s0
diff --git a/sepolicy/public/attributes b/sepolicy/public/attributes
new file mode 100644
index 0000000..be962bc
--- /dev/null
+++ b/sepolicy/public/attributes
@@ -0,0 +1,6 @@
+attribute hal_dsi_ant;
+expandattribute hal_dsi_ant true;
+attribute hal_dsi_ant_client;
+expandattribute hal_dsi_ant_client true;
+attribute hald_dsi_ant_server;
+expandattribute hal_dsi_ant_server false;
diff --git a/sepolicy/public/hal_dsi_ant.te b/sepolicy/public/hal_dsi_ant.te
new file mode 100644
index 0000000..c5f93b0
--- /dev/null
+++ b/sepolicy/public/hal_dsi_ant.te
@@ -0,0 +1,9 @@
+type hal_dsi_ant_hwservice, hwservice_manager_type;
+
+# Allow interaction with the hwservice manager for the initial bind.
+add_hwservice(hal_dsi_ant_server, hal_dsi_ant_hwservice);
+allow hal_dsi_ant_client hal_dsi_ant_hwservice:hwservice_manager find;
+
+# Binder calls are made in both directions.
+binder_call(hal_dsi_ant_client, hal_dsi_ant_server);
+binder_call(hal_dsi_ant_server, hal_dsi_ant_client);
diff --git a/src/bluez_hci/Android.mk b/src/bluez_hci/Android.mk
deleted file mode 100644
index 2a7687b..0000000
--- a/src/bluez_hci/Android.mk
+++ /dev/null
@@ -1,67 +0,0 @@
-#
-# Copyright (C) 2009 Dynastream Innovations
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-include $(CLEAR_VARS)
-
-LOCAL_CFLAGS := -g -c -W -Wall -O2
-
-# Check which chip is used so correct values in messages
-ifeq ($(BOARD_ANT_WIRELESS_DEVICE),"wl12xx")
-LOCAL_CFLAGS += -DBOARD_ANT_DEVICE_WL12XX
-else ifeq ($(BOARD_ANT_WIRELESS_DEVICE),"bcm433x")
-LOCAL_CFLAGS += -DBOARD_ANT_DEVICE_BCM433X
-endif
-
-LOCAL_C_INCLUDES := \
- $(LOCAL_PATH)/src/common/inc \
- $(LOCAL_PATH)/$(ANT_DIR)/inc \
- system/bluetooth/bluez-clean-headers \
-
-ifeq ($(BOARD_ANT_WIRELESS_POWER),"bluedroid")
-LOCAL_CFLAGS += \
- -DBOARD_HAVE_ANT_WIRELESS \
- -DUSE_EXTERNAL_POWER_LIBRARY \
-
-LOCAL_C_INCLUDES += system/bluetooth/bluedroid/include/bluedroid
-endif # BOARD_ANT_WIRELESS_POWER = bluedroid
-
-LOCAL_SRC_FILES := \
- $(COMMON_DIR)/JAntNative.cpp \
- $(COMMON_DIR)/ant_utils.c \
- $(ANT_DIR)/ant_native_hci.c \
- $(ANT_DIR)/ant_rx.c \
- $(ANT_DIR)/ant_tx.c \
-
-# JNI
-LOCAL_C_INCLUDE += $(JNI_H_INCLUDE)
-
-LOCAL_SHARED_LIBRARIES += \
- libnativehelper \
-
-# chip power
-LOCAL_SHARED_LIBRARIES += \
- libbluedroid \
-
-# logging
-LOCAL_SHARED_LIBRARIES += \
- libcutils \
-
-LOCAL_MODULE_TAGS := optional
-LOCAL_PRELINK_MODULE := false
-LOCAL_MODULE := libantradio
-
-include $(BUILD_SHARED_LIBRARY)
-
diff --git a/src/bluez_hci/ant_native_hci.c b/src/bluez_hci/ant_native_hci.c
deleted file mode 100644
index f247534..0000000
--- a/src/bluez_hci/ant_native_hci.c
+++ /dev/null
@@ -1,865 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2009 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/******************************************************************************\
-*
-* FILE NAME: ant_native_hci.c
-*
-* BRIEF:
-* This file provides the BlueZ HCI implementation of ant_native.h
-*
-*
-\******************************************************************************/
-
-#include <pthread.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "ant_types.h"
-#include "ant_native.h"
-#include "ant_utils.h"
-#include "ant_version.h"
-
-#if USE_EXTERNAL_POWER_LIBRARY
-#include "antradio_power.h"
-#endif
-
-#include "ant_rx.h"
-#include "ant_tx.h"
-#include "ant_hciutils.h"
-#include "ant_log.h"
-
-static pthread_mutex_t txLock;
-pthread_mutex_t enableLock;
-
-ANTRadioEnabledStatus radio_status = RADIO_STATUS_DISABLED;
-ANTRadioEnabledStatus get_and_set_radio_status(void);
-
-////////////////////////////////////////////////////////////////////
-// ant_init
-//
-// Initialises the native environment.
-//
-// Parameters:
-// -
-//
-// Returns:
-// Success:
-// ANT_STATUS_SUCCESS
-// Failures:
-// ANT_STATUS_FAILED if could not initialize mutex
-//
-// Psuedocode:
-/*
-LOCK antdevice_LOCK
- CREATE mutex for locking Tx attempt
- IF could not create mutex
- RESULT = ANT_STATUS_FAILED
- ELSE
- CREATE mutex for locking enable/disable
- IF could not create mutex
- RESULT = ANT_STATUS_FAILED
- ELSE
- RESULT = ANT_STATUS_SUCCESS
- ENDIF
- ENDIF
-UNLOCK
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_init(void)
-{
- int mutexResult;
- ANTStatus status = ANT_STATUS_FAILED;
- ANT_FUNC_START();
-
- mutexResult = pthread_mutex_init(&txLock, NULL); //use default attr
- if (mutexResult)
- {
- ANT_ERROR("Tx Lock mutex initialization failed: %s", strerror(mutexResult));
- }
- else
- {
- mutexResult = pthread_mutex_init(&enableLock, NULL);
- if (mutexResult)
- {
- ANT_ERROR("Enable Lock mutex init failed %s", strerror(mutexResult));
- }
- else
- {
- status = ANT_STATUS_SUCCESS;
- }
- }
-
- ANT_FUNC_END();
- return status;
-}
-
-
-////////////////////////////////////////////////////////////////////
-// ant_deinit
-//
-// De-initialises the native environment.
-//
-// Parameters:
-// -
-//
-// Returns:
-// Success:
-// ANT_STATUS_SUCCESS
-// Failures:
-// ANT_STATUS_FAILED if could not de-initialize mutex
-//
-// Psuedocode:
-/*
-LOCK antdevice_LOCK (also Init and Tx)
- DESTROY mutex for locking Tx attempt
- IF could not destroy mutex
- RESULT = ANT_STATUS_FAILED
- ELSE
- DESTROY mutex for locking enable/disable
- IF coult not destroy mutex
- RESULT = ANT_STATUS_FAILED
- ELSE
- RESULT = ANT_STATUS_SUCCESS
- ENDIF
- ENDIF
-UNLOCK
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_deinit(void)
-{
- int mutexResult;
- ANTStatus result_status = ANT_STATUS_FAILED;
- ANT_FUNC_START();
-
- mutexResult = pthread_mutex_destroy(&txLock);
- if (mutexResult)
- {
- ANT_ERROR("Tx Lock mutex destroy failed: %s", strerror(mutexResult));
- }
- else
- {
- mutexResult = pthread_mutex_destroy(&enableLock);
- if (mutexResult)
- {
- ANT_ERROR("Enable Lock mutex destroy failed: %s", strerror(mutexResult));
- }
- else
- {
- result_status = ANT_STATUS_SUCCESS;
- }
- }
-
- ANT_FUNC_END();
- return result_status;
-}
-
-
-////////////////////////////////////////////////////////////////////
-// ant_enable_radio
-//
-// Powers on the ANT part and initialises the transport to the chip.
-// Changes occur in part implementing ant_enable() call
-// On Android this is in the Bluedroid module.
-// On Linux this is device specific
-//
-// Parameters:
-// -
-//
-// Returns:
-// Success:
-// ANT_STATUS_SUCCESS
-// Failures:
-// ANT_STATUS_TRANSPORT_INIT_ERR if could not enable
-// ANT_STATUS_FAILED if failed to get mutex or init rx thread
-//
-// Psuedocode:
-/*
-LOCK enable_LOCK
- LOCK tx_LOCK
- IF state is not enabled
- STATE = ENABLING
- ENDIF
- ant enable
- IF ant_enable success
- IF rx thread is running
- STATE = ENABLED
- RESULT = SUCCESS
- ELSE
- start rx thread
- IF starting rx thread fails
- ant disable
- get state
- IF state is enabled
- log a serious error
- ENDIF
- RESULT = FAILED
- ELSE
- STATE = ENABLED
- RESULT = SUCCESS
- ENDIF
- ENDIF
- ELSE
- get state
- IF state is enabled
- log a serious error
- ENDIF
- RESULT = FAILURE
- ENDIF
- UNLOCK
-UNLOCK
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_enable_radio(void)
-{
- int result;
- int lockResult;
- ANTStatus result_status = ANT_STATUS_FAILED;
- ANT_FUNC_START();
-
- ANT_DEBUG_V("getting enableLock in %s", __FUNCTION__);
- lockResult = pthread_mutex_lock(&enableLock);
- if(lockResult)
- {
- ANT_ERROR("Enable failed to get enableLock mutex: %s", strerror(lockResult));
- return ANT_STATUS_FAILED;
- }
- ANT_DEBUG_V("got enableLock in %s", __FUNCTION__);
-
- if(RADIO_STATUS_DISABLED == radio_status)
- {
- radio_status = RADIO_STATUS_ENABLING;
- }
-
- ANT_DEBUG_V("getting txLock in %s", __FUNCTION__);
- lockResult = pthread_mutex_lock(&txLock);
- if (lockResult)
- {
- ANT_ERROR("Enable txLock failed: %s", strerror(lockResult));
- pthread_mutex_unlock(&enableLock);
- return ANT_STATUS_FAILED;
- }
- ANT_DEBUG_V("got txLock in %s", __FUNCTION__);
-
- if (get_and_set_radio_status() != RADIO_STATUS_ENABLED)
- {
- if (RxParams.thread)
- {
- ANT_WARN("in enable call: rx thread still exists but radio crashed. trying to recover");
- ANT_DEBUG_V("radio crashed, letting rx thread join");
- pthread_join(RxParams.thread, NULL);
- RxParams.thread = 0;
- ANT_DEBUG_V("recovered. joined by rx thread");
- }
-
- ANT_DEBUG_I("radio_status (%d -> %d)", radio_status, RADIO_STATUS_ENABLING);
- radio_status = RADIO_STATUS_ENABLING;
-
-#if USE_EXTERNAL_POWER_LIBRARY
- if (RxParams.pfStateCallback)
- RxParams.pfStateCallback(radio_status);
-#endif
- }
-
-#if USE_EXTERNAL_POWER_LIBRARY
- result = ant_enable();
-
- ANT_DEBUG_D("ant_enable() result is %d", result);
-#else
- result = 0;
-#endif
- if (result == 0)
- {
- if (RxParams.thread)
- {
- result_status = ANT_STATUS_SUCCESS;
- radio_status = RADIO_STATUS_ENABLED; // sanity assign, cant be enabling
- ANT_DEBUG_D("ANT radio re-enabled");
- }
- else
- {
- result = pthread_create(&RxParams.thread, NULL, ANTHCIRxThread, NULL);
- if (result)
- {
- ANT_ERROR("Thread initialization failed: %s", strerror(result));
- result_status = ANT_STATUS_FAILED;
- }
- else
- {
- result_status = ANT_STATUS_SUCCESS;
-#if USE_EXTERNAL_POWER_LIBRARY
- if (radio_status == RADIO_STATUS_ENABLING)
- {
- ANT_DEBUG_I("radio_status (%d -> %d)", radio_status, RADIO_STATUS_ENABLED);
- radio_status = RADIO_STATUS_ENABLED;
-
- if (RxParams.pfStateCallback)
- RxParams.pfStateCallback(radio_status);
- }
- else
- {
- ANT_WARN("radio was already enabled but rx thread was not running");
- }
-#else
- radio_status = RADIO_STATUS_ENABLED;
-#endif
- }
- }
- }
- else
- {
- result_status = ANT_STATUS_TRANSPORT_INIT_ERR;
- }
-
- if (result_status != ANT_STATUS_SUCCESS) // ant_enable() or rx thread creating failed
- {
-#if USE_EXTERNAL_POWER_LIBRARY
- ant_disable();
-#endif
-
- switch (get_and_set_radio_status())
- {
- case RADIO_STATUS_ENABLED:
- ANT_ERROR("SERIOUS: enable failed, but ANT is enabled without a rx thread");
- break;
- default:
- ANT_DEBUG_D("Enable failed, after cleanup chip is not enabled");
- break;
- }
- }
-
- ANT_DEBUG_V("releasing txLock in %s", __FUNCTION__);
- pthread_mutex_unlock(&txLock);
- ANT_DEBUG_V("released txLock in %s", __FUNCTION__);
-
- ANT_DEBUG_V("releasing enableLock in %s", __FUNCTION__);
- pthread_mutex_unlock(&enableLock);
- ANT_DEBUG_V("released enableLock in %s", __FUNCTION__);
-
- ANT_FUNC_END();
- return result_status;
-}
-
-////////////////////////////////////////////////////////////////////
-// ant_radio_hard_reset
-//
-// Does nothing as Hard Reset is not supported.
-//
-// Parameters:
-// -
-//
-// Returns:
-// ANT_NOT_SUPPORTED
-//
-// Psuedocode:
-/*
-RESULT = NOT SUPPORTED
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_radio_hard_reset(void)
-{
- ANTStatus result_status = ANT_STATUS_NOT_SUPPORTED;
- ANT_FUNC_START();
- ANT_FUNC_END();
- return result_status;
-}
-
-////////////////////////////////////////////////////////////////////
-// ant_disable_radio
-//
-// Disables the HCI transport and powers off the ANT part.
-//
-// Parameters:
-// -
-//
-// Returns:
-// Success:
-// ANT_STATUS_SUCCESS
-// Failures:
-// ANT_STATUS_FAILED if could not get mutex
-// ANT_STATUS_NOT_DE_INITIALIZED if ant_disable failed
-//
-// Psuedocode:
-/*
-LOCK enable_LOCK
- LOCK tx_LOCK
- IF not disabled
- STATE = DISABLING
- ENDIF
- ant disable
- IF rx thread is running
- wait for rx thread to terminate
- ENDIF
- get radio status
- IF radio is disabled
- RESULT = SUCCESS
- ELSE IF radio is enabled
- log a serious error
- RESULT = FAILURE
- ELSE
- RESULT = FAILURE
- ENDIF
- UNLOCK
-UNLOCK
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_disable_radio(void)
-{
- int result;
- int lockResult;
- ANTStatus ret = ANT_STATUS_FAILED;
- ANT_FUNC_START();
-
- ANT_DEBUG_V("getting enableLock in %s", __FUNCTION__);
- lockResult = pthread_mutex_lock(&enableLock);
- if(lockResult)
- {
- ANT_ERROR("Disable failed to get enableLock mutex: %s", strerror(lockResult));
- return ANT_STATUS_FAILED;
- }
- ANT_DEBUG_V("got enableLock in %s", __FUNCTION__);
-
- ANT_DEBUG_V("getting txLock in %s", __FUNCTION__);
- lockResult = pthread_mutex_lock(&txLock);
- if (lockResult)
- {
- ANT_ERROR("Disable txLock failed: %s", strerror(lockResult));
- pthread_mutex_unlock(&enableLock);
- return ANT_STATUS_FAILED;
- }
- ANT_DEBUG_V("got txLock in %s", __FUNCTION__);
-
-#if USE_EXTERNAL_POWER_LIBRARY
- if (get_and_set_radio_status() != RADIO_STATUS_DISABLED)
- {
- ANT_DEBUG_I("radio_status (%d -> %d)", radio_status, RADIO_STATUS_DISABLING);
- radio_status = RADIO_STATUS_DISABLING;
-
- if (RxParams.pfStateCallback)
- RxParams.pfStateCallback(radio_status);
- }
-
- result = ant_disable();
-
- ANT_DEBUG_D("ant_disable() result is %d", result);
-#else
- radio_status = RADIO_STATUS_DISABLED;
-#endif
-
- // If rx thread exists ( != 0)
- if (RxParams.thread)
- {
- ANT_DEBUG_V("quit rx thread, joining");
- pthread_join(RxParams.thread, NULL);
- RxParams.thread = 0;
- ANT_DEBUG_V("joined by rx thread");
- }
- else
- {
- ANT_DEBUG_W("rx thread is 0 (not created?)");
- }
-
- switch (get_and_set_radio_status())
- {
- case RADIO_STATUS_DISABLED:
- ret = ANT_STATUS_SUCCESS;
- break;
- case RADIO_STATUS_ENABLED:
- ANT_ERROR("SERIOUS: ANT was disabled, rx thread quit, but ANT is enabled");
- ret = ANT_STATUS_FAILED;
- break;
- default:
- ret = ANT_STATUS_NOT_DE_INITIALIZED;
- break;
- }
-
- ANT_DEBUG_V("releasing txLock in %s", __FUNCTION__);
- pthread_mutex_unlock(&txLock);
- ANT_DEBUG_V("released txLock in %s", __FUNCTION__);
-
- ANT_DEBUG_V("releasing enableLock in %s", __FUNCTION__);
- pthread_mutex_unlock(&enableLock);
- ANT_DEBUG_V("released enableLock in %s", __FUNCTION__);
-
- ANT_FUNC_END();
- return ret;
-}
-
-
-////////////////////////////////////////////////////////////////////
-// ant_radio_enabled_status
-//
-// Returns if the chip/transport is disabled/disabling/enabling/enabled. This
-// function will NOT overwrite internal state variable enabling or disabling.
-// It will call get_and_set_radio_status() if not enabling/disabling which can
-// change internal state on errors.
-//
-// Parameters:
-// -
-//
-// Returns:
-// The current radio status (ANTRadioEnabledStatus)
-//
-// Psuedocode:
-/*
-IF Enabling
- RESULT = Enabling
-ELSE IF Disabling
- RESULT = Disabling
-ELSE
- IF ant_is_enabled
- Enabled
- RESULT = Enabled
- ELSE
- Disabled
- RESULT = Disabled
- ENDIF
-ENDIF
-*/
-////////////////////////////////////////////////////////////////////
-ANTRadioEnabledStatus ant_radio_enabled_status(void)
-{
- ANT_FUNC_START();
-
- if ((RADIO_STATUS_ENABLING != radio_status) &&
- (RADIO_STATUS_DISABLING != radio_status))
- {
- get_and_set_radio_status();
- }
-
- ANT_FUNC_END();
- return radio_status;
-}
-
-////////////////////////////////////////////////////////////////////
-// get_and_set_radio_status
-//
-// Returns if the chip/transport is disabled/enabled/unknown This function WILL
-// overwrite what it thinks the state is with what the BlueZ core (kernel)
-// thinks it is. It will overwrite enabling or disabling states, and might
-// change internal state from enabled, disabled, or unknown to any of these
-// three on errors.
-//
-// Parameters:
-// -
-//
-// Returns:
-// The current radio status (ANTRadioEnabledStatus)
-//
-////////////////////////////////////////////////////////////////////
-ANTRadioEnabledStatus get_and_set_radio_status(void)
-{
- ANT_FUNC_START();
-#if USE_EXTERNAL_POWER_LIBRARY
- ANTRadioEnabledStatus orig_status = radio_status;
- switch (ant_is_enabled())
- {
- case 0:
- radio_status = RADIO_STATUS_DISABLED;
- break;
- case 1:
- radio_status = RADIO_STATUS_ENABLED;
- break;
- default:
- ANT_ERROR("getting chip state returned an error");
- radio_status = RADIO_STATUS_UNKNOWN;
- break;
- }
- if (orig_status != radio_status)
- {
- ANT_DEBUG_I("radio_status (%d -> %d)", orig_status, radio_status);
-
- if (RxParams.pfStateCallback)
- RxParams.pfStateCallback(radio_status);
- }
-#endif
- ANT_FUNC_END();
- return radio_status;
-}
-
-////////////////////////////////////////////////////////////////////
-// set_ant_rx_callback
-//
-// Sets which function to call when an ANT message is received.
-//
-// Parameters:
-// rx_callback_func the ANTNativeANTEventCb function to be used
-// for received messages.
-//
-// Returns:
-// ANT_STATUS_SUCCESS
-//
-// Psuedocode:
-/*
- Rx Callback = rx_callback_func
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus set_ant_rx_callback(ANTNativeANTEventCb rx_callback_func)
-{
- ANTStatus status = ANT_STATUS_SUCCESS;
- ANT_FUNC_START();
-
- RxParams.pfRxCallback = rx_callback_func;
-
- ANT_FUNC_END();
- return status;
-}
-
-////////////////////////////////////////////////////////////////////
-// set_ant_state_callback
-//
-// Sets which function to call when an ANT state change occurs.
-//
-// Parameters:
-// state_callback_func the ANTNativeANTStateCb function to be used
-// for received state changes.
-//
-// Returns:
-// ANT_STATUS_SUCCESS
-//
-// Psuedocode:
-/*
- State Callback = state_callback_func
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus set_ant_state_callback(ANTNativeANTStateCb state_callback_func)
-{
- ANTStatus status = ANT_STATUS_SUCCESS;
- ANT_FUNC_START();
-
- RxParams.pfStateCallback = state_callback_func;
-
- ANT_FUNC_END();
-
- return status;
-}
-
-////////////////////////////////////////////////////////////////////
-// ant_tx_message
-//
-// Sends an ANT message to the chip
-//
-// Parameters:
-// ucLen the length of the message
-// pucMesg pointer to the message data
-//
-// Returns:
-// Success:
-// ANT_STATUS_SUCCESS
-// Failure:
-// ANT_STATUS_NOT_ENABLED
-//
-// Psuedocode:
-/*
-IF not enabled
- RESULT = NOT ENABLED
-ELSE
- Lock
- IF Lock failed
- RESULT = FAILED
- ELSE
- STORE length (little endian) in send buffer
- STORE data in send buffer
- ENDIF
-ENDIF
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_tx_message(ANT_U8 ucLen, ANT_U8 *pucMesg)
-{
- ANTStatus status;
-
- /* Socket for sending HCI commands */
- int tx_socket = -1;
-
- int lockResult;
-
- ANT_FUNC_START();
-
- ANT_DEBUG_V("getting txLock in %s", __FUNCTION__);
- lockResult = pthread_mutex_lock(&txLock);
- if (lockResult)
- {
- ANT_ERROR("ant_tx_message, could not get txLock: %s", strerror(lockResult));
- return ANT_STATUS_FAILED;
- }
-
- ANT_DEBUG_V("got txLock in %s", __FUNCTION__);
-
- if(RADIO_STATUS_ENABLED != get_and_set_radio_status())
- {
- ANT_DEBUG_E("ant_tx_message, ANT not enabled - ABORTING. Radio status = %d",
- radio_status);
- ANT_DEBUG_V("releasing txLock in %s", __FUNCTION__);
- pthread_mutex_unlock(&txLock);
- ANT_DEBUG_V("released txLock in %s", __FUNCTION__);
- return ANT_STATUS_FAILED_BT_NOT_INITIALIZED;
- }
-
- // Open socket
- tx_socket = ant_open_tx_transport();
-
- if(tx_socket < 0)
- {
- ANT_ERROR("Could not open Tx socket");
- ANT_DEBUG_V("releasing txLock in %s", __FUNCTION__);
- pthread_mutex_unlock(&txLock);
- ANT_DEBUG_V("released txLock in %s", __FUNCTION__);
- return ANT_STATUS_FAILED;
- }
-
- // Send HCI packet
- ANT_BOOL retryRx;
- ANT_BOOL retryTx;
- status = ANT_STATUS_FAILED;
-
- int MAX_RETRIES_WRITE_FAIL = 10;
- int MAX_RETRY_TIME_SECS = 10;
- int commandWriteFailRetries = 0;
-
- // Start New timed retry code:
- time_t startTime = time(NULL);
- time_t endTime = 0;
- if((time_t)-1 != startTime)
- {
- endTime = startTime + MAX_RETRY_TIME_SECS;
- }
- else
- {
- ANT_ERROR("failed to get current time");
- }
-
- do // while (retryTx)
- {
- retryTx = ANT_FALSE;
-
- if(ANT_STATUS_SUCCESS == write_data(pucMesg, ucLen))
- {
- do // while (retryRx)
- {
- retryRx = ANT_FALSE;
-
- if(ANT_TRUE == wait_for_message(tx_socket))
- {
- ANT_DEBUG_D("New HCI data available, reading...");
-
- status = get_command_complete_result(tx_socket);
- switch (status)
- {
- case ANT_STATUS_NO_VALUE_AVAILABLE:
- {
- ANT_WARN("Did not get an expected response for write, trying again");
- retryRx = ANT_TRUE;
- break;
- }
- case ANT_STATUS_FAILED:
- {
- ANT_ERROR("Command Complete: ANT_STATUS_FAILED");
- break;
- }
- case ANT_STATUS_COMMAND_WRITE_FAILED:
- {
- ANT_ERROR("Command Complete: ANT_STATUS_WRITE_FAILED");
-
- if(++commandWriteFailRetries < MAX_RETRIES_WRITE_FAIL)
- {
- ANT_DEBUG_D("Retrying. Retry count = %d",
- commandWriteFailRetries);
-
- retryTx = ANT_TRUE;
- }
- else
- {
- ANT_ERROR("Aborting. Retry count = %d. Max retries = %d",
- commandWriteFailRetries, MAX_RETRIES_WRITE_FAIL);
- }
- break;
- }
- case ANT_STATUS_TRANSPORT_UNSPECIFIED_ERROR:
- {
- ANT_DEBUG_D("Command Complete: ANT_STATUS_UNSPECIFIED_ERROR");
-
- // Give the chip a break before we try to resend data.
- nanosleep((struct timespec[]){{0, 50000000}}, NULL);
-
- time_t currentTime = time(NULL);
-
- if((time_t)-1 != currentTime)
- {
- if(currentTime < endTime)
- {
- ANT_DEBUG_V("Retrying. Current time = %d. "
- "End time = %d", (int)currentTime, (int)endTime);
-
- retryTx = ANT_TRUE;
- }
- else
- {
- ANT_ERROR("Command Complete: ANT_STATUS_UNSPECIFIED_ERROR");
- ANT_ERROR("Aborting. Current time = %d. End Time = %d",
- (int)currentTime, (int)endTime);
- }
- }
- else
- {
- ANT_ERROR("Command Complete: failed to get current time");
- }
-
- break;
- }
- case ANT_STATUS_SUCCESS:
- {
- break;
- }
- default:
- {
- ANT_ERROR("Unhandled command complete status");
- break;
- }
- }
- }
- else
- {
- ANT_WARN("Command Complete: wait for message failed");
- }
- } while (retryRx);
- }
- else
- {
- ANT_ERROR("write failed");
- retryRx = ANT_FALSE;
-
- status = ANT_STATUS_FAILED;
- }
- } while(retryTx);
-
- ant_close_tx_transport(tx_socket);
-
- ANT_DEBUG_V("releasing txLock in %s", __FUNCTION__);
- pthread_mutex_unlock(&txLock);
- ANT_DEBUG_V("released txLock in %s", __FUNCTION__);
-
- ANT_FUNC_END();
-
- return status;
-}
-
-const char *ant_get_lib_version()
-{
- return "libantradio.so Bluez HCI Transport Version "
- LIBANT_STACK_MAJOR "." LIBANT_STACK_MINOR "." LIBANT_STACK_INCRE;
-}
-
diff --git a/src/bluez_hci/ant_rx.c b/src/bluez_hci/ant_rx.c
deleted file mode 100644
index 3894cd6..0000000
--- a/src/bluez_hci/ant_rx.c
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2009 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/******************************************************************************\
-*
-* FILE NAME: ant_rx.c
-*
-* BRIEF:
-* This file implements the receive thread for a BlueZ HCI implementation
-* using Vendor Specific messages.
-*
-*
-\******************************************************************************/
-
-#define _GNU_SOURCE /* needed for PTHREAD_MUTEX_RECURSIVE */
-
-#include <errno.h>
-#include <poll.h>
-#include <pthread.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-
-#include <sys/resource.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/un.h>
-
-#include <bluetooth/bluetooth.h>
-#include <bluetooth/hci.h>
-#include <bluetooth/hci_lib.h>
-
-#include "ant_types.h"
-
-#if USE_EXTERNAL_POWER_LIBRARY
-#include "antradio_power.h"
-#endif
-
-#include "ant_rx.h"
-#include "ant_hciutils.h"
-#include "ant_framing.h"
-#include "ant_log.h"
-
-#undef LOG_TAG
-#define LOG_TAG "antradio_rx"
-
-/* Global Options */
-ANTHCIRxParams RxParams = {
- .pfRxCallback = NULL,
- .pfStateCallback = NULL,
- .thread = 0
-};
-
-extern pthread_mutex_t enableLock;
-extern ANTRadioEnabledStatus get_and_set_radio_status(void);
-#ifndef USE_EXTERNAL_POWER_LIBRARY
-extern ANTRadioEnabledStatus radio_status;
-#endif
-
-/*
- * This thread opens a Bluez HCI socket and waits for ANT messages.
- */
-void *ANTHCIRxThread(void *pvHCIDevice)
-{
- int ret = ANT_STATUS_SUCCESS;
- int rxSocket;
- int len;
- unsigned char buf[HCI_MAX_EVENT_SIZE];
- int result;
- struct hci_filter eventVendorFilter;
- ANT_FUNC_START();
-
- (void)pvHCIDevice; //unused waring
-
- ANT_DEBUG_D("Entering ANTHCIRxThread");
-
- rxSocket = create_hci_sock();
- if (rxSocket < 0)
- {
- ANT_DEBUG_E("can't open HCI socket in rx thread: %s", strerror(errno));
-
- ret = ANT_STATUS_FAILED;
- goto out;
- }
-
- eventVendorFilter.type_mask = TYPE_MASK_EVENT_PACKET;
- eventVendorFilter.event_mask[0] = 0;
- eventVendorFilter.event_mask[1] = EVENT_MASK_1_EVENT_VENDOR;
- eventVendorFilter.opcode = htobs(ANT_EVENT_VENDOR_CODE);
-
- if (setsockopt(rxSocket, SOL_HCI, HCI_FILTER, &eventVendorFilter, sizeof(eventVendorFilter)) < 0)
- {
- ANT_ERROR("failed to set socket options: %s", strerror(errno));
-
- ret = ANT_STATUS_FAILED;
- goto close;
- }
-
- /* continue running as long as not terminated */
- while (get_and_set_radio_status() == RADIO_STATUS_ENABLED)
- {
- struct pollfd p;
- int n;
-
- p.fd = rxSocket;
- p.events = POLLIN;
-
- ANT_DEBUG_V(" RX: Polling HCI for data...");
-
- /* poll socket, wait for ANT messages */
- while ((n = poll(&p, 1, 2500)) == -1)
- {
- if (errno == EAGAIN || errno == EINTR)
- continue;
-
- ANT_ERROR("failed to poll socket: %s", strerror(errno));
-
- ret = ANT_STATUS_FAILED;
- goto close;
- }
-
- /* we timeout once in a while */
- /* this let's us the chance to check if we were terminated */
- if (0 == n)
- {
- ANT_DEBUG_V(" RX: Timeout");
- continue;
- }
-
- ANT_DEBUG_D("New HCI data available, reading...");
-
- /* read newly arrived data */
- /* TBD: rethink assumption about single arrival */
- while ((len = read(rxSocket, buf, sizeof(buf))) < 0)
- {
- if (errno == EAGAIN || errno == EINTR)
- continue;
-
- ANT_ERROR("failed to read socket: %s", strerror(errno));
-
- ret = ANT_STATUS_FAILED;
- goto close;
- }
-
- hci_event_packet_t *event_packet = (hci_event_packet_t *)buf;
- int hci_payload_len = validate_hci_event_packet(event_packet, len);
- if (hci_payload_len == -1)
- {
- // part of the message is incorrect, ignore it. validate_event_packet will log error
- continue;
- }
-
- ANT_SERIAL(event_packet->hci_payload, hci_payload_len, 'R');
-
- if(RxParams.pfRxCallback != NULL)
- {
- RxParams.pfRxCallback(hci_payload_len, event_packet->hci_payload);
- }
- else
- {
- ANT_ERROR("Can't send rx message - no callback registered");
- }
- }
-
-close:
- result = pthread_mutex_trylock(&enableLock);
- ANT_DEBUG_D("rx thread close: trylock enableLock returned %d", result);
-
- if (result == 0)
- {
- ANT_DEBUG_W("rx thread socket has unexpectedly crashed");
-#if USE_EXTERNAL_POWER_LIBRARY
- if (RxParams.pfStateCallback)
- RxParams.pfStateCallback(RADIO_STATUS_DISABLING);
- ant_disable();
- get_and_set_radio_status();
-#else
- radio_status = RADIO_STATUS_DISABLED;
-#endif
- RxParams.thread = 0;
- pthread_mutex_unlock(&enableLock);
- }
- else if (result == EBUSY)
- {
- ANT_DEBUG_V("rx thread socket was closed");
- }
- else
- {
- ANT_ERROR("rx thread close: trylock failed: %s", strerror(result));
- }
-
- if (-1 == close(rxSocket))
- {
- ANT_ERROR("failed to close hci device (socket handle=%#x): %s", rxSocket, strerror(errno));
- }
- else
- {
- ANT_DEBUG_D("closed hci device (socket handle=%#x)", rxSocket);
- }
-
-out:
- ANT_FUNC_END();
-
- pthread_exit((void *)ret);
-
-#if defined(ANDROID)
- return 0;
-#endif
-}
-
diff --git a/src/bluez_hci/ant_tx.c b/src/bluez_hci/ant_tx.c
deleted file mode 100644
index e1efa7f..0000000
--- a/src/bluez_hci/ant_tx.c
+++ /dev/null
@@ -1,335 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2009 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/******************************************************************************\
-*
-* FILE NAME: ant_tx.c
-*
-* BRIEF:
-* This file Implements the transmit functionality for a BlueZ HCI
-* implementation using Vendor Specific messages.
-*
-*
-\******************************************************************************/
-
-#include <errno.h>
-#include <poll.h>
-#include <sys/uio.h>
-
-#include <bluetooth/bluetooth.h>
-#include <bluetooth/hci.h>
-#include <bluetooth/hci_lib.h>
-
-#include "ant_types.h"
-#include "ant_hciutils.h"
-#include "ant_framing.h"
-#include "ant_utils.h"
-#include "ant_log.h"
-
-#undef LOG_TAG
-#define LOG_TAG "antradio_tx"
-
-int g_ant_cmd_socket = -1;
-
-int ant_open_tx_transport(void)
-{
- int socket = -1;
- struct hci_filter commandCompleteFilter;
- ANT_FUNC_START();
-
- socket = create_hci_sock();
-
- if (socket < 0)
- {
- ANT_DEBUG_E("failed to open HCI socket for tx: %s", strerror(errno));
- }
- else
- {
- g_ant_cmd_socket = socket;
- ANT_DEBUG_D("socket handle %#x", socket);
-
- commandCompleteFilter.type_mask = TYPE_MASK_EVENT_PACKET;
- commandCompleteFilter.event_mask[0] = EVENT_MASK_0_COMMAND_COMPLETE;
- commandCompleteFilter.event_mask[1] = 0;
- commandCompleteFilter.opcode = htobs(ANT_COMMAND_OPCODE);
-
- if (setsockopt(socket, SOL_HCI, HCI_FILTER, &commandCompleteFilter, sizeof(commandCompleteFilter)) < 0)
- {
- ANT_ERROR("failed to set socket options: %s", strerror(errno));
- close(socket);
- socket = -1;
- }
- }
-
- ANT_FUNC_END();
- return socket;
-}
-
-void ant_close_tx_transport(int socket)
-{
- ANT_FUNC_START();
-
- if(0 < socket)
- {
- if (0 == close(socket))
- {
- ANT_DEBUG_D("closed hci device (socket handle=%#x)", socket);
- }
- else
- {
- ANT_ERROR("failed to close hci device (socket handle=%#x): %s", socket, strerror(errno));
- }
- }
- else
- {
- ANT_DEBUG_E("requested close on socket %#x. invalid param", socket);
- }
-
- ANT_FUNC_END();
-}
-
-/*
-Format of an HCI WRITE command to ANT chip:
-
-HCI Header:
-----------
-- HCI Packet Type: 1 byte
-
-- HCI Opcode: 2 bytes
- (LSB, MSB - LE)
-- HCI Parameters Total Len (total length of all subsequent fields): 1 byte
-
-HCI Parameters:
---------------
-- VS Parameters Len (total length of ANT Mesg inculding Len/ID) 2 bytes
- (LSB, MSB - LE)
-- ANT Mesg Len (N = number of bytes in ANT Mesg Data): 1 byte
-- ANT Mesg ID: 1 byte
-- ANT Mesg Data: N bytes
-*/
-
-ANT_BOOL wait_for_message(int socket)
-{
- struct pollfd p;
- int n;
-
- ANT_BOOL bReturn = ANT_FALSE;
- ANT_BOOL bRetry = ANT_FALSE;
-
- ANT_FUNC_START();
-
- p.fd = socket;
- p.events = POLLIN;
-
- do
- {
- bRetry = ANT_FALSE;
-
- ANT_DEBUG_V(" CC: Polling HCI for data...");
-
- /* poll socket, wait for ANT messages */
- n = poll(&p, 1, 2500);
- if (0 > n)
- {
- if (errno == EAGAIN || errno == EINTR)
- {
- ANT_DEBUG_W(" CC: error: %s", strerror(errno));
- bRetry = ANT_TRUE;
- }
- else
- {
- ANT_ERROR("failed to poll socket. error: %s", strerror(errno));
- }
- }
-
- /* timeout */
- else if (0 == n)
- {
- ANT_ERROR("SERIOUS: Timeouted getting Command Complete");
- }
- else if(0 < n)
- {
- // There is data to read.
- bReturn = ANT_TRUE;
- }
-
- } while(ANT_TRUE == bRetry);
-
- ANT_FUNC_END();
-
- return bReturn;
-}
-
-ANTStatus write_data(ANT_U8 ant_message[], int ant_message_len)
-{
- ANTStatus ret = ANT_STATUS_FAILED;
- ANT_BOOL retry = ANT_FALSE;
- int bytes_written;
- struct iovec iov[2];
- hci_command_vendor_header_t hci_header;
-
- ANT_FUNC_START();
-
- create_command_header(&hci_header, ant_message_len);
-
- iov[0].iov_base = &hci_header;
- iov[0].iov_len = sizeof(hci_header);
- iov[1].iov_base = ant_message;
- iov[1].iov_len = ant_message_len;
-
- do //while retry
- {
- retry = ANT_FALSE;
-
- if (g_ant_cmd_socket < 0)
- {
- ANT_DEBUG_E("bad socket handle %#x", g_ant_cmd_socket);
- return ANT_STATUS_INTERNAL_ERROR;
- }
-
- ANT_SERIAL(ant_message, ant_message_len, 'T');
-
- bytes_written = writev(g_ant_cmd_socket, iov, 2);
-
- ANT_DEBUG_D("writing to socket %#x returned %d", g_ant_cmd_socket,
- bytes_written);
-
-// bytes_written < 0 = error (check errno)
-// bytes_written = 0 = No data written
-// bytes_written < sizeof(hci_message) = not all data written
-// bytes_written = sizeof(hci_message) = all data written
-
- if(bytes_written < 0)
- {
- ANT_ERROR("write to HCI failed: %s", strerror(errno));
-
- if (errno == EAGAIN || errno == EINTR)
- {
- ANT_DEBUG_D("Retrying write to HCI");
- retry = ANT_TRUE;
- }
- else
- {
- ret = ANT_STATUS_FAILED;
- }
- }
- else if(bytes_written < ((int)sizeof(hci_header) + ant_message_len))
- {
- ANT_DEBUG_D("Only %d bytes written to HCI.", bytes_written);
- ret = ANT_STATUS_FAILED;
- }
- else
- {
- ANT_DEBUG_V("writev successful");
- ret = ANT_STATUS_SUCCESS;
- }
- } while(retry);
-
- ANT_FUNC_END();
-
- return ret;
-}
-
-// Returns:
-// ANT_STATUS_NO_VALUE_AVAILABLE if not a CC packet
-// ANT_STATUS_FAILED if could not read socket or not a
-// valid length CC packet
-// ANT_STATUS_TRANSPORT_UNSPECIFIED_ERROR if CC indicates an unspecified error
-// ANT_STATUS_COMMAND_WRITE_FAILED if CC indicates a failure
-// ANT_STATUS_SUCCESS if CC indicates message was received
-ANTStatus get_command_complete_result(int socket)
-{
- ANTStatus status = ANT_STATUS_NO_VALUE_AVAILABLE;
- int len;
- ANT_U8 ucResult = -1;
- ANT_U8 buf[HCI_MAX_EVENT_SIZE];
-
- ANT_FUNC_START();
- ANT_DEBUG_V("reading off socket %#x", socket);
-
- /* read newly arrived data */
- while ((len = read(socket, buf, sizeof(buf))) < 0)
- {
- if (errno == EAGAIN || errno == EINTR)
- continue;
-
- ANT_ERROR("failed to read socket. error: %s", strerror(errno));
-
- status = ANT_STATUS_FAILED;
- goto close;
- }
-
- ANT_SERIAL(buf, len, 'C');
-
- // validate that we have a single command complete packet
- if (len != sizeof(hci_command_complete_packet_t))
- {
- status = ANT_STATUS_FAILED;
- }
- else
- {
- hci_command_complete_packet_t *command_complete = (hci_command_complete_packet_t *)buf;
-
- if(command_complete->packet_type == HCI_EVENT_PKT)
- {
- ANT_DEBUG_D("Received Event Packet");
-
- if(command_complete->event_header.evt == EVT_CMD_COMPLETE)
- {
- ANT_U16 opcode = ANT_UTILS_LEtoHost16((ANT_U8 *)&command_complete->command_complete_hdr.opcode);
- if(opcode == ANT_COMMAND_OPCODE)
- {
- ANT_DEBUG_V("Received COMMAND COMPLETE");
- ucResult = command_complete->response;
-
- if(ucResult == 0)
- {
- ANT_DEBUG_D("Command Complete = SUCCESS");
- status = ANT_STATUS_SUCCESS;
- }
- else if(ucResult == HCI_UNSPECIFIED_ERROR)
- {
- ANT_DEBUG_D("Command Complete = UNSPECIFIED_ERROR");
- status = ANT_STATUS_TRANSPORT_UNSPECIFIED_ERROR;
- }
- else
- {
- status = ANT_STATUS_COMMAND_WRITE_FAILED;
- ANT_DEBUG_D("Command Complete = WRITE_FAILED");
- }
- }
- else
- {
- ANT_DEBUG_W("Command complete has wrong opcode, this should have been filtered out");
- }
- }
- else
- {
- ANT_DEBUG_W("Event is not a command complete, this should have been filtered out");
- }
- }
- else
- {
- ANT_DEBUG_W("Other Event Packet, this should have been filtered out");
- }
- }
-
-close:
- ANT_FUNC_END();
- return status;
-}
-
diff --git a/src/bluez_hci/inc/ant_framing.h b/src/bluez_hci/inc/ant_framing.h
deleted file mode 100644
index 59c16ca..0000000
--- a/src/bluez_hci/inc/ant_framing.h
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2009 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/******************************************************************************\
-*
-* FILE NAME: ant_framing.h
-*
-* BRIEF:
-* This file defines ANT specific HCI values used by the ANT chip with a
-* shared BlueZ HCI transport.
-*
-*
-\******************************************************************************/
-
-#ifndef __ANT_HCIFRAMING_H
-#define __ANT_HCIFRAMING_H
-
-#if defined(BOARD_ANT_DEVICE_WL12XX)
-
-#define ANT_COMMAND_OPCODE 0xFDD1
-#define ANT_EVENT_VENDOR_CODE 0x0500
-
-typedef struct {
- ANT_U16 vendor_msg_len;
-} __attribute__ ((packed)) hci_cmd_vendor_hdr_t;
-#define HCI_COMMAND_VENDOR_HDR_SIZE 2
-
-typedef struct {
- ANT_U16 vendor_code;
- ANT_U16 vendor_msg_len;
-} __attribute__ ((packed)) hci_evt_vendor_hdr_t;
-#define HCI_EVENT_VENDOR_HDR_SIZE 4
-
-#elif defined(BOARD_ANT_DEVICE_BCM433X)
-
-#define ANT_COMMAND_OPCODE 0xFCEC
-#define ANT_EVENT_VENDOR_CODE 0x2D
-
-typedef struct {
- ANT_U8 command_id_padding;
-} __attribute__ ((packed)) hci_cmd_vendor_hdr_t;
-#define HCI_COMMAND_VENDOR_HDR_SIZE 1
-
-typedef struct {
- ANT_U8 vendor_code;
- ANT_U8 status;
-} __attribute__ ((packed)) hci_evt_vendor_hdr_t;
-#define HCI_EVENT_VENDOR_HDR_SIZE 2
-
-#define COMMAND_ID_PADDING 0xFF
-
-#endif
-
-#include <bluetooth/bluetooth.h>
-#include <bluetooth/hci.h>
-
-#include "ant_native.h"
-#include "ant_types.h"
-#include "ant_utils.h"
-
-#define HCI_EVENT_HEADER_OVERHEAD (HCI_TYPE_LEN + HCI_EVENT_HDR_SIZE)
-#define HCI_EVENT_TOTAL_OVERHEAD (HCI_EVENT_HEADER_OVERHEAD + HCI_EVENT_VENDOR_HDR_SIZE)
-
-#define TYPE_MASK_EVENT_PACKET 0x00000010
-#define EVENT_MASK_0_COMMAND_COMPLETE 0x00004000
-#define EVENT_MASK_1_EVENT_VENDOR 0x80000000
-
-// -------------------------------------------------
-
-typedef struct {
- ANT_U8 packet_type; // HCI_COMMAND_PKT
- hci_command_hdr command_header; // from hci.h
- hci_cmd_vendor_hdr_t vendor_header;
-} __attribute__ ((packed)) hci_command_vendor_header_t;
-
-
-typedef struct {
- ANT_U8 packet_type; // HCI_EVENT_PKT
- hci_event_hdr event_header; // from hci.h
- hci_evt_vendor_hdr_t vendor_header;
- ANT_U8 hci_payload[HCI_MAX_EVENT_SIZE];
-} __attribute__ ((packed)) hci_event_packet_t;
-
-typedef struct {
- ANT_U8 packet_type; // HCI_EVENT_PKT
- hci_event_hdr event_header; // from hci.h
- evt_cmd_complete command_complete_hdr;// from hci.h
- ANT_U8 response;
-} __attribute__ ((packed)) hci_command_complete_packet_t;
-
-// -------------------------------------------------
-
-/**
- * @param header the struct to fill with chip specific hci header
- * @param ant_message_len total ant length, size, id, and data
- */
-static inline void create_command_header(hci_command_vendor_header_t *header, ANT_U8 ant_message_len)
-{
- header->packet_type = HCI_COMMAND_PKT;
- header->command_header.opcode = htobs(ANT_COMMAND_OPCODE);
- header->command_header.plen = ant_message_len + HCI_COMMAND_VENDOR_HDR_SIZE;
-#if defined(BOARD_ANT_DEVICE_WL12XX)
- header->vendor_header.vendor_msg_len = htobs(ant_message_len);
-#elif defined(BOARD_ANT_DEVICE_BCM433X)
- header->vendor_header.command_id_padding = COMMAND_ID_PADDING;
-#endif
-}
-
-/**
- * @param packet the struct to check if is an ANT hci payload
- * @param packet_len the total length of the packet
- * @return 0 if valid, -1 if not valid
- */
-static inline int validate_hci_event_vendor(hci_event_packet_t *packet, int packet_len)
-{
-#if defined(BOARD_ANT_DEVICE_WL12XX)
- ANT_U16 vendor_code = ANT_UTILS_LEtoHost16((ANT_U8 *)&packet->vendor_header.vendor_code);
-#elif defined(BOARD_ANT_DEVICE_BCM433X)
- ANT_U8 vendor_code = packet->vendor_header.vendor_code;
-#endif
- if (vendor_code != ANT_EVENT_VENDOR_CODE) {
- ANT_ERROR("HCI packet vendor event code is not ANT");
- return -1;
- }
-
-#if defined(BOARD_ANT_DEVICE_WL12XX)
- ANT_U16 vendor_msg_len = ANT_UTILS_LEtoHost16((ANT_U8 *)&packet->vendor_header.vendor_msg_len);
- if (packet_len != vendor_msg_len + HCI_EVENT_TOTAL_OVERHEAD) {
- ANT_ERROR("HCI packet length (%d) should be %d bytes more than HCI payload length (%d)",
- packet_len, HCI_EVENT_TOTAL_OVERHEAD, vendor_msg_len);
- return -1;
- }
-#elif defined(BOARD_ANT_DEVICE_BCM433X)
- (void)packet_len; // unused warning
-#endif
-
- return 0;
-}
-
-/**
- * @param packet the struct to validate
- * @param packet_len the total length of the packet
- * @return -1 if not valid, or length of the ANT hci payload
- */
-static inline int validate_hci_event_packet(hci_event_packet_t *packet, int packet_len)
-{
- // Make sure we have at the minimum the hci header, vendor header, and ANT size/id bytes
- if (packet_len < HCI_EVENT_TOTAL_OVERHEAD) {
- ANT_ERROR("HCI packet length (%d) is less than minimum (%d)",
- packet_len, HCI_EVENT_TOTAL_OVERHEAD);
- return -1;
- }
-
- if (packet->packet_type != HCI_EVENT_PKT) {
- ANT_ERROR("HCI packet is not an event packet");
- return -1;
- }
-
- if (packet->event_header.evt != EVT_VENDOR) {
- ANT_ERROR("HCI packet is not a vendor event");
- return -1;
- }
-
- if (packet_len != packet->event_header.plen + HCI_EVENT_HEADER_OVERHEAD) {
- ANT_ERROR("HCI packet length (%d) should be %d bytes more than HCI event length (%d)",
- packet_len, HCI_EVENT_HDR_SIZE, packet->event_header.plen);
- return -1;
- }
-
- if (validate_hci_event_vendor(packet, packet_len) == -1)
- {
- return -1;
- }
- else
- {
- // return HCI payload len
- return packet_len - HCI_EVENT_TOTAL_OVERHEAD;
- }
-}
-
-#endif /* __ANT_HCIFRAMING_H */
diff --git a/src/bluez_hci/inc/ant_hciutils.h b/src/bluez_hci/inc/ant_hciutils.h
deleted file mode 100644
index d654ce9..0000000
--- a/src/bluez_hci/inc/ant_hciutils.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2009 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/******************************************************************************\
-*
-* FILE NAME: ant_hciutils.h
-*
-* BRIEF:
-* This file defines the utility functions for a Bluetooth HCI implementation
-*
-*
-\******************************************************************************/
-
-#ifndef __ANT_HCIUTILS_H
-#define __ANT_HCIUTILS_H
-
-#include <errno.h>
-#include <sys/socket.h>
-#include <bluetooth/bluetooth.h>
-#include <bluetooth/hci.h>
-
-#include "ant_log.h"
-// -------------------------------------------------
-
-static inline int create_hci_sock() {
- struct sockaddr_hci sa;
- int sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
- if (sk < 0)
- {
- ANT_ERROR("Failed to create bluetooth hci socket: %s", strerror(errno));
- }
- else
- {
- memset(&sa, 0, sizeof(sa));
- // sockaddr_hci changed from kernel 2.6.37 to 2.6.38 adding member hci_channel
- // In order to be backwards compatible set it to 0 if it exists (HCI_CHANNEL_RAW)
- sa.hci_family = AF_BLUETOOTH;
- sa.hci_dev = 0;
- if (bind(sk, (struct sockaddr *) &sa, sizeof(sa)) < 0)
- {
- ANT_ERROR("Failed to bind socket %#x to hci0: %s", sk, strerror(errno));
- close(sk);
- sk = -1;
- }
- }
- return sk;
-}
-
-#endif /* __ANT_HCIUTILS_H */
-
-
diff --git a/src/bluez_hci/inc/ant_rx.h b/src/bluez_hci/inc/ant_rx.h
deleted file mode 100644
index aff076d..0000000
--- a/src/bluez_hci/inc/ant_rx.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2009 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/******************************************************************************\
-*
-* FILE NAME: ant_rx.h
-*
-* BRIEF:
-* This file defines the receive thread function and the ANTHCIRxParams
-* type for storing the configuration of the receive thread.
-*
-*
-\******************************************************************************/
-
-#ifndef __ANT_OS_H
-#define __ANT_OS_H
-
-#include <pthread.h>
-#include "ant_types.h"
-#include "ant_native.h"
-
-// The configuration of a receive thread
-typedef struct
-{
- //The function to call back with received data
- ANTNativeANTEventCb pfRxCallback;
-
- //The function to call back with state changes
- ANTNativeANTStateCb pfStateCallback;
-
- //The thread object itself
- pthread_t thread;
-
-} ANTHCIRxParams;
-
-extern ANTHCIRxParams RxParams;
-
-//The message receive thread
-void* ANTHCIRxThread(void* pvHCIDevice);
-
-#endif /* __ANT_OS_H */
-
diff --git a/src/bluez_hci/inc/ant_tx.h b/src/bluez_hci/inc/ant_tx.h
deleted file mode 100644
index 0c85a5a..0000000
--- a/src/bluez_hci/inc/ant_tx.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2009 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/******************************************************************************\
-*
-* FILE NAME: ant_tx.h
-*
-* BRIEF:
-* This file defines the utility functions used by the transmit function.
-*
-*
-\******************************************************************************/
-
-#ifndef __ANT_TX_H
-#define __ANT_TX_H
-
-#include "ant_types.h"
-#include "ant_hciutils.h"
-
-int ant_open_tx_transport(void);
-void ant_close_tx_transport(int socket);
-ANT_BOOL wait_for_message(int socket);
-ANTStatus write_data(ANT_U8 ant_message[], int ant_message_len);
-
-ANTStatus get_command_complete_result(int socket);
-
-#endif /* __ANT_TX_H */
-
diff --git a/src/bt-vendor_vfs/Android.mk b/src/bt-vendor_vfs/Android.mk
deleted file mode 100644
index e6813d0..0000000
--- a/src/bt-vendor_vfs/Android.mk
+++ /dev/null
@@ -1,57 +0,0 @@
-#
-# Copyright (C) 2011 Dynastream Innovations
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-include $(CLEAR_VARS)
-
-LOCAL_CFLAGS := -g -c -W -Wall -O2
-
-# needed to pull in the header file for libbt-vendor.so
-BDROID_DIR:= external/bluetooth/bluedroid
-
-# Added hci/include to give access to the header for the libbt-vendorso interface.
-LOCAL_C_INCLUDES := \
- $(LOCAL_PATH)/src/common/inc \
- $(LOCAL_PATH)/$(ANT_DIR)/inc \
- $(BDROID_DIR)/hci/include \
-
-ifeq ($(BOARD_ANT_WIRELESS_DEVICE),"qualcomm-uart")
-LOCAL_C_INCLUDES += \
- $(LOCAL_PATH)/$(ANT_DIR)/qualcomm/uart \
-
-endif # BOARD_ANT_WIRELESS_DEVICE = "qualcomm-uart"
-
-LOCAL_SRC_FILES := \
- $(COMMON_DIR)/JAntNative.cpp \
- $(COMMON_DIR)/ant_utils.c \
- $(ANT_DIR)/ant_native_chardev.c \
- $(ANT_DIR)/ant_rx_chardev.c \
-
-# JNI
-LOCAL_C_INCLUDE += $(JNI_H_INCLUDE)
-
-LOCAL_SHARED_LIBRARIES += \
- libnativehelper \
-
-# logging and dll loading
-LOCAL_SHARED_LIBRARIES += \
- libcutils \
- libdl \
-
-LOCAL_MODULE_TAGS := optional
-LOCAL_PRELINK_MODULE := false
-LOCAL_MODULE := libantradio
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/src/bt-vendor_vfs/ant_native_chardev.c b/src/bt-vendor_vfs/ant_native_chardev.c
deleted file mode 100644
index a90c8c4..0000000
--- a/src/bt-vendor_vfs/ant_native_chardev.c
+++ /dev/null
@@ -1,1078 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2011 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/******************************************************************************\
-*
-* FILE NAME: ant_native_chardev.c
-*
-* BRIEF:
-* This file provides the VFS implementation of ant_native.h
-* VFS could be Character Device, TTY, etc.
-*
-*
-\******************************************************************************/
-
-#include <errno.h>
-#include <fcntl.h> /* for open() */
-#include <linux/ioctl.h> /* For hard reset */
-#include <pthread.h>
-#include <dlfcn.h> /* needed for runtime dll loading. */
-#include <stdint.h> /* for uint64_t */
-#include <sys/eventfd.h> /* For eventfd() */
-#include <unistd.h> /* for read(), write(), and close() */
-
-#include "ant_types.h"
-#include "ant_native.h"
-#include "ant_version.h"
-
-#include "antradio_power.h"
-#include "ant_rx_chardev.h"
-#include "ant_hci_defines.h"
-#include "ant_log.h"
-#include "bt_vendor_lib.h" /* used by qualcomms code to call into libbt-vendor.so */
-#include <cutils/properties.h> /* used by qualcomms additions for logging. */
-// The following functions are dummy implementations of the callbacks required by libbt-vendor.
-static void vendor_fwcfg_cb(bt_vendor_op_result_t result) {
-}
-static void vendor_scocfg_cb(bt_vendor_op_result_t result) {
-}
-static void vendor_lpm_vnd_cb(bt_vendor_op_result_t result) {
-}
-static void* vendor_alloc(int size) {
- return NULL;
-}
-static void vendor_dealloc(void *p_buf) {
-}
-static uint8_t vendor_xmit_cb(uint16_t opcode, void *p_buf, tINT_CMD_CBACK p_cback) {
- return 0;
-}
-static void vendor_epilog_cb(bt_vendor_op_result_t result) {
-}
-
-// This struct is used to regsiter the dummy callbacks with libbt-vendor
-bt_vendor_interface_t *vendor_interface=NULL;
-static const bt_vendor_callbacks_t vendor_callbacks = {
- sizeof(bt_vendor_callbacks_t),
- vendor_fwcfg_cb,
- vendor_scocfg_cb,
- vendor_lpm_vnd_cb,
- vendor_alloc,
- vendor_dealloc,
- vendor_xmit_cb,
- vendor_epilog_cb
-};
-
-#if ANT_HCI_SIZE_SIZE > 1
-#include "ant_utils.h" // Put HCI Size value across multiple bytes
-#endif
-
-#define MESG_BROADCAST_DATA_ID ((ANT_U8)0x4E)
-#define MESG_ACKNOWLEDGED_DATA_ID ((ANT_U8)0x4F)
-#define MESG_BURST_DATA_ID ((ANT_U8)0x50)
-#define MESG_EXT_BROADCAST_DATA_ID ((ANT_U8)0x5D)
-#define MESG_EXT_ACKNOWLEDGED_DATA_ID ((ANT_U8)0x5E)
-#define MESG_EXT_BURST_DATA_ID ((ANT_U8)0x5F)
-#define MESG_ADV_BURST_DATA_ID ((ANT_U8)0x72)
-
-static ant_rx_thread_info_t stRxThreadInfo;
-static pthread_mutex_t stEnabledStatusLock = PTHREAD_MUTEX_INITIALIZER;
-static pthread_mutex_t stFlowControlLock = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t stFlowControlCond = PTHREAD_COND_INITIALIZER;
-ANTNativeANTStateCb g_fnStateCallback;
-
-static const uint64_t EVENT_FD_PLUS_ONE = 1L;
-
-static void ant_channel_init(ant_channel_info_t *pstChnlInfo, const char *pcCharDevName);
-
-////////////////////////////////////////////////////////////////////
-// ant_init
-//
-// Initialises the native environment.
-//
-// Parameters:
-// -
-//
-// Returns:
-// ANT_STATUS_SUCCESS if intialize completed, else ANT_STATUS_FAILED
-//
-// Psuedocode:
-/*
-Set variables to defaults
-Initialise each supported path to chip
-Setup eventfd object.
-RESULT = ANT_STATUS_SUCCESS if no problems else ANT_STATUS_FAILED
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_init(void)
-{
- ANTStatus status = ANT_STATUS_FAILED;
- ANT_FUNC_START();
-
- stRxThreadInfo.stRxThread = 0;
- stRxThreadInfo.ucRunThread = 0;
- stRxThreadInfo.ucChipResetting = 0;
- stRxThreadInfo.pstEnabledStatusLock = &stEnabledStatusLock;
- g_fnStateCallback = 0;
-
-#ifdef ANT_DEVICE_NAME // Single transport path
- ant_channel_init(&stRxThreadInfo.astChannels[SINGLE_CHANNEL], ANT_DEVICE_NAME);
-#else // Separate data/command paths
- ant_channel_init(&stRxThreadInfo.astChannels[COMMAND_CHANNEL], ANT_COMMANDS_DEVICE_NAME);
- ant_channel_init(&stRxThreadInfo.astChannels[DATA_CHANNEL], ANT_DATA_DEVICE_NAME);
-#endif // Separate data/command paths
-
- // Make the eventfd. Want it non blocking so that we can easily reset it by reading.
- stRxThreadInfo.iRxShutdownEventFd = eventfd(0, EFD_NONBLOCK);
-
- // Check for error case
- if(stRxThreadInfo.iRxShutdownEventFd == -1)
- {
- ANT_ERROR("ANT init failed. Could not create event fd. Reason: %s", strerror(errno));
- } else {
- status = ANT_STATUS_SUCCESS;
- }
-
- ANT_FUNC_END();
- return status;
-}
-
-////////////////////////////////////////////////////////////////////
-// ant_deinit
-//
-// clean up eventfd object
-//
-// Parameters:
-// -
-//
-// Returns:
-// ANT_STATUS_SUCCESS
-//
-// Psuedocode:
-/*
-RESULT = SUCCESS
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_deinit(void)
-{
- ANTStatus result_status = ANT_STATUS_FAILED;
- ANT_FUNC_START();
-
- if(close(stRxThreadInfo.iRxShutdownEventFd) < 0)
- {
- ANT_ERROR("Could not close eventfd in deinit. Reason: %s", strerror(errno));
- } else {
- result_status = ANT_STATUS_SUCCESS;
- }
-
- ANT_FUNC_END();
- return result_status;
-}
-
-
-////////////////////////////////////////////////////////////////////
-// ant_enable_radio
-//
-// Powers on the ANT part and initialises the transport to the chip.
-// Changes occur in part implementing ant_enable() call
-//
-// Parameters:
-// -
-//
-// Returns:
-// Success:
-// ANT_STATUS_SUCCESS
-// Failures:
-// ANT_STATUS_TRANSPORT_INIT_ERR if could not enable
-// ANT_STATUS_FAILED if failed to get mutex or init rx thread
-//
-// Psuedocode:
-/*
-LOCK enable_LOCK
- State callback: STATE = ENABLING
- ant enable
- IF ant_enable success
- State callback: STATE = ENABLED
- RESULT = SUCCESS
- ELSE
- ant disable
- State callback: STATE = Current state
- RESULT = FAILURE
- ENDIF
-UNLOCK
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_enable_radio(void)
-{
- int iLockResult;
- ANTStatus result_status = ANT_STATUS_FAILED;
- ANT_FUNC_START();
-
- ANT_DEBUG_V("getting stEnabledStatusLock in %s", __FUNCTION__);
- iLockResult = pthread_mutex_lock(&stEnabledStatusLock);
- if(iLockResult) {
- ANT_ERROR("enable failed to get state lock: %s", strerror(iLockResult));
- goto out;
- }
- ANT_DEBUG_V("got stEnabledStatusLock in %s", __FUNCTION__);
-
- if (g_fnStateCallback) {
- g_fnStateCallback(RADIO_STATUS_ENABLING);
- }
-
- if (ant_enable() < 0) {
- ANT_ERROR("ant enable failed: %s", strerror(errno));
-
- ant_disable();
-
- if (g_fnStateCallback) {
- g_fnStateCallback(ant_radio_enabled_status());
- }
- } else {
- if (g_fnStateCallback) {
- g_fnStateCallback(RADIO_STATUS_ENABLED);
- }
-
- result_status = ANT_STATUS_SUCCESS;
- }
-
- ANT_DEBUG_V("releasing stEnabledStatusLock in %s", __FUNCTION__);
- pthread_mutex_unlock(&stEnabledStatusLock);
- ANT_DEBUG_V("released stEnabledStatusLock in %s", __FUNCTION__);
-
-out:
- ANT_FUNC_END();
- return result_status;
-}
-
-////////////////////////////////////////////////////////////////////
-// ant_radio_hard_reset
-//
-// IF SUPPORTED triggers a hard reset of the chip providing ANT functionality.
-//
-// Parameters:
-// -
-//
-// Returns:
-// Success:
-// ANT_STATUS_SUCCESS
-// Failures:
-// ANT_STATUS_NOT_SUPPORTED if the chip can't hard reset
-// ANT_STATUS_FAILED if failed to get mutex or enable
-//
-// Psuedocode:
-/*
-IF Hard Reset not supported
- RESULT = NOT SUPPORTED
-ELSE
- LOCK enable_LOCK
- IF Lock failed
- RESULT = FAILED
- ELSE
- Set Flag Rx thread that chip is resetting
- FOR each path to chip
- Send Reset IOCTL to path
- ENDFOR
- ant disable
- ant enable
- IF ant_enable success
- State callback: STATE = RESET
- RESULT = SUCCESS
- ELSE
- State callback: STATE = DISABLED
- RESULT = FAILURE
- ENDIF
- Clear Flag Rx thread that chip is resetting
- UNLOCK
-ENDIF
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_radio_hard_reset(void)
-{
- ANTStatus result_status = ANT_STATUS_NOT_SUPPORTED;
- ANT_FUNC_START();
-
-#ifdef ANT_IOCTL_RESET
- ant_channel_type eChannel;
- int iLockResult;
-
- result_status = ANT_STATUS_FAILED;
-
- ANT_DEBUG_V("getting stEnabledStatusLock in %s", __FUNCTION__);
- iLockResult = pthread_mutex_lock(&stEnabledStatusLock);
- if(iLockResult) {
- ANT_ERROR("enable failed to get state lock: %s", strerror(iLockResult));
- goto out;
- }
- ANT_DEBUG_V("got stEnabledStatusLock in %s", __FUNCTION__);
-
- stRxThreadInfo.ucChipResetting = 1;
- if (g_fnStateCallback)
- g_fnStateCallback(RADIO_STATUS_RESETTING);
-
-#ifdef ANT_IOCTL_RESET_PARAMETER
- ioctl(stRxThreadInfo.astChannels[0].iFd, ANT_IOCTL_RESET, ANT_IOCTL_RESET_PARAMETER);
-#else
- ioctl(stRxThreadInfo.astChannels[0].iFd, ANT_IOCTL_RESET);
-#endif // ANT_IOCTL_RESET_PARAMETER
-
- ant_disable();
-
- if (ant_enable()) { /* failed */
- if (g_fnStateCallback)
- g_fnStateCallback(RADIO_STATUS_DISABLED);
- } else { /* success */
- if (g_fnStateCallback)
- g_fnStateCallback(RADIO_STATUS_RESET);
- result_status = ANT_STATUS_SUCCESS;
- }
- stRxThreadInfo.ucChipResetting = 0;
-
- ANT_DEBUG_V("releasing stEnabledStatusLock in %s", __FUNCTION__);
- pthread_mutex_unlock(&stEnabledStatusLock);
- ANT_DEBUG_V("released stEnabledStatusLock in %s", __FUNCTION__);
-out:
-#endif // ANT_IOCTL_RESET
-
- ANT_FUNC_END();
- return result_status;
-}
-
-////////////////////////////////////////////////////////////////////
-// ant_disable_radio
-//
-// Powers off the ANT part and closes the transport to the chip.
-//
-// Parameters:
-// -
-//
-// Returns:
-// Success:
-// ANT_STATUS_SUCCESS
-// Failures:
-// ANT_STATUS_FAILED if failed to get mutex
-//
-// Psuedocode:
-/*
-LOCK enable_LOCK
- State callback: STATE = DISABLING
- ant disable
- State callback: STATE = Current state
- RESULT = SUCCESS
-UNLOCK
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_disable_radio(void)
-{
- int iLockResult;
- ANTStatus ret = ANT_STATUS_FAILED;
- ANT_FUNC_START();
-
- ANT_DEBUG_V("getting stEnabledStatusLock in %s", __FUNCTION__);
- iLockResult = pthread_mutex_lock(&stEnabledStatusLock);
- if(iLockResult) {
- ANT_ERROR("disable failed to get state lock: %s", strerror(iLockResult));
- goto out;
- }
- ANT_DEBUG_V("got stEnabledStatusLock in %s", __FUNCTION__);
-
- if (g_fnStateCallback) {
- g_fnStateCallback(RADIO_STATUS_DISABLING);
- }
-
- ant_disable();
-
- if (g_fnStateCallback) {
- g_fnStateCallback(ant_radio_enabled_status());
- }
-
- ret = ANT_STATUS_SUCCESS;
-
- ANT_DEBUG_V("releasing stEnabledStatusLock in %s", __FUNCTION__);
- pthread_mutex_unlock(&stEnabledStatusLock);
- ANT_DEBUG_V("released stEnabledStatusLock in %s", __FUNCTION__);
-
-out:
- ANT_FUNC_END();
- return ret;
-}
-
-////////////////////////////////////////////////////////////////////
-// ant_radio_enabled_status
-//
-// Gets the current chip/transport state; either disabled, disabling,
-// enabling, enabled, or resetting. Determines this on the fly by checking
-// if Rx thread is running and how many of the paths for the ANT chip have
-// open VFS files.
-//
-// Parameters:
-// -
-//
-// Returns:
-// The current radio status (ANTRadioEnabledStatus)
-//
-// Psuedocode:
-/*
-IF Thread Resetting Flag is set
- RESULT = Resetting
-ELSE
- COUNT the number of open files
- IF Thread Run Flag is Not Set
- IF there are open files OR Rx thread exists
- RESULT = Disabling
- ELSE
- RESULT = Disabled
- ENDIF
- ELSE
- IF All files are open (all paths) AND Rx thread exists
- RESULT = ENABLED
- ELSE IF there are open files (Not 0 open files) AND Rx thread exists
- RESULT = UNKNOWN
- ELSE (0 open files or Rx thread does not exist [while Thread Run set])
- RESULT = ENABLING
- ENDIF
- ENDIF
-ENDIF
-*/
-////////////////////////////////////////////////////////////////////
-ANTRadioEnabledStatus ant_radio_enabled_status(void)
-{
- ant_channel_type eChannel;
- int iOpenFiles = 0;
- int iOpenThread;
- ANTRadioEnabledStatus uiRet = RADIO_STATUS_UNKNOWN;
- ANT_FUNC_START();
-
- if (stRxThreadInfo.ucChipResetting) {
- uiRet = RADIO_STATUS_RESETTING;
- goto out;
- }
-
- for (eChannel = 0; eChannel < NUM_ANT_CHANNELS; eChannel++) {
- if (stRxThreadInfo.astChannels[eChannel].iFd != -1) {
- iOpenFiles++;
- }
- }
-
- iOpenThread = (stRxThreadInfo.stRxThread) ? 1 : 0;
-
- if (!stRxThreadInfo.ucRunThread) {
- if (iOpenFiles || iOpenThread) {
- uiRet = RADIO_STATUS_DISABLING;
- } else {
- uiRet = RADIO_STATUS_DISABLED;
- }
- } else {
- if ((iOpenFiles == NUM_ANT_CHANNELS) && iOpenThread) {
- uiRet = RADIO_STATUS_ENABLED;
- } else if (!iOpenFiles && iOpenThread) {
- uiRet = RADIO_STATUS_UNKNOWN;
- } else {
- uiRet = RADIO_STATUS_ENABLING;
- }
- }
-
-out:
- ANT_DEBUG_D("get radio enabled status returned %d", uiRet);
-
- ANT_FUNC_END();
- return uiRet;
-}
-
-////////////////////////////////////////////////////////////////////
-// set_ant_rx_callback
-//
-// Sets which function to call when an ANT message is received.
-//
-// Parameters:
-// rx_callback_func the ANTNativeANTEventCb function to be used for
-// received messages (from all transport paths).
-//
-// Returns:
-// ANT_STATUS_SUCCESS
-//
-// Psuedocode:
-/*
-FOR each transport path
- Path Rx Callback = rx_callback_func
-ENDFOR
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus set_ant_rx_callback(ANTNativeANTEventCb rx_callback_func)
-{
- ANTStatus status = ANT_STATUS_SUCCESS;
- ANT_FUNC_START();
-
-#ifdef ANT_DEVICE_NAME // Single transport path
- stRxThreadInfo.astChannels[SINGLE_CHANNEL].fnRxCallback = rx_callback_func;
-#else // Separate data/command paths
- stRxThreadInfo.astChannels[COMMAND_CHANNEL].fnRxCallback = rx_callback_func;
- stRxThreadInfo.astChannels[DATA_CHANNEL].fnRxCallback = rx_callback_func;
-#endif // Separate data/command paths
-
- ANT_FUNC_END();
- return status;
-}
-
-////////////////////////////////////////////////////////////////////
-// set_ant_state_callback
-//
-// Sets which function to call when an ANT state change occurs.
-//
-// Parameters:
-// state_callback_func the ANTNativeANTStateCb function to be used
-// for received state changes.
-//
-// Returns:
-// ANT_STATUS_SUCCESS
-//
-// Psuedocode:
-/*
- State Callback = state_callback_func
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus set_ant_state_callback(ANTNativeANTStateCb state_callback_func)
-{
- ANTStatus status = ANT_STATUS_SUCCESS;
- ANT_FUNC_START();
-
- g_fnStateCallback = state_callback_func;
-
- ANT_FUNC_END();
- return status;
-}
-
-////////////////////////////////////////////////////////////////////
-// ant_tx_message_flowcontrol_wait
-//
-// Sends an ANT message to the chip and waits for a CTS signal
-//
-// Parameters:
-// eTxPath device to transmit message on
-// eFlowMessagePath device that receives CTS
-// ucMessageLength the length of the message
-// pucMesg pointer to the message data
-//
-// Returns:
-// Success:
-// ANT_STATUS_SUCCESS
-// Failure:
-// ANT_STATUS_NOT_ENABLED
-//
-// Psuedocode:
-/*
- LOCK flow control
- IF Lock failed
- RESULT = FAILED
- ELSE
- SET flowMessagePath Flow Control response as FLOW_STOP
- WRITE txBuffer to txPath (only length of packet part)
- IF Wrote less then 0 bytes
- Log error
- RESULT = FAILED
- ELSE IF Didn't write 'length of packet' bytes
- Log error
- RESULT = FAILED
- ELSE
- IF flowMessagePath Flow Control response is not FLOW_GO
- WAIT until flowMessagePath Flow Control response is FLOW_GO, UNTIL FLOW_GO Wait Timeout seconds (10) from Now
- IF error Waiting
- IF error is Timeout
- RESULT = HARDWARE ERROR
- ELSE
- RESULT = FAILED
- ENDIF
- ELSE
- RESULT = SUCCESS
- ENDIF
- ELSE
- RESULT = SUCCESS;
- ENDIF
- ENDIF
- UNLOCK flow control
- ENDIF
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_tx_message_flowcontrol_wait(ant_channel_type eTxPath, ant_channel_type eFlowMessagePath, ANT_U8 ucMessageLength, ANT_U8 *pucTxMessage)
-{
- int iMutexResult;
- int iResult;
- struct timespec stTimeout;
- int iCondWaitResult;
- ANTStatus status = ANT_STATUS_FAILED;
- ANT_FUNC_START();
-
- ANT_DEBUG_V("getting stFlowControlLock in %s", __FUNCTION__);
- iMutexResult = pthread_mutex_lock(&stFlowControlLock);
- if (iMutexResult) {
- ANT_ERROR("failed to lock flow control mutex during tx: %s", strerror(iMutexResult));
- goto out;
- }
- ANT_DEBUG_V("got stFlowControlLock in %s", __FUNCTION__);
-
- stRxThreadInfo.astChannels[eFlowMessagePath].ucFlowControlResp = ANT_FLOW_STOP;
-
-#ifdef ANT_FLOW_RESEND
- // Store Tx message so can resend it from Rx thread
- stRxThreadInfo.astChannels[eFlowMessagePath].ucResendMessageLength = ucMessageLength;
- stRxThreadInfo.astChannels[eFlowMessagePath].pucResendMessage = pucTxMessage;
-#endif // ANT_FLOW_RESEND
-
- iResult = write(stRxThreadInfo.astChannels[eTxPath].iFd, pucTxMessage, ucMessageLength);
- if (iResult < 0) {
- ANT_ERROR("failed to write data message to device: %s", strerror(errno));
- } else if (iResult != ucMessageLength) {
- ANT_ERROR("bytes written and message size don't match up");
- } else {
- stTimeout.tv_sec = time(0) + ANT_FLOW_GO_WAIT_TIMEOUT_SEC;
- stTimeout.tv_nsec = 0;
-
- while (stRxThreadInfo.astChannels[eFlowMessagePath].ucFlowControlResp != ANT_FLOW_GO) {
- iCondWaitResult = pthread_cond_timedwait(&stFlowControlCond, &stFlowControlLock, &stTimeout);
- if (iCondWaitResult) {
- ANT_ERROR("failed to wait for flow control response: %s", strerror(iCondWaitResult));
-
- if (iCondWaitResult == ETIMEDOUT) {
- status = ANT_STATUS_HARDWARE_ERR;
-
-#ifdef ANT_FLOW_RESEND
- // Clear Tx message so will stop resending it from Rx thread
- stRxThreadInfo.astChannels[eFlowMessagePath].ucResendMessageLength = 0;
- stRxThreadInfo.astChannels[eFlowMessagePath].pucResendMessage = NULL;
-#endif // ANT_FLOW_RESEND
- }
- goto wait_error;
- }
- }
-
- status = ANT_STATUS_SUCCESS;
- }
-
-wait_error:
- ANT_DEBUG_V("releasing stFlowControlLock in %s", __FUNCTION__);
- pthread_mutex_unlock(&stFlowControlLock);
- ANT_DEBUG_V("released stFlowControlLock in %s", __FUNCTION__);
-
-out:
- ANT_FUNC_END();
- return status;
-}
-
-////////////////////////////////////////////////////////////////////
-// ant_tx_message_flowcontrol_none
-//
-// Sends an ANT message to the chip without waiting for flow control
-//
-// Parameters:
-// eTxPath device to transmit on
-// ucMessageLength the length of the message
-// pucMesg pointer to the message data
-//
-// Returns:
-// Success:
-// ANT_STATUS_SUCCESS
-// Failure:
-// ANT_STATUS_NOT_ENABLED
-//
-// Psuedocode:
-/*
- WRITE txBuffer to Tx Path (only length of packet part)
- IF Wrote less then 0 bytes
- Log error
- RESULT = FAILED
- ELSE IF Didn't write 'length of packet' bytes
- Log error
- RESULT = FAILED
- ELSE
- RESULT = SUCCESS
- ENDIF
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_tx_message_flowcontrol_none(ant_channel_type eTxPath, ANT_U8 ucMessageLength, ANT_U8 *pucTxMessage)
-{
- int iResult;
- ANTStatus status = ANT_STATUS_FAILED;\
- ANT_FUNC_START();
-
- iResult = write(stRxThreadInfo.astChannels[eTxPath].iFd, pucTxMessage, ucMessageLength);
- if (iResult < 0) {
- ANT_ERROR("failed to write message to device: %s", strerror(errno));
- } else if (iResult != ucMessageLength) {
- ANT_ERROR("bytes written and message size don't match up");
- } else {
- status = ANT_STATUS_SUCCESS;
- }
-
- ANT_FUNC_END();
- return status;
-}
-
-////////////////////////////////////////////////////////////////////
-// ant_tx_message
-//
-// Frames ANT data and decides which flow control method to use for sending the
-// ANT message to the chip
-//
-// Parameters:
-// ucLen the length of the message
-// pucMesg pointer to the message data
-//
-// Returns:
-// Success:
-// ANT_STATUS_SUCCESS
-// Failure:
-// ANT_STATUS_NOT_ENABLED
-//
-// Psuedocode:
-/*
-IF not enabled
- RESULT = BT NOT INITIALIZED
-ELSE
- Create txBuffer, MAX HCI Message Size large
- PUT ucLen in txBuffer AT ANT HCI Size Offset (0)
- COPY pucMesg to txBuffer AT ANT HCI Header Size (1) <- ? Not at offset?
- LOG txBuffer as a serial Tx (only length of packet part)
- IF is a data message
- Tx message on Data Path with FLOW_GO/FLOW_STOP flow control (ant_tx_message_flowcontrol_go_stop())
- ELSE
- Tx message on Command Path with no flow control (ant_tx_message_flowcontrol_none())
- ENDIF
-ENDIF
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_tx_message(ANT_U8 ucLen, ANT_U8 *pucMesg)
-{
- // During a tx we must prepend a packet type byte. Thus HCI_PACKET_TYPE_SIZE is added
- // to all offsets when writing into the tx buffer.
- ANTStatus status = ANT_STATUS_FAILED;
- // TODO ANT_HCI_MAX_MSG_SIZE is transport (driver) dependent.
- ANT_U8 txBuffer[HCI_PACKET_TYPE_SIZE + ANT_HCI_MAX_MSG_SIZE];
- // TODO Message length can be greater than ANT_U8 can hold.
- // Not changed as ANT_SERIAL takes length as ANT_U8.
- ANT_U8 txMessageLength = HCI_PACKET_TYPE_SIZE + ucLen + ANT_HCI_HEADER_SIZE;
- ANT_FUNC_START();
-
- if (ant_radio_enabled_status() != RADIO_STATUS_ENABLED) {
- status = ANT_STATUS_FAILED_BT_NOT_INITIALIZED;
- goto out;
- }
-
-#if ANT_HCI_OPCODE_SIZE == 1
- txBuffer[HCI_PACKET_TYPE_SIZE + ANT_HCI_OPCODE_OFFSET] = ANT_HCI_OPCODE_TX;
-#elif ANT_HCI_OPCODE_SIZE > 1
-#error "Specified ANT_HCI_OPCODE_SIZE not currently supported"
-#endif
-
-#if ANT_HCI_SIZE_SIZE == 1
- txBuffer[HCI_PACKET_TYPE_SIZE + ANT_HCI_SIZE_OFFSET] = ucLen;
-#elif ANT_HCI_SIZE_SIZE == 2
- ANT_UTILS_StoreLE16(txBuffer + HCI_PACKET_TYPE_SIZE + ANT_HCI_SIZE_OFFSET, (ANT_U16)ucLen);
-#else
-#error "Specified ANT_HCI_SIZE_SIZE not currently supported"
-#endif
-
- memcpy(txBuffer + HCI_PACKET_TYPE_SIZE + ANT_HCI_HEADER_SIZE, pucMesg, ucLen);
-
-// We no longer do the serial logging here because the packet type byte is not yet written.
-//ANT_SERIAL(txBuffer, txMessageLength, 'T');
-
-// We only do this if we are using single physical and logical channels.
-#if defined(ANT_DEVICE_NAME) && (HCI_PACKET_TYPE_SIZE == 0) // Single transport path
- ANT_SERIAL(txBuffer, txMessageLength, 'T');
- status = ant_tx_message_flowcontrol_wait(SINGLE_CHANNEL, SINGLE_CHANNEL, txMessageLength, txBuffer);
-#else // Separate data/command paths
- // Each path follows this structure:
- // write the packet type if needed.
- // log the packet
- // Send using the appropriate physical channel, waiting for flow control for data commands.
- switch (txBuffer[HCI_PACKET_TYPE_SIZE + ANT_HCI_DATA_OFFSET + ANT_MSG_ID_OFFSET]) {
- case MESG_BROADCAST_DATA_ID:
- case MESG_ACKNOWLEDGED_DATA_ID:
- case MESG_BURST_DATA_ID:
- case MESG_EXT_BROADCAST_DATA_ID:
- case MESG_EXT_ACKNOWLEDGED_DATA_ID:
- case MESG_EXT_BURST_DATA_ID:
- case MESG_ADV_BURST_DATA_ID:
- ANT_DEBUG_V("Data Path");
- #if HCI_PACKET_TYPE_SIZE == 1
- txBuffer[0] = ANT_DATA_TYPE_PACKET;
- #elif HCI_PACKET_TYPE_SIZE > 1
- #error "Specified HCI_PACKET_TYPE_SIZE not supported"
- #endif
- ANT_SERIAL(txBuffer, txMessageLength, 'T');
- #ifdef ANT_DEVICE_NAME
- status = ant_tx_message_flowcontrol_wait(SINGLE_CHANNEL, SINGLE_CHANNEL, txMessageLength, txBuffer);
- #else
- status = ant_tx_message_flowcontrol_wait(DATA_CHANNEL, COMMAND_CHANNEL, txMessageLength, txBuffer);
- #endif
- break;
- default:
- ANT_DEBUG_V("Control Path");
- #if HCI_PACKET_TYPE_SIZE == 1
- txBuffer[0] = ANT_CMD_TYPE_PACKET;
- #elif HCI_PACKET_TYPE_SIZE > 1
- #error "Specified HCI_PACKET_TYPE_SIZE not supported"
- #endif
- ANT_SERIAL(txBuffer, txMessageLength, 'T');
- #ifdef ANT_DEVICE_NAME
- status = ant_tx_message_flowcontrol_none(SINGLE_CHANNEL, txMessageLength, txBuffer);
- #else
- status = ant_tx_message_flowcontrol_none(COMMAND_CHANNEL, txMessageLength, txBuffer);
- #endif
- }
-#endif // Separate data/command paths
-
-out:
- ANT_FUNC_END();
- return status;
-}
-
-//----------------- TODO Move these somewhere for multi transport path / dedicated channel support:
-
-static void ant_channel_init(ant_channel_info_t *pstChnlInfo, const char *pcCharDevName)
-{
- ANT_FUNC_START();
-
- // TODO Don't need to store, only accessed when trying to open:
- // Is however useful for logs.
- pstChnlInfo->pcDevicePath = pcCharDevName;
-
- // This is the only piece of info that needs to be stored per channel
- pstChnlInfo->iFd = -1;
-
- // TODO Only 1 of these (not per-channel) is actually ever used:
- pstChnlInfo->fnRxCallback = NULL;
- pstChnlInfo->ucFlowControlResp = ANT_FLOW_GO;
-#ifdef ANT_FLOW_RESEND
- pstChnlInfo->ucResendMessageLength = 0;
- pstChnlInfo->pucResendMessage = NULL;
-#endif // ANT_FLOW_RESEND
- // TODO Only used when Flow Control message received, so must only be Command path Rx thread
- pstChnlInfo->pstFlowControlCond = &stFlowControlCond;
- pstChnlInfo->pstFlowControlLock = &stFlowControlLock;
-
- ANT_FUNC_END();
-}
-
-// This function is used as an alternative to opening the char device directly.
-// It is needed as libbt-vendor does the power up/down control for us when we open/close the file descriptor.
-int init_transport_bdroid(int on) {
-
- void *so_handle;
- unsigned char bdaddr[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
- int fd[CH_MAX], powerstate, ret;
-
- if (on) {
- so_handle = dlopen("libbt-vendor.so", RTLD_NOW);
- if (!so_handle)
- {
- ALOGE("Failed to load vendor component");
- return -1;
- }
-
- vendor_interface = (bt_vendor_interface_t *) dlsym(so_handle, "BLUETOOTH_VENDOR_LIB_INTERFACE");
- if (!vendor_interface)
- {
- ALOGE("Failed to accesst bt vendor interface");
- return -1;
- }
-
- vendor_interface->init(&vendor_callbacks, bdaddr);
-
- ALOGI("Turn On BT power");
- powerstate = BT_VND_PWR_ON;
- ret = vendor_interface->op(BT_VND_OP_POWER_CTRL, &powerstate);
- if (ret < 0)
- {
- ALOGE("Failed to turn on power from bt vendor interface");
- return -1;
- }
- /*call ANT_USERIAL_OPEN to get ANT handle*/
- ret = vendor_interface->op(BT_VND_OP_ANT_USERIAL_OPEN, fd);
- ALOGE("ret value: %d", ret);
- if (ret != 1)
- {
- ALOGE("Failed to get fd from bt vendor interface");
- return -1;
- } else {
- ALOGE("FD: %x", fd[0]);
- return fd[0];
- }
- } else {
- if (vendor_interface) {
- ALOGE("Close and cleanup the interfaces");
- int ret = vendor_interface->op(BT_VND_OP_ANT_USERIAL_CLOSE, NULL);
-
- ALOGE("ret value: %d", ret);
- ALOGI("Turn off BT power");
- powerstate = BT_VND_PWR_OFF;
- ret = vendor_interface->op(BT_VND_OP_POWER_CTRL, &powerstate);
- if (ret < 0)
- {
- ALOGE("Failed to turn off power from bt vendor interface");
- return -1;
- }
- vendor_interface->cleanup();
- vendor_interface = NULL;
- return 0;
- } else {
-
- ALOGE("Not able to find vendor interface handle");
- return -1;
- }
- }
-}
-
-static void ant_disable_channel(ant_channel_info_t *pstChnlInfo)
-{
- ANT_FUNC_START();
- if (!pstChnlInfo) {
- ANT_ERROR("null channel info passed to channel disable function");
- goto out;
- }
- if (pstChnlInfo->iFd != -1) {
- // Use the new init_transport function instead of open() to get our fd.
- if (init_transport_bdroid(0) < 0) {
- ANT_ERROR("failed to close channel %s(%#x): %s", pstChnlInfo->pcDevicePath, pstChnlInfo->iFd, strerror(errno));
- }
-
- pstChnlInfo->iFd = -1; //TODO can this overwrite a still valid fd?
- } else {
- ANT_DEBUG_D("%s file is already closed", pstChnlInfo->pcDevicePath);
- }
-
-out:
- ANT_FUNC_END();
-}
-
-static int ant_enable_channel(ant_channel_info_t *pstChnlInfo)
-{
- int iRet = -1;
- ANT_FUNC_START();
- if (!pstChnlInfo) {
- ANT_ERROR("null channel info passed to channel enable function");
- errno = EINVAL;
- goto out;
- }
- if (pstChnlInfo->iFd == -1) {
- // Use the init_transport function to release our fd instead of close()
- pstChnlInfo->iFd = init_transport_bdroid(1);
- if (pstChnlInfo->iFd < 0) {
- ANT_ERROR("failed to open dev %s: %s", pstChnlInfo->pcDevicePath, strerror(errno));
- goto out;
- }
- } else {
- ANT_DEBUG_D("%s is already enabled", pstChnlInfo->pcDevicePath);
- }
- iRet = 0;
-out:
- ANT_FUNC_END();
- return iRet;
-}
-
-//----------------------------------------------------------------------- This is antradio_power.h:
-
-int ant_enable(void)
-{
- int iRet = -1;
- ant_channel_type eChannel;
- ANT_FUNC_START();
-
- // Reset the shutdown signal.
- uint64_t counter;
- ssize_t result = read(stRxThreadInfo.iRxShutdownEventFd, &counter, sizeof(counter));
- // EAGAIN result indicates that the counter was already 0 in non-blocking mode.
- if(result < 0 && errno != EAGAIN)
- {
- ANT_ERROR("Could not clear shutdown signal in enable. Reason: %s", strerror(errno));
- goto out;
- }
-
- stRxThreadInfo.ucRunThread = 1;
-
- for (eChannel = 0; eChannel < NUM_ANT_CHANNELS; eChannel++) {
- if (ant_enable_channel(&stRxThreadInfo.astChannels[eChannel]) < 0) {
- ANT_ERROR("failed to enable channel %s: %s",
- stRxThreadInfo.astChannels[eChannel].pcDevicePath,
- strerror(errno));
- goto out;
- }
- }
-
- if (stRxThreadInfo.stRxThread == 0) {
- if (pthread_create(&stRxThreadInfo.stRxThread, NULL, fnRxThread, &stRxThreadInfo) < 0) {
- ANT_ERROR("failed to start rx thread: %s", strerror(errno));
- goto out;
- }
- } else {
- ANT_DEBUG_D("rx thread is already running");
- }
-
- if (!stRxThreadInfo.ucRunThread) {
- ANT_ERROR("rx thread crashed during init");
- goto out;
- }
-
- iRet = 0;
-
-out:
- ANT_FUNC_END();
- return iRet;
-}
-
-int ant_disable(void)
-{
- int iRet = -1;
- ant_channel_type eChannel;
- ANT_FUNC_START();
-
- stRxThreadInfo.ucRunThread = 0;
-
- if (stRxThreadInfo.stRxThread != 0) {
- ANT_DEBUG_I("Sending shutdown signal to rx thread.");
- if(write(stRxThreadInfo.iRxShutdownEventFd, &EVENT_FD_PLUS_ONE, sizeof(EVENT_FD_PLUS_ONE)) < 0)
- {
- ANT_ERROR("failed to signal rx thread with eventfd. Reason: %s", strerror(errno));
- goto out;
- }
- ANT_DEBUG_I("Waiting for rx thread to finish.");
- if (pthread_join(stRxThreadInfo.stRxThread, NULL) < 0) {
- ANT_ERROR("failed to join rx thread: %s", strerror(errno));
- goto out;
- }
- } else {
- ANT_DEBUG_D("rx thread is not running");
- }
-
- for (eChannel = 0; eChannel < NUM_ANT_CHANNELS; eChannel++) {
- ant_disable_channel(&stRxThreadInfo.astChannels[eChannel]);
- }
-
- iRet = 0;
-
-out:
- stRxThreadInfo.stRxThread = 0;
- ANT_FUNC_END();
- return iRet;
-}
-
-//---------------------------------------------------------
-
-const char *ant_get_lib_version()
-{
- return "libantradio.so: "ANT_CHIP_NAME". Version "
- LIBANT_STACK_MAJOR"."LIBANT_STACK_MINOR"."LIBANT_STACK_INCRE;
-}
diff --git a/src/bt-vendor_vfs/ant_rx_chardev.c b/src/bt-vendor_vfs/ant_rx_chardev.c
deleted file mode 100644
index 69656b2..0000000
--- a/src/bt-vendor_vfs/ant_rx_chardev.c
+++ /dev/null
@@ -1,464 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2011 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/******************************************************************************\
-*
-* FILE NAME: ant_rx_chardev.c
-*
-* BRIEF:
-* This file implements the receive thread function which will loop reading
-* ANT messages until told to exit.
-*
-*
-\******************************************************************************/
-
-#include <errno.h>
-#include <poll.h>
-#include <pthread.h>
-#include <stdint.h> /* for uint64_t */
-
-#include "ant_types.h"
-#include "antradio_power.h"
-#include "ant_rx_chardev.h"
-#include "ant_hci_defines.h"
-#include "ant_log.h"
-#include "ant_native.h" // ANT_HCI_MAX_MSG_SIZE, ANT_MSG_ID_OFFSET, ANT_MSG_DATA_OFFSET,
- // ant_radio_enabled_status()
-
-extern ANTStatus ant_tx_message_flowcontrol_none(ant_channel_type eTxPath, ANT_U8 ucMessageLength, ANT_U8 *pucTxMessage);
-
-#undef LOG_TAG
-#define LOG_TAG "antradio_rx"
-
-#define ANT_POLL_TIMEOUT ((int)30000)
-#define KEEPALIVE_TIMEOUT ((int)5000)
-
-static ANT_U8 aucRxBuffer[NUM_ANT_CHANNELS][ANT_HCI_MAX_MSG_SIZE];
-
-#ifdef ANT_DEVICE_NAME // Single transport path
- static int iRxBufferLength[NUM_ANT_CHANNELS] = {0};
-#else
- static int iRxBufferLength[NUM_ANT_CHANNELS] = {0, 0};
-#endif //
-
-// Defines for use with the poll() call
-#define EVENT_DATA_AVAILABLE (POLLIN|POLLRDNORM)
-#define EVENT_CHIP_SHUTDOWN (POLLHUP)
-#define EVENT_HARD_RESET (POLLERR|POLLPRI|POLLRDHUP)
-
-#define EVENTS_TO_LISTEN_FOR (EVENT_DATA_AVAILABLE|EVENT_CHIP_SHUTDOWN|EVENT_HARD_RESET)
-
-// Plus one is for the eventfd shutdown signal.
-#define NUM_POLL_FDS (NUM_ANT_CHANNELS + 1)
-#define EVENTFD_IDX NUM_ANT_CHANNELS
-
-static ANT_U8 KEEPALIVE_MESG[] = {0x01, 0x00, 0x00};
-static ANT_U8 KEEPALIVE_RESP[] = {0x03, 0x40, 0x00, 0x00, 0x28};
-
-void doReset(ant_rx_thread_info_t *stRxThreadInfo);
-int readChannelMsg(ant_channel_type eChannel, ant_channel_info_t *pstChnlInfo);
-
-/*
- * Function to check that all given flags are set in a particular value.
- * Designed for use with the revents field of pollfds filled out by poll().
- *
- * Parameters:
- * - value: The value that will be checked to contain all flags.
- * - flags: Bitwise-or of the flags that value should be checked for.
- *
- * Returns:
- * - true IFF all the bits that are set in 'flags' are also set in 'value'
- */
-ANT_BOOL areAllFlagsSet(short value, short flags)
-{
- value &= flags;
- return (value == flags);
-}
-
-/*
- * This thread is run occasionally as a detached thread in order to send a keepalive message to the
- * chip.
- */
-void *fnKeepAliveThread(void *unused)
-{
- ANT_DEBUG_V("Sending dummy keepalive message.");
- ant_tx_message(sizeof(KEEPALIVE_MESG)/sizeof(ANT_U8), KEEPALIVE_MESG);
- return NULL;
-}
-
-/*
- * This thread waits for ANT messages from a VFS file.
- */
-void *fnRxThread(void *ant_rx_thread_info)
-{
- int iMutexLockResult;
- int iPollRet;
- ant_rx_thread_info_t *stRxThreadInfo;
- struct pollfd astPollFd[NUM_POLL_FDS];
- ant_channel_type eChannel;
- ANT_FUNC_START();
-
- stRxThreadInfo = (ant_rx_thread_info_t *)ant_rx_thread_info;
- for (eChannel = 0; eChannel < NUM_ANT_CHANNELS; eChannel++) {
- astPollFd[eChannel].fd = stRxThreadInfo->astChannels[eChannel].iFd;
- astPollFd[eChannel].events = EVENTS_TO_LISTEN_FOR;
- }
- // Fill out poll request for the shutdown signaller.
- astPollFd[EVENTFD_IDX].fd = stRxThreadInfo->iRxShutdownEventFd;
- astPollFd[EVENTFD_IDX].events = POLL_IN;
-
- // Reset the waiting for response, since we don't want a stale value if we were reset.
- stRxThreadInfo->bWaitingForKeepaliveResponse = ANT_FALSE;
-
- /* continue running as long as not terminated */
- while (stRxThreadInfo->ucRunThread) {
- /* Wait for data available on any file (transport path), shorter wait if we just timed out. */
- int timeout = stRxThreadInfo->bWaitingForKeepaliveResponse ? KEEPALIVE_TIMEOUT : ANT_POLL_TIMEOUT;
- iPollRet = poll(astPollFd, NUM_POLL_FDS, timeout);
- if (!iPollRet) {
- if(!stRxThreadInfo->bWaitingForKeepaliveResponse)
- {
- stRxThreadInfo->bWaitingForKeepaliveResponse = ANT_TRUE;
- // Keep alive is done on a separate thread so that rxThread can handle flow control during
- // the message.
- pthread_t thread;
- // Don't care if it failed as the consequence is just a missed keep-alive.
- pthread_create(&thread, NULL, fnKeepAliveThread, NULL);
- // Detach the thread so that we don't need to join it later.
- pthread_detach(thread);
- ANT_DEBUG_V("poll timed out, checking exit cond");
- } else
- {
- ANT_DEBUG_E("No response to keepalive, attempting recovery.");
- doReset(stRxThreadInfo);
- goto out;
- }
- } else if (iPollRet < 0) {
- ANT_ERROR("unhandled error: %s, attempting recovery.", strerror(errno));
- doReset(stRxThreadInfo);
- goto out;
- } else {
- for (eChannel = 0; eChannel < NUM_ANT_CHANNELS; eChannel++) {
- if (areAllFlagsSet(astPollFd[eChannel].revents, EVENT_HARD_RESET)) {
- ANT_ERROR("Hard reset indicated by %s. Attempting recovery.",
- stRxThreadInfo->astChannels[eChannel].pcDevicePath);
- doReset(stRxThreadInfo);
- goto out;
- } else if (areAllFlagsSet(astPollFd[eChannel].revents, EVENT_CHIP_SHUTDOWN)) {
- /* chip reported it was unexpectedly disabled */
- ANT_DEBUG_D(
- "poll hang-up from %s. exiting rx thread", stRxThreadInfo->astChannels[eChannel].pcDevicePath);
-
- doReset(stRxThreadInfo);
- goto out;
- } else if (areAllFlagsSet(astPollFd[eChannel].revents, EVENT_DATA_AVAILABLE)) {
- ANT_DEBUG_D("data on %s. reading it",
- stRxThreadInfo->astChannels[eChannel].pcDevicePath);
-
- // Doesn't matter what data we received, we know the chip is alive.
- stRxThreadInfo->bWaitingForKeepaliveResponse = ANT_FALSE;
-
- if (readChannelMsg(eChannel, &stRxThreadInfo->astChannels[eChannel]) < 0) {
- // set flag to exit out of Rx Loop
- stRxThreadInfo->ucRunThread = 0;
- }
- } else if (areAllFlagsSet(astPollFd[eChannel].revents, POLLNVAL)) {
- ANT_ERROR("poll was called on invalid file descriptor %s. Attempting recovery.",
- stRxThreadInfo->astChannels[eChannel].pcDevicePath);
- doReset(stRxThreadInfo);
- goto out;
- } else if (areAllFlagsSet(astPollFd[eChannel].revents, POLLERR)) {
- ANT_ERROR("Unknown error from %s. Attempting recovery.",
- stRxThreadInfo->astChannels[eChannel].pcDevicePath);
- doReset(stRxThreadInfo);
- goto out;
- } else if (astPollFd[eChannel].revents) {
- ANT_DEBUG_W("unhandled poll result %#x from %s",
- astPollFd[eChannel].revents,
- stRxThreadInfo->astChannels[eChannel].pcDevicePath);
- }
- }
- // Now check for shutdown signal
- if(areAllFlagsSet(astPollFd[EVENTFD_IDX].revents, POLLIN))
- {
- ANT_DEBUG_I("rx thread caught shutdown signal.");
- // reset the counter by reading.
- uint64_t counter;
- read(stRxThreadInfo->iRxShutdownEventFd, &counter, sizeof(counter));
- // don't care if read error, going to close the thread anyways.
- stRxThreadInfo->ucRunThread = 0;
- } else if (astPollFd[EVENTFD_IDX].revents != 0) {
- ANT_ERROR("Shutdown event descriptor had unexpected event: %#x. exiting rx thread.",
- astPollFd[EVENTFD_IDX].revents);
- stRxThreadInfo->ucRunThread = 0;
- }
- }
- }
-
- /* disable ANT radio if not already disabling */
- // Try to get stEnabledStatusLock.
- // if you get it then no one is enabling or disabling
- // if you can't get it assume something made you exit
- ANT_DEBUG_V("try getting stEnabledStatusLock in %s", __FUNCTION__);
- iMutexLockResult = pthread_mutex_trylock(stRxThreadInfo->pstEnabledStatusLock);
- if (!iMutexLockResult) {
- ANT_DEBUG_V("got stEnabledStatusLock in %s", __FUNCTION__);
- ANT_WARN("rx thread has unexpectedly crashed, cleaning up");
-
- // spoof our handle as closed so we don't try to join ourselves in disable
- stRxThreadInfo->stRxThread = 0;
-
- if (g_fnStateCallback) {
- g_fnStateCallback(RADIO_STATUS_DISABLING);
- }
-
- ant_disable();
-
- if (g_fnStateCallback) {
- g_fnStateCallback(ant_radio_enabled_status());
- }
-
- ANT_DEBUG_V("releasing stEnabledStatusLock in %s", __FUNCTION__);
- pthread_mutex_unlock(stRxThreadInfo->pstEnabledStatusLock);
- ANT_DEBUG_V("released stEnabledStatusLock in %s", __FUNCTION__);
- } else if (iMutexLockResult != EBUSY) {
- ANT_ERROR("rx thread closing code, trylock on state lock failed: %s",
- strerror(iMutexLockResult));
- } else {
- ANT_DEBUG_V("stEnabledStatusLock busy");
- }
-
- out:
- ANT_FUNC_END();
-#ifdef ANDROID
- return NULL;
-#endif
-}
-
-void doReset(ant_rx_thread_info_t *stRxThreadInfo)
-{
- int iMutexLockResult;
-
- ANT_FUNC_START();
- /* Chip was reset or other error, only way to recover is to
- * close and open ANT chardev */
- stRxThreadInfo->ucChipResetting = 1;
-
- if (g_fnStateCallback) {
- g_fnStateCallback(RADIO_STATUS_RESETTING);
- }
-
- stRxThreadInfo->ucRunThread = 0;
-
- ANT_DEBUG_V("getting stEnabledStatusLock in %s", __FUNCTION__);
- iMutexLockResult = pthread_mutex_lock(stRxThreadInfo->pstEnabledStatusLock);
- if (iMutexLockResult < 0) {
- ANT_ERROR("chip was reset, getting state mutex failed: %s",
- strerror(iMutexLockResult));
- stRxThreadInfo->stRxThread = 0;
- stRxThreadInfo->ucChipResetting = 0;
- } else {
- ANT_DEBUG_V("got stEnabledStatusLock in %s", __FUNCTION__);
-
- stRxThreadInfo->stRxThread = 0; /* spoof our handle as closed so we don't
- * try to join ourselves in disable */
-
- ant_disable();
-
- int enableResult = ant_enable();
-
- stRxThreadInfo->ucChipResetting = 0;
- if (enableResult) { /* failed */
- if (g_fnStateCallback) {
- g_fnStateCallback(RADIO_STATUS_DISABLED);
- }
- } else { /* success */
- if (g_fnStateCallback) {
- g_fnStateCallback(RADIO_STATUS_RESET);
- }
- }
-
- ANT_DEBUG_V("releasing stEnabledStatusLock in %s", __FUNCTION__);
- pthread_mutex_unlock(stRxThreadInfo->pstEnabledStatusLock);
- ANT_DEBUG_V("released stEnabledStatusLock in %s", __FUNCTION__);
- }
-
- ANT_FUNC_END();
-}
-
-////////////////////////////////////////////////////////////////////
-// setFlowControl
-//
-// Sets the flow control "flag" to the value provided and signals the transmit
-// thread to check the value.
-//
-// Parameters:
-// pstChnlInfo the details of the channel being updated
-// ucFlowSetting the value to use
-//
-// Returns:
-// Success:
-// 0
-// Failure:
-// -1
-////////////////////////////////////////////////////////////////////
-int setFlowControl(ant_channel_info_t *pstChnlInfo, ANT_U8 ucFlowSetting)
-{
- int iRet = -1;
- int iMutexResult;
- ANT_FUNC_START();
-
- ANT_DEBUG_V("getting stFlowControlLock in %s", __FUNCTION__);
- iMutexResult = pthread_mutex_lock(pstChnlInfo->pstFlowControlLock);
- if (iMutexResult) {
- ANT_ERROR("failed to lock flow control mutex during response: %s", strerror(iMutexResult));
- } else {
- ANT_DEBUG_V("got stFlowControlLock in %s", __FUNCTION__);
-
- pstChnlInfo->ucFlowControlResp = ucFlowSetting;
-
- ANT_DEBUG_V("releasing stFlowControlLock in %s", __FUNCTION__);
- pthread_mutex_unlock(pstChnlInfo->pstFlowControlLock);
- ANT_DEBUG_V("released stFlowControlLock in %s", __FUNCTION__);
-
- pthread_cond_signal(pstChnlInfo->pstFlowControlCond);
-
- iRet = 0;
- }
-
- ANT_FUNC_END();
- return iRet;
-}
-
-int readChannelMsg(ant_channel_type eChannel, ant_channel_info_t *pstChnlInfo)
-{
- int iRet = -1;
- int iRxLenRead;
- int iCurrentHciPacketOffset;
- int iHciDataSize;
- ANT_FUNC_START();
-
- // Keep trying to read while there is an error, and that error is EAGAIN
- while (((iRxLenRead = read(pstChnlInfo->iFd, &aucRxBuffer[eChannel][iRxBufferLength[eChannel]], (sizeof(aucRxBuffer[eChannel]) - iRxBufferLength[eChannel]))) < 0)
- && errno == EAGAIN)
- ;
-
- if (iRxLenRead < 0) {
- if (errno == ENODEV) {
- ANT_ERROR("%s not enabled, exiting rx thread",
- pstChnlInfo->pcDevicePath);
-
- goto out;
- } else if (errno == ENXIO) {
- ANT_ERROR("%s there is no physical ANT device connected",
- pstChnlInfo->pcDevicePath);
-
- goto out;
- } else {
- ANT_ERROR("%s read thread exiting, unhandled error: %s",
- pstChnlInfo->pcDevicePath, strerror(errno));
-
- goto out;
- }
- } else {
- ANT_SERIAL(aucRxBuffer[eChannel], iRxLenRead, 'R');
-
- iRxLenRead += iRxBufferLength[eChannel]; // add existing data on
-
- // if we didn't get a full packet, then just exit
- if (iRxLenRead < (aucRxBuffer[eChannel][ANT_HCI_SIZE_OFFSET] + ANT_HCI_HEADER_SIZE + ANT_HCI_FOOTER_SIZE)) {
- iRxBufferLength[eChannel] = iRxLenRead;
- iRet = 0;
- goto out;
- }
-
- iRxBufferLength[eChannel] = 0; // reset buffer length here since we should have a full packet
-
-#if ANT_HCI_OPCODE_SIZE == 1 // Check the different message types by opcode
- ANT_U8 opcode = aucRxBuffer[eChannel][ANT_HCI_OPCODE_OFFSET];
-
- if(ANT_HCI_OPCODE_COMMAND_COMPLETE == opcode) {
- // Command Complete, so signal a FLOW_GO
- if(setFlowControl(pstChnlInfo, ANT_FLOW_GO)) {
- goto out;
- }
- } else if(ANT_HCI_OPCODE_FLOW_ON == opcode) {
- // FLow On, so resend the last Tx
-#ifdef ANT_FLOW_RESEND
- // Check if there is a message to resend
- if(pstChnlInfo->ucResendMessageLength > 0) {
- ant_tx_message_flowcontrol_none(eChannel, pstChnlInfo->ucResendMessageLength, pstChnlInfo->pucResendMessage);
- } else {
- ANT_DEBUG_D("Resend requested by chip, but tx request cancelled");
- }
-#endif // ANT_FLOW_RESEND
- } else if(ANT_HCI_OPCODE_ANT_EVENT == opcode)
- // ANT Event, send ANT packet to Rx Callback
-#endif // ANT_HCI_OPCODE_SIZE == 1
- {
- // Received an ANT packet
- iCurrentHciPacketOffset = 0;
-
- while(iCurrentHciPacketOffset < iRxLenRead) {
-
- // TODO Allow HCI Packet Size value to be larger than 1 byte
- // This currently works as no size value is greater than 255, and little endian
- iHciDataSize = aucRxBuffer[eChannel][iCurrentHciPacketOffset + ANT_HCI_SIZE_OFFSET];
-
- if ((iHciDataSize + ANT_HCI_HEADER_SIZE + ANT_HCI_FOOTER_SIZE + iCurrentHciPacketOffset) >
- iRxLenRead) {
- // we don't have a whole packet
- iRxBufferLength[eChannel] = iRxLenRead - iCurrentHciPacketOffset;
- memcpy(aucRxBuffer[eChannel], &aucRxBuffer[eChannel][iCurrentHciPacketOffset], iRxBufferLength[eChannel]);
- // the increment at the end should push us out of the while loop
- } else
-#ifdef ANT_MESG_FLOW_CONTROL
- if (aucRxBuffer[eChannel][iCurrentHciPacketOffset + ANT_HCI_DATA_OFFSET + ANT_MSG_ID_OFFSET] ==
- ANT_MESG_FLOW_CONTROL) {
- // This is a flow control packet, not a standard ANT message
- if(setFlowControl(pstChnlInfo, \
- aucRxBuffer[eChannel][iCurrentHciPacketOffset + ANT_HCI_DATA_OFFSET + ANT_MSG_DATA_OFFSET])) {
- goto out;
- }
- } else
-#endif // ANT_MESG_FLOW_CONTROL
- {
- ANT_U8 *msg = aucRxBuffer[eChannel] + iCurrentHciPacketOffset + ANT_HCI_DATA_OFFSET;
- ANT_BOOL bIsKeepAliveResponse = memcmp(msg, KEEPALIVE_RESP, sizeof(KEEPALIVE_RESP)/sizeof(ANT_U8)) == 0;
- if (bIsKeepAliveResponse) {
- ANT_DEBUG_V("Filtered out keepalive response.");
- } else if (pstChnlInfo->fnRxCallback != NULL) {
-
- // Loop through read data until all HCI packets are written to callback
- pstChnlInfo->fnRxCallback(iHciDataSize, \
- msg);
- } else {
- ANT_WARN("%s rx callback is null", pstChnlInfo->pcDevicePath);
- }
- }
-
- iCurrentHciPacketOffset = iCurrentHciPacketOffset + ANT_HCI_HEADER_SIZE + ANT_HCI_FOOTER_SIZE + iHciDataSize;
- }
- }
-
- iRet = 0;
- }
-
-out:
- ANT_FUNC_END();
- return iRet;
-}
diff --git a/src/bt-vendor_vfs/inc/ant_hci_defines.h b/src/bt-vendor_vfs/inc/ant_hci_defines.h
deleted file mode 100644
index 3ffe672..0000000
--- a/src/bt-vendor_vfs/inc/ant_hci_defines.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2013 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*******************************************************************************\
-*
-* FILE NAME: ant_hci_defines.h
-*
-* BRIEF:
-* This file defines ANT specific HCI values used by the ANT chip that are
-* not specific to the underlying chip. These should not need to be modified,
-* but should be verified they are correct.
-*
-\*******************************************************************************/
-
-#ifndef __VFS_INDEPENDENT_H
-#define __VFS_INDEPENDENT_H
-
-// ANT HCI Packet Structure
-// -----------------------------------------
-// | Header | Data | Footer |
-// |----------------------|-----------------|
-// |Optional| Data | Opt. | ... | Optional |
-// | Opcode | Size | Sync | | Checksum |
-// Data may include any number of ANT packets, with no sync byte or checksum.
-// A read from the driver may return any number of ANT HCI packets.
-
-#include "ant_driver_defines.h"
-
-#define ANT_HCI_HEADER_SIZE ((ANT_HCI_OPCODE_SIZE) + (ANT_HCI_SIZE_SIZE) + (ANT_HCI_SYNC_SIZE))
-#define ANT_HCI_FOOTER_SIZE (ANT_HCI_CHECKSUM_SIZE)
-
-#define ANT_HCI_OPCODE_OFFSET 0
-#define ANT_HCI_SIZE_OFFSET ((ANT_HCI_OPCODE_OFFSET) + (ANT_HCI_OPCODE_SIZE))
-#define ANT_HCI_SYNC_OFFSET ((ANT_HCI_SIZE_OFFSET) + (ANT_HCI_SIZE_SIZE))
-#define ANT_HCI_DATA_OFFSET (ANT_HCI_HEADER_SIZE)
-
-#define ANT_FLOW_GO_WAIT_TIMEOUT_SEC 10
-
-#endif /* ifndef __VFS_INDEPENDENT_H */
diff --git a/src/bt-vendor_vfs/inc/ant_rx_chardev.h b/src/bt-vendor_vfs/inc/ant_rx_chardev.h
deleted file mode 100644
index 12ba629..0000000
--- a/src/bt-vendor_vfs/inc/ant_rx_chardev.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2011 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*******************************************************************************\
-*
-* FILE NAME: ant_rx_chardev.h
-*
-* BRIEF:
-* This file defines the receive thread function, the ant_rx_thread_info_t
-* type for storing the -configuration- <state> of the receive thread, the
-* ant_channel_info_t type for storing a channel's (transport path)
-* configuration, and an enumeration of all ANT channels (transport paths).
-*
-*
-\*******************************************************************************/
-
-#ifndef __ANT_RX_NATIVE_H
-#define __ANT_RX_NATIVE_H
-
-#include "ant_native.h"
-#include "ant_hci_defines.h"
-
-/* same as HCI_MAX_EVENT_SIZE from hci.h, but hci.h is not included for vfs */
-#define ANT_HCI_MAX_MSG_SIZE 260
-
-#define ANT_MSG_SIZE_OFFSET ((ANT_U8)0)
-#define ANT_MSG_ID_OFFSET ((ANT_U8)1)
-#define ANT_MSG_DATA_OFFSET ((ANT_U8)2)
-
-/* This struct defines the info passed to an rx thread */
-typedef struct {
- /* Device path */
- const char *pcDevicePath;
- /* File descriptor to read from */
- int iFd;
- /* Callback to call with ANT packet */
- ANTNativeANTEventCb fnRxCallback;
- /* Flow control response if channel supports it */
- ANT_U8 ucFlowControlResp;
- /* Handle to flow control condition */
- pthread_cond_t *pstFlowControlCond;
- /* Handle to flow control mutex */
- pthread_mutex_t *pstFlowControlLock;
-#ifdef ANT_FLOW_RESEND
- /* Length of message to resend on request from chip */
- ANT_U8 ucResendMessageLength;
- /* The message to resend on request from chip */
- ANT_U8 *pucResendMessage;
-#endif // ANT_FLOW_RESEND
-} ant_channel_info_t;
-
-typedef enum {
-#ifdef ANT_DEVICE_NAME // Single transport path
- SINGLE_CHANNEL,
-#else // Separate data/command paths
- DATA_CHANNEL,
- COMMAND_CHANNEL,
-#endif // Separate data/command paths
- NUM_ANT_CHANNELS
-} ant_channel_type;
-
-typedef struct {
- /* Thread handle */
- pthread_t stRxThread;
- /* Exit condition */
- ANT_U8 ucRunThread;
- /* Set state as resetting override */
- ANT_U8 ucChipResetting;
- /* Handle to state change lock for crash cleanup */
- pthread_mutex_t *pstEnabledStatusLock;
- /* ANT channels */
- ant_channel_info_t astChannels[NUM_ANT_CHANNELS];
- /* Event file descriptor used to interrupt the poll() loop in the rx thread. */
- int iRxShutdownEventFd;
- /* Indicates whether thread is waiting for a keepalive response. */
- ANT_BOOL bWaitingForKeepaliveResponse;
-} ant_rx_thread_info_t;
-
-extern ANTNativeANTStateCb g_fnStateCallback; // TODO State callback should be inside ant_rx_thread_info_t.
-
-/* This is the rx thread function. It loops reading ANT packets until told to
- * exit */
-void *fnRxThread(void *ant_rx_thread_info);
-
-#endif /* ifndef __ANT_RX_NATIVE_H */
-
diff --git a/src/bt-vendor_vfs/inc/antradio_power.h b/src/bt-vendor_vfs/inc/antradio_power.h
deleted file mode 100644
index 1aa0b24..0000000
--- a/src/bt-vendor_vfs/inc/antradio_power.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __ANTRADIOPM_H
-#define __ANTRADIOPM_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Enable the ANT radio interface.
- *
- * Responsible for power on, and bringing up HCI interface.
- * Will block until the HCI interface is ready to use.
- *
- * Returns 0 on success, -ve on error */
-int ant_enable();
-
-/* Disable the ANT radio interface.
- *
- * Responsbile for pulling down the HCI interface, and powering down the chip.
- * Will block until power down is complete, and it is safe to immediately call
- * enable().
- *
- * Returns 0 on success, -ve on error */
-int ant_disable();
-
-/* Returns 1 if enabled, 0 if disabled, and -ve on error */
-int ant_is_enabled();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/bt-vendor_vfs/qualcomm/uart/ant_driver_defines.h b/src/bt-vendor_vfs/qualcomm/uart/ant_driver_defines.h
deleted file mode 100644
index 06b2e22..0000000
--- a/src/bt-vendor_vfs/qualcomm/uart/ant_driver_defines.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2011 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*******************************************************************************\
-*
-* FILE NAME: ant_driver_defines.h
-*
-* BRIEF:
-* This file defines ANT specific HCI values used by the ANT chip for a
-* Qualcomm UART implementation.
-*
-*
-\*******************************************************************************/
-
-#ifndef __VFS_PRERELEASE_H
-#define __VFS_PRERELEASE_H
-
-// Packets may be prefixed with an optional packet type byte when being sent to
-// the chip. Will not be present in messages received.
-
-// -----------------------------------------
-// | Header | Data | Footer |
-// |----------------------|-----------------|
-// |Optional| Data | Opt. | ... | Optional |
-// | Opcode | Size | Sync | | Checksum |
-
-// Data may include any number of ANT packets, with no sync byte or checksum.
-// A read from the driver may return any number of ANT HCI packets.
-
-
-// ---------------------- REQUIRED
-
-// Which chip is this library being built for:
-#define ANT_CHIP_NAME "Qualcomm UART"
-
-// Set the file name the driver creates for the ANT device:
-// If chip uses separate command and data paths:
-// #define ANT_COMMANDS_DEVICE_NAME "/dev/X"
-// #define ANT_DATA_DEVICE_NAME "/dev/Y"
-// OR
-// If chip uses one path:
-
-#define ANT_DEVICE_NAME "/dev/ttyHS0"
-
-// Optional Packet prefix byte.
-#define HCI_PACKET_TYPE_SIZE 1
-
-// Set to the number of bytes of header is for Opcode:
-#define ANT_HCI_OPCODE_SIZE 0
-
-// Set to the number of bytes of header is for Data Size:
-#define ANT_HCI_SIZE_SIZE 1
-
-// Set to the number of bytes of header is for Sync:
-#define ANT_HCI_SYNC_SIZE 0
-
-// Set to the number of bytes of footer is for Checksum:
-#define ANT_HCI_CHECKSUM_SIZE 0
-
-// ---------------------- OPTIONAL
-
-// If hard reset is supported, define ANT_IOCTL_RESET
-// #define ANT_IOCTL_RESET _IOW('U', 210, int)
-// #define ANT_IOCTL_RESET_PARAMETER (0)
-
-// If the chip sends flow control messages:
-// Define the Opcode for a Flow Control message:
-#define ANT_MESG_FLOW_CONTROL ((ANT_U8)0xC9)
-// AND
-// define the message content:
-// That signals Flow Go:
-#define ANT_FLOW_GO ((ANT_U8)0x00)
-
-// That signals Flow Stop:
-#define ANT_FLOW_STOP ((ANT_U8)0x80)
-
-// Define protocol byte to be added
-// as multiple data will be sent/received over
-// same transport(BT, ANT ..etc)
-// needed for HCI_PACKET_TYPE_SIZE > 1.
-#define ANT_CMD_TYPE_PACKET ((ANT_U8)0x0C)
-#define ANT_DATA_TYPE_PACKET ((ANT_U8)0x0E)
-
-#endif /* ifndef __VFS_PRERELEASE_H */
diff --git a/src/common/JAntNative.cpp b/src/common/JAntNative.cpp
deleted file mode 100644
index 2e3beb0..0000000
--- a/src/common/JAntNative.cpp
+++ /dev/null
@@ -1,366 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2009 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*******************************************************************************\
-*
-* FILE NAME: JAntNative.cpp
-*
-* BRIEF:
-* This file provides the implementation of the native interface functions for ANT
-*
-*
-\*******************************************************************************/
-
-#include "android_runtime/AndroidRuntime.h"
-#include "jni.h"
-#include "nativehelper/JNIHelp.h"
-
-static JNIEnv *g_jEnv = NULL;
-static JavaVM *g_jVM = NULL;
-static jclass g_sJClazz;
-static jmethodID g_sMethodId_nativeCb_AntRxMessage;
-static jmethodID g_sMethodId_nativeCb_AntStateChange;
-
-extern "C"
-{
- #include "ant_native.h"
- #include "ant_log.h"
- #undef LOG_TAG
- #define LOG_TAG "JAntNative"
-
- void nativeJAnt_RxCallback(ANT_U8 ucLen, ANT_U8* pucData);
- void nativeJAnt_StateCallback(ANTRadioEnabledStatus uiNewState);
-}
-
-static jint nativeJAnt_Create(JNIEnv *env, jobject obj)
-{
- ANTStatus antStatus = ANT_STATUS_FAILED;
- (void)env; //unused warning
- (void)obj; //unused warning
-
- ANT_FUNC_START();
-
- antStatus = ant_init();
- if (antStatus)
- {
- ANT_DEBUG_D("failed to init ANT stack");
- goto CLEANUP;
- }
-
- antStatus = set_ant_rx_callback(nativeJAnt_RxCallback);
- if (antStatus)
- {
- ANT_DEBUG_D("failed to set ANT rx callback");
- goto CLEANUP;
- }
-
- antStatus = set_ant_state_callback(nativeJAnt_StateCallback);
- if (antStatus)
- {
- ANT_DEBUG_D("failed to set ANT state callback");
- goto CLEANUP;
- }
-
-CLEANUP:
- ANT_FUNC_END();
- return antStatus;
-}
-
-static jint nativeJAnt_Destroy(JNIEnv *env, jobject obj)
-{
- (void)env; //unused warning
- (void)obj; //unused warning
- ANTStatus status;
- ANT_FUNC_START();
-
- ANT_DEBUG_D("nativeJAnt_Destroy(): calling ant_deinit");
- status = ant_deinit();
- if (status)
- {
- ANT_DEBUG_D("failed to deinit ANT stack returned %d",(int)status);
- return status;
- }
- else
- {
- ANT_DEBUG_D("deinit ANT stack Success");
- }
-
- ANT_FUNC_END();
- return status;
-}
-
-static jint nativeJAnt_Enable(JNIEnv *env, jobject obj)
-{
- (void)env; //unused warning
- (void)obj; //unused warning
- ANT_FUNC_START();
-
- ANTStatus status = ant_enable_radio();
-
- ANT_FUNC_END();
- return status;
-}
-
-static jint nativeJAnt_Disable(JNIEnv *env, jobject obj)
-{
- (void)env; //unused warning
- (void)obj; //unused warning
- ANT_FUNC_START();
-
- ANTStatus status = ant_disable_radio();
-
- ANT_FUNC_END();
- return status;
-}
-
-static jint nativeJAnt_GetRadioEnabledStatus(JNIEnv *env, jobject obj)
-{
- (void)env; //unused warning
- (void)obj; //unused warning
- ANT_FUNC_START();
-
- jint status = ant_radio_enabled_status();
-
- ANT_FUNC_END();
- return status;
-}
-
-static jint nativeJAnt_TxMessage(JNIEnv *env, jobject obj, jbyteArray msg)
-{
- (void)obj; //unused warning
- ANT_FUNC_START();
-
- if (msg == NULL)
- {
- if (jniThrowException(env, "java/lang/NullPointerException", NULL))
- {
- ANT_ERROR("Unable to throw NullPointerException");
- }
- return -1;
- }
-
- jbyte* msgBytes = env->GetByteArrayElements(msg, NULL);
- jint msgLength = env->GetArrayLength(msg);
-
- ANTStatus status = ant_tx_message((ANT_U8) msgLength, (ANT_U8 *)msgBytes);
- ANT_DEBUG_D("nativeJAnt_TxMessage: ant_tx_message() returned %d", (int)status);
-
- env->ReleaseByteArrayElements(msg, msgBytes, JNI_ABORT);
-
- ANT_FUNC_END();
- return status;
-}
-
-static jint nativeJAnt_HardReset(JNIEnv *env, jobject obj)
-{
- (void)env; //unused warning
- (void)obj; //unused warning
- ANT_FUNC_START();
-
- ANTStatus status = ant_radio_hard_reset();
-
- ANT_FUNC_END();
- return status;
-}
-
-extern "C"
-{
-
- /**********************************************************************
- * Callback registration
- ***********************************************************************/
- void nativeJAnt_RxCallback(ANT_U8 ucLen, ANT_U8* pucData)
- {
- JNIEnv* env = NULL;
- jbyteArray jAntRxMsg = NULL;
- ANT_FUNC_START();
-
- ANT_DEBUG_D( "got message %d bytes", ucLen);
-
- g_jVM->AttachCurrentThread((&env), NULL);
-
- if (env == NULL)
- {
- ANT_DEBUG_D("nativeJAnt_RxCallback: Entered, env is null");
- return; // log error? cleanup?
- }
- else
- {
- ANT_DEBUG_D("nativeJAnt_RxCallback: jEnv %p", env);
- }
-
- jAntRxMsg = env->NewByteArray(ucLen);
-
- if (jAntRxMsg == NULL)
- {
- ANT_ERROR("nativeJAnt_RxCallback: Failed creating java byte[]");
- goto CLEANUP;
- }
-
- env->SetByteArrayRegion(jAntRxMsg,0,ucLen,(jbyte*)pucData);
-
- if (env->ExceptionOccurred())
- {
- ANT_ERROR("nativeJAnt_RxCallback: ExceptionOccurred during byte[] copy");
- goto CLEANUP;
- }
- ANT_DEBUG_V("nativeJAnt_RxCallback: Calling java rx callback");
- env->CallStaticVoidMethod(g_sJClazz, g_sMethodId_nativeCb_AntRxMessage, jAntRxMsg);
- ANT_DEBUG_V("nativeJAnt_RxCallback: Called java rx callback");
-
- if (env->ExceptionOccurred())
- {
- ANT_ERROR("nativeJAnt_RxCallback: Calling Java nativeCb_AntRxMessage failed");
- goto CLEANUP;
- }
-
- //Delete the local references
- if (jAntRxMsg != NULL)
- {
- env->DeleteLocalRef(jAntRxMsg);
- }
-
- ANT_DEBUG_D("nativeJAnt_RxCallback: Exiting, Calling DetachCurrentThread at the END");
-
- g_jVM->DetachCurrentThread();
-
- ANT_FUNC_END();
- return;
-
- CLEANUP:
- ANT_ERROR("nativeJAnt_RxCallback: Exiting due to failure");
- if (jAntRxMsg != NULL)
- {
- env->DeleteLocalRef(jAntRxMsg);
- }
-
- if (env->ExceptionOccurred())
- {
- env->ExceptionDescribe();
- env->ExceptionClear();
- }
-
- g_jVM->DetachCurrentThread();
-
- return;
- }
-
- void nativeJAnt_StateCallback(ANTRadioEnabledStatus uiNewState)
- {
- JNIEnv* env = NULL;
- jint jNewState = uiNewState;
- ANT_BOOL iShouldDetach = ANT_FALSE;
- ANT_FUNC_START();
-
- g_jVM->GetEnv((void**) &env, JNI_VERSION_1_4);
- if (env == NULL)
- {
- ANT_DEBUG_D("nativeJAnt_StateCallback: called from rx thread, attaching to VM");
- g_jVM->AttachCurrentThread((&env), NULL);
- if (env == NULL)
- {
- ANT_DEBUG_E("nativeJAnt_StateCallback: failed to attach rx thread to VM");
- return;
- }
- iShouldDetach = ANT_TRUE;
- }
- else
- {
- ANT_DEBUG_D("nativeJAnt_StateCallback: called from java enable/disable"
- ", already attached, don't detach");
- }
-
- ANT_DEBUG_V("nativeJAnt_StateCallback: Calling java state callback");
- env->CallStaticVoidMethod(g_sJClazz, g_sMethodId_nativeCb_AntStateChange, jNewState);
- ANT_DEBUG_V("nativeJAnt_StateCallback: Called java state callback");
-
- if (env->ExceptionOccurred())
- {
- ANT_ERROR("nativeJAnt_StateCallback: Calling Java nativeCb_AntStateChange failed");
- env->ExceptionDescribe();
- env->ExceptionClear();
- }
-
- if (iShouldDetach)
- {
- ANT_DEBUG_D("nativeJAnt_StateCallback: env was attached, detaching");
- g_jVM->DetachCurrentThread();
- }
-
- ANT_FUNC_END();
- return;
- }
-}
-
-static JNINativeMethod g_sMethods[] =
-{
- /* name, signature, funcPtr */
- {"nativeJAnt_Create", "()I", (void*)nativeJAnt_Create},
- {"nativeJAnt_Destroy", "()I", (void*)nativeJAnt_Destroy},
- {"nativeJAnt_Enable", "()I", (void*)nativeJAnt_Enable},
- {"nativeJAnt_Disable", "()I", (void*)nativeJAnt_Disable},
- {"nativeJAnt_GetRadioEnabledStatus", "()I", (void*)nativeJAnt_GetRadioEnabledStatus},
- {"nativeJAnt_TxMessage","([B)I", (void*)nativeJAnt_TxMessage},
- {"nativeJAnt_HardReset", "()I", (void *)nativeJAnt_HardReset}
-};
-
-jint JNI_OnLoad(JavaVM* vm, void* reserved) {
- ANT_FUNC_START();
- (void)reserved; //unused warning
-
- g_jVM = vm;
- if (g_jVM->GetEnv((void**) &g_jEnv, JNI_VERSION_1_4) != JNI_OK) {
- ANT_ERROR("GetEnv failed");
- return -1;
- }
- if (NULL == g_jEnv) {
- ANT_ERROR("env is null");
- return -1;
- }
-
- g_sJClazz = g_jEnv->FindClass("com/dsi/ant/core/JAntJava");
- if (NULL == g_sJClazz) {
- ANT_ERROR("could not find class \"com/dsi/ant/core/JAntJava\"");
- return -1;
- }
-
- /* Save class information in global reference to prevent class unloading */
- g_sJClazz = (jclass)g_jEnv->NewGlobalRef(g_sJClazz);
-
- if (g_jEnv->RegisterNatives(g_sJClazz, g_sMethods, NELEM(g_sMethods)) != JNI_OK) {
- ANT_ERROR("failed to register methods");
- return -1;
- }
-
- g_sMethodId_nativeCb_AntRxMessage = g_jEnv->GetStaticMethodID(g_sJClazz,
- "nativeCb_AntRxMessage", "([B)V");
- if (NULL == g_sMethodId_nativeCb_AntRxMessage) {
- ANT_ERROR("VerifyMethodId: Failed getting method id of \"void nativeCb_AntRxMessage(byte[])\"");
- return -1;
- }
-
- g_sMethodId_nativeCb_AntStateChange = g_jEnv->GetStaticMethodID(g_sJClazz,
- "nativeCb_AntStateChange", "(I)V");
- if (NULL == g_sMethodId_nativeCb_AntStateChange) {
- ANT_ERROR("VerifyMethodId: Failed getting method id of \"void nativeCb_AntStateChange(int)\"");
- return -1;
- }
-
- ANT_FUNC_END();
- return JNI_VERSION_1_4;
-}
-
diff --git a/src/common/ant_utils.c b/src/common/ant_utils.c
deleted file mode 100644
index 65b35de..0000000
--- a/src/common/ant_utils.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2009 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/******************************************************************************\
-*
-* FILE NAME: ANT_utils.c
-*
-* BRIEF:
-* This file contains utility functions
-*
-*
-\******************************************************************************/
-
-#include "ant_types.h"
-#include "ant_utils.h"
-
-
-ANT_U16 ANT_UTILS_BEtoHost16(ANT_U8 * num)
-{
- return (ANT_U16)(((ANT_U16) *(num) << 8) | ((ANT_U16) *(num+1)));
-}
-ANT_U16 ANT_UTILS_LEtoHost16(ANT_U8 * num)
-{
- return (ANT_U16)(((ANT_U16) *(num+1) << 8) | ((ANT_U16) *(num)));
-}
-void ANT_UTILS_StoreBE16(ANT_U8 *buff, ANT_U16 be_value)
-{
- buff[0] = (ANT_U8)(be_value>>8);
- buff[1] = (ANT_U8)be_value;
-}
-void ANT_UTILS_StoreLE16(ANT_U8 *buff, ANT_U16 le_value)
-{
- buff[1] = (ANT_U8)(le_value>>8);
- buff[0] = (ANT_U8)le_value;
-}
-
-void ANT_UTILS_StoreBE32(ANT_U8 *buff, ANT_U32 be_value)
-{
- buff[0] = (ANT_U8)(be_value>>24);
- buff[1] = (ANT_U8)(be_value>>16);
- buff[2] = (ANT_U8)(be_value>>8);
- buff[3] = (ANT_U8)be_value;
-}
diff --git a/src/common/inc/ant_log.h b/src/common/inc/ant_log.h
deleted file mode 100644
index bc45462..0000000
--- a/src/common/inc/ant_log.h
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
-* ANT Stack
-*
-* Copyright 2009 Dynastream Innovations
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-/******************************************************************************\
-*
-* FILE NAME: ANT_log.h
-*
-* BRIEF:
-* This file defines logging functions
-*
-*
-\******************************************************************************/
-
-#ifndef __ANT_LOG_H
-#define __ANT_LOG_H
-
-#include <unistd.h>
-#include "ant_types.h"
-
-#define LEVEL_NONE 0
-#define LEVEL_ERROR 1
-#define LEVEL_WARNING 2
-#define LEVEL_INFO 3
-#define LEVEL_DEBUG 4
-#define LEVEL_VERBOSE 5
-
-#define STREAM_STDOUT 16
-#define STREAM_LOGCAT 17
-
-/* Define what stream output should go to depending on platform */
-#if defined(__ANDROID__) || defined(ANDROID)
- #define ANT_OUTPUT_STREAM STREAM_LOGCAT
-#elif defined(__linux__) || defined(__linux) || defined(linux)
- #define ANT_OUTPUT_STREAM STREAM_STDOUT
-#endif
-
-/* If no debug level defined, set default as none */
-#if !defined(ANT_DEBUG)
- #define ANT_DEBUG LEVEL_NONE
-#endif
-
-/* Define to show function entry and exit */
-//#define ANT_STACK_TRACE
-
-/* Define to show message in byte form */
-//#define ANT_LOG_SERIAL
-
-/* Define to write serial log to file instead of logcat */
-//#define ANT_LOG_SERIAL_FILE "/data/system/antseriallog.txt"
-
-#undef LOG_TAG
-#define LOG_TAG "antradio"
-
-#if ANT_DEBUG == LEVEL_NONE
- #undef ANT_STACK_TRACE
- #undef ANT_LOG_SERIAL
-#endif
-
-#if ANT_DEBUG >= LEVEL_ERROR
- #define OUTPUT_LEVEL_ERROR(...) OUTPUT_ERROR(__VA_ARGS__)
-#else
- #define OUTPUT_LEVEL_ERROR(...) ((void)0)
-#endif
-#if ANT_DEBUG >= LEVEL_WARNING
- #define OUTPUT_LEVEL_WARNING(...) OUTPUT_WARNING(__VA_ARGS__)
-#else
- #define OUTPUT_LEVEL_WARNING(...) ((void)0)
-#endif
-#if ANT_DEBUG >= LEVEL_INFO
- #define OUTPUT_LEVEL_INFO(...) OUTPUT_INFO(__VA_ARGS__)
-#else
- #define OUTPUT_LEVEL_INFO(...) ((void)0)
-#endif
-#if ANT_DEBUG >= LEVEL_DEBUG
- #define OUTPUT_LEVEL_DEBUG(...) OUTPUT_DEBUG(__VA_ARGS__)
-#else
- #define OUTPUT_LEVEL_DEBUG(...) ((void)0)
-#endif
-#if ANT_DEBUG >= LEVEL_VERBOSE
- #define OUTPUT_LEVEL_VERBOSE(...) OUTPUT_VERBOSE(__VA_ARGS__)
-#else
- #define OUTPUT_LEVEL_VERBOSE(...) ((void)0)
-#endif
-
-#if ANT_OUTPUT_STREAM == STREAM_STDOUT
- #include <stdio.h>
- #define OUTPUT_VERBOSE(fmt, ...) fprintf(stdout, LOG_TAG "<V>: " fmt "\n", ##__VA_ARGS__)
- #define OUTPUT_DEBUG(fmt, ...) fprintf(stdout, LOG_TAG "<D>: " fmt "\n", ##__VA_ARGS__)
- #define OUTPUT_INFO(fmt, ...) fprintf(stdout, LOG_TAG "<I>: " fmt "\n", ##__VA_ARGS__)
- #define OUTPUT_WARNING(fmt, ...) fprintf(stdout, LOG_TAG "<W>: " fmt "\n", ##__VA_ARGS__)
- #define OUTPUT_ERROR(fmt, ...) fprintf(stdout, LOG_TAG "<E>: " fmt "\n", ##__VA_ARGS__)
-#elif ANT_OUTPUT_STREAM == STREAM_LOGCAT
- #if (ANT_DEBUG >= LEVEL_VERBOSE) || (defined(ANT_LOG_SERIAL) && !defined(ANT_LOG_SERIAL_FILE))
- #undef NDEBUG /* Define verbose logging for logcat if required */
- #endif
- #include <cutils/log.h>
- #define OUTPUT_VERBOSE(...) ALOGV(__VA_ARGS__)
- #define OUTPUT_DEBUG(...) ALOGD(__VA_ARGS__)
- #define OUTPUT_INFO(...) ALOGI(__VA_ARGS__)
- #define OUTPUT_WARNING(...) ALOGW(__VA_ARGS__)
- #define OUTPUT_ERROR(...) ALOGE(__VA_ARGS__)
-#endif
-
-#define ANT_WARN(...) OUTPUT_WARNING(__VA_ARGS__)
-#define ANT_ERROR(...) OUTPUT_ERROR(__VA_ARGS__)
-
-#define ANT_DEBUG_V(...) OUTPUT_LEVEL_VERBOSE(__VA_ARGS__)
-#define ANT_DEBUG_D(...) OUTPUT_LEVEL_DEBUG(__VA_ARGS__)
-#define ANT_DEBUG_I(...) OUTPUT_LEVEL_INFO(__VA_ARGS__)
-#define ANT_DEBUG_W(...) OUTPUT_LEVEL_WARNING(__VA_ARGS__)
-#define ANT_DEBUG_E(...) OUTPUT_LEVEL_ERROR(__VA_ARGS__)
-
-#if defined(ANT_STACK_TRACE)
- #define ANT_FUNC_START() OUTPUT_DEBUG("-> FUNC start %s", __FUNCTION__)
- #define ANT_FUNC_END() OUTPUT_DEBUG("<- FUNC end %s", __FUNCTION__)
-#else
- #define ANT_FUNC_START() ((void)0)
- #define ANT_FUNC_END() ((void)0)
-#endif
-
-#if defined(ANT_LOG_SERIAL)
-static inline void ANT_SERIAL(ANT_U8 *buf, ANT_U8 len, char dir)
-{
- static const char hexToChar[] = {'0','1','2','3','4','5','6','7',
- '8','9','A','B','C','D','E','F'};
- int i;
- static char log[1024];
- char *ptr = log;
-
- *(ptr++) = dir;
- *(ptr++) = 'x';
- *(ptr++) = ' ';
- for (i = 0; i < len; i++) {
- *(ptr++) = '[';
- *(ptr++) = hexToChar[(buf[i] & 0xF0) >> 4];
- *(ptr++) = hexToChar[(buf[i] & 0x0F) >> 0];
- *(ptr++) = ']';
- }
-#if defined(ANT_LOG_SERIAL_FILE)
- *(ptr++) = '\n';
- FILE *fd = NULL;
- fd = fopen(ANT_LOG_SERIAL_FILE, "a");
- if (NULL == fd) {
- LOGW("Could not open %s for serial output. %s", ANT_LOG_SERIAL_FILE, strerror(errno));
- } else {
- fwrite(log, 1, (ptr - log), fd);
- if (fclose(fd)) {
- LOGW("Could not close file for serial output. %s", strerror(errno));
- }
- }
-#else
- *(ptr++) = '\0';
- OUTPUT_VERBOSE("%s", log);
-#endif
-}
-#else
- #define ANT_SERIAL(...) ((void)0)
-#endif
-
-#endif /* __ANT_LOG_H */
diff --git a/src/common/inc/ant_native.h b/src/common/inc/ant_native.h
deleted file mode 100644
index 6fe106d..0000000
--- a/src/common/inc/ant_native.h
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2009 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/******************************************************************************\
-*
-* FILE NAME: ant_native.h
-*
-* BRIEF:
-* This file defines the interface to the ANT transport layer
-*
-*
-\******************************************************************************/
-
-#ifndef __ANT_NATIVE_H
-#define __ANT_NATIVE_H
-
-/*******************************************************************************
- *
- * Include files
- *
- ******************************************************************************/
-#include "ant_types.h"
-
-/*******************************************************************************
- *
- * Constants
- *
- ******************************************************************************/
-
-/*******************************************************************************
- *
- * Types
- *
- ******************************************************************************/
-typedef void (*ANTNativeANTEventCb)(ANT_U8 ucLen, ANT_U8* pucData);
-typedef void (*ANTNativeANTStateCb)(ANTRadioEnabledStatus uiNewState);
-
-/*******************************************************************************
- *
- * Data Structures
- *
- ******************************************************************************/
-
-/*******************************************************************************
- *
- * Function declarations
- *
- ******************************************************************************/
-
-/*------------------------------------------------------------------------------
- * ant_init()
- *
- * Called to initialize the ANT stack
- */
-ANTStatus ant_init(void);
-
-/*------------------------------------------------------------------------------
- * ant_deinit()
- *
- * Called to de-initialize the ANT stack
- */
-ANTStatus ant_deinit(void);
-
-/*------------------------------------------------------------------------------
- * ant_enable_radio()
- *
- * Power on the chip and set it to a state which can read / write to it
- */
-ANTStatus ant_enable_radio(void);
-
-/*------------------------------------------------------------------------------
- * ant_disable_radio()
- *
- * Kill power to the ANT chip and set state which doesnt allow read / write
- */
-ANTStatus ant_disable_radio(void);
-
-/*------------------------------------------------------------------------------
- * ant_radio_enabled_status()
- *
- * Gets if the chip/transport is disabled/disabling/enabling/enabled
- */
-ANTRadioEnabledStatus ant_radio_enabled_status(void);
-
-/*------------------------------------------------------------------------------
- * set_ant_rx_callback()
- *
- * Sets the callback function for receiving ANT messages
- */
-ANTStatus set_ant_rx_callback(ANTNativeANTEventCb rx_callback_func);
-
-/*------------------------------------------------------------------------------
- * set_ant_state_callback()
- *
- * Sets the callback function for any ANT radio enabled status state changes
- */
-ANTStatus set_ant_state_callback(ANTNativeANTStateCb state_callback_func);
-
-/*------------------------------------------------------------------------------
- * ant_tx_message()
- *
- * Sends an ANT message command to the chip.
- */
-ANTStatus ant_tx_message(ANT_U8 ucLen, ANT_U8 *pucMesg);
-
-/*------------------------------------------------------------------------------
- * ant_radio_hard_reset()
- *
- * If supported, forces the chip to do a power cycle reset
- */
-ANTStatus ant_radio_hard_reset(void);
-
-/*------------------------------------------------------------------------------
- * ant_get_lib_version()
- *
- * Gets the current version and transport type of libantradio.so
- */
-const char *ant_get_lib_version(void);
-
-#endif /* ifndef __ANT_NATIVE_H */
-
diff --git a/src/common/inc/ant_types.h b/src/common/inc/ant_types.h
deleted file mode 100644
index bc896b6..0000000
--- a/src/common/inc/ant_types.h
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2009 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/******************************************************************************\
-*
-* FILE NAME: ANT_types.h
-*
-* BRIEF:
-* This file defines types used in the ANT stack
-*
-*
-\******************************************************************************/
-
-#ifndef __ANT_TYPES_H
-#define __ANT_TYPES_H
-
-#include <stdint.h>
-
-/* -------------------------------------------------------------
- * 8 Bits Types
- */
-typedef uint8_t ANT_U8;
-typedef int8_t ANT_S8;
-
-/* -------------------------------------------------------------
- * 16 Bits Types
- */
-typedef uint16_t ANT_U16;
-typedef int8_t ANT_S16;
-
-/* -------------------------------------------------------------
- * 32 Bits Types
- */
-typedef uint32_t ANT_U32;
-typedef int32_t ANT_S32;
-
-
-/* -------------------------------------------------------------
- * Native Integer Types (# of bits irrelevant)
- */
-typedef int ANT_INT;
-typedef unsigned int ANT_UINT;
-
-
-/* --------------------------------------------------------------
- * Boolean Definitions
- */
-typedef ANT_INT ANT_BOOL;
-
-#define ANT_TRUE (1 == 1)
-#define ANT_FALSE (1 == 0)
-
-/*
-*/
-#define ANT_NO_VALUE ((ANT_U32)0xFFFFFFFFUL)
-
-
-/* -------------------------------------------------------------
- * ANTRadioEnabledStatus Type
- */
-typedef ANT_UINT ANTRadioEnabledStatus;
-
-#define RADIO_STATUS_UNKNOWN ((ANTRadioEnabledStatus)0)
-#define RADIO_STATUS_ENABLING ((ANTRadioEnabledStatus)1)
-#define RADIO_STATUS_ENABLED ((ANTRadioEnabledStatus)2)
-#define RADIO_STATUS_DISABLING ((ANTRadioEnabledStatus)3)
-#define RADIO_STATUS_DISABLED ((ANTRadioEnabledStatus)4)
-#define RADIO_STATUS_NOT_SUPPORTED ((ANTRadioEnabledStatus)5)
-#define RADIO_STATUS_SERVICE_NOT_INSTALLED ((ANTRadioEnabledStatus)6)
-#define RADIO_STATUS_SERVICE_NOT_CONNECTED ((ANTRadioEnabledStatus)7)
-#define RADIO_STATUS_RESETTING ((ANTRadioEnabledStatus)8)
-#define RADIO_STATUS_RESET ((ANTRadioEnabledStatus)9)
-
-/*------------------------------------------------------------------------------
- * ANTStatus Type
- *
- */
-typedef ANT_UINT ANTStatus;
-
-#define ANT_STATUS_SUCCESS ((ANTStatus)0)
-#define ANT_STATUS_FAILED ((ANTStatus)1)
-#define ANT_STATUS_PENDING ((ANTStatus)2)
-#define ANT_STATUS_INVALID_PARM ((ANTStatus)3)
-#define ANT_STATUS_IN_PROGRESS ((ANTStatus)4)
-#define ANT_STATUS_NOT_APPLICABLE ((ANTStatus)5)
-#define ANT_STATUS_NOT_SUPPORTED ((ANTStatus)6)
-#define ANT_STATUS_INTERNAL_ERROR ((ANTStatus)7)
-#define ANT_STATUS_TRANSPORT_INIT_ERR ((ANTStatus)8)
-#define ANT_STATUS_HARDWARE_ERR ((ANTStatus)9)
-#define ANT_STATUS_NO_VALUE_AVAILABLE ((ANTStatus)10)
-#define ANT_STATUS_CONTEXT_DOESNT_EXIST ((ANTStatus)11)
-#define ANT_STATUS_CONTEXT_NOT_DESTROYED ((ANTStatus)12)
-#define ANT_STATUS_CONTEXT_NOT_ENABLED ((ANTStatus)13)
-#define ANT_STATUS_CONTEXT_NOT_DISABLED ((ANTStatus)14)
-#define ANT_STATUS_NOT_DE_INITIALIZED ((ANTStatus)15)
-#define ANT_STATUS_NOT_INITIALIZED ((ANTStatus)16)
-#define ANT_STATUS_TOO_MANY_PENDING_CMDS ((ANTStatus)17)
-#define ANT_STATUS_DISABLING_IN_PROGRESS ((ANTStatus)18)
-
-#define ANT_STATUS_COMMAND_WRITE_FAILED ((ANTStatus)20)
-#define ANT_STATUS_SCRIPT_EXEC_FAILED ((ANTStatus)21)
-
-#define ANT_STATUS_FAILED_BT_NOT_INITIALIZED ((ANTStatus)23)
-#define ANT_STATUS_AUDIO_OPERATION_UNAVAILIBLE_RESOURCES ((ANTStatus)24)
-
-#define ANT_STATUS_TRANSPORT_UNSPECIFIED_ERROR ((ANTStatus)30)
-
-#define ANT_STATUS_NO_VALUE ((ANTStatus)100)
-
-#endif /* __ANT_TYPES_H */
-
diff --git a/src/common/inc/ant_utils.h b/src/common/inc/ant_utils.h
deleted file mode 100644
index 60abe8c..0000000
--- a/src/common/inc/ant_utils.h
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2009 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/******************************************************************************\
-*
-* FILE NAME: ANT_utils.h
-*
-* BRIEF:
-* This file defines utility functions
-*
-*
-\******************************************************************************/
-#ifndef __ANT_UTILS_H
-#define __ANT_UTILS_H
-
-#include "ant_types.h"
-
-/****************************************************************************
- *
- * Type Definitions
- *
- ****************************************************************************/
-
-
-
-/*------------------------------------------------------------------------------
- * ANT_xxx()
- *
- * Brief:
- * xxx
- *
- * Description:
- * xxx
- *
- * Type:
- * Syxxx/As
- *
- * Parameters:
- * xxx [in] -
- *
- * Returns:
- * xxx
- */
-ANT_U16 ANT_UTILS_BEtoHost16(ANT_U8 * num);
-/*------------------------------------------------------------------------------
- * ANT_xxx()
- *
- * Brief:
- * xxx
- *
- * Description:
- * xxx
- *
- * Type:
- * Syxxx/As
- *
- * Parameters:
- * xxx [in] -
- *
- * Returns:
- * xxx
- */
-ANT_U16 ANT_UTILS_LEtoHost16(ANT_U8 * num);
-/*------------------------------------------------------------------------------
- * ANT_xxx()
- *
- * Brief:
- * xxx
- *
- * Description:
- * xxx
- *
- * Type:
- * Syxxx/As
- *
- * Parameters:
- * xxx [in] -
- *
- * Returns:
- * xxx
- */
-void ANT_UTILS_StoreBE16(ANT_U8 *buff, ANT_U16 be_value) ;
-/*------------------------------------------------------------------------------
- * ANT_xxx()
- *
- * Brief:
- * xxx
- *
- * Description:
- * xxx
- *
- * Type:
- * Syxxx/As
- *
- * Parameters:
- * xxx [in] -
- *
- * Returns:
- * xxx
- */
-void ANT_UTILS_StoreLE16(ANT_U8 *buff, ANT_U16 le_value) ;
-/*------------------------------------------------------------------------------
- * ANT_xxx()
- *
- * Brief:
- * xxx
- *
- * Description:
- * xxx
- *
- * Type:
- * Syxxx/As
- *
- * Parameters:
- * xxx [in] -
- *
- * Returns:
- * xxx
- */
-void ANT_UTILS_StoreBE32(ANT_U8 *buff, ANT_U32 be_value) ;
-
-
-
-#endif /* __ANT_UTILS_H */
-
diff --git a/src/common/inc/ant_version.h b/src/common/inc/ant_version.h
deleted file mode 100644
index 4a8881a..0000000
--- a/src/common/inc/ant_version.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2011 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __ANT_VERSION_H
-#define __ANT_VERSION_H
-
-#define LIBANT_STACK_MAJOR "1"
-#define LIBANT_STACK_MINOR "9"
-#define LIBANT_STACK_INCRE "7"
-
-#endif // __ANT_VERSION_H
-
diff --git a/src/qcomm-hidl/Android.mk b/src/qcomm-hidl/Android.mk
deleted file mode 100644
index 55f8d3d..0000000
--- a/src/qcomm-hidl/Android.mk
+++ /dev/null
@@ -1,72 +0,0 @@
-#
-# Copyright (C) 2011 Dynastream Innovations
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-include $(CLEAR_VARS)
-
-LOCAL_CFLAGS := -g -c -W -Wall -O2
-
-# needed to pull in the header file for libbt-vendor.so
-BDROID_DIR:= system/bt
-HWBINDER_DIR := system/hwbinder
-QCOM_DIR:= hardware/qcom/bt/libbt-vendor
-
-# Added hci/include to give access to the header for the libbt-vendorso interface.
-LOCAL_C_INCLUDES := \
- $(LOCAL_PATH)/src/common/inc \
- $(LOCAL_PATH)/$(ANT_DIR)/inc \
- $(BDROID_DIR)/hci/include \
- $(QCOM_DIR)/include \
- $(HWBINDER_DIR)/include
-
-
-ifeq ($(BOARD_ANT_WIRELESS_DEVICE),"qualcomm-hidl")
-LOCAL_C_INCLUDES += \
- $(LOCAL_PATH)/$(ANT_DIR)/qualcomm/hidl
-
-endif # BOARD_ANT_WIRELESS_DEVICE = "qualcomm-hidl"
-
-LOCAL_SRC_FILES := \
- $(COMMON_DIR)/ant_utils.c \
- $(ANT_DIR)/ant_native_chardev.c \
- $(ANT_DIR)/ant_rx_chardev.c \
- $(ANT_DIR)/AntHidlClient.cpp
-
-LOCAL_SRC_FILES += $(COMMON_DIR)/JAntNative.cpp
-
-
-# JNI
-LOCAL_C_INCLUDE += $(JNI_H_INCLUDE)
-
-LOCAL_SHARED_LIBRARIES += \
- libnativehelper \
- libbase \
- libhidlbase \
- libhidltransport \
- libhwbinder \
- libutils \
- com.qualcomm.qti.ant@1.0 \
- android.hardware.bluetooth@1.0 \
-
-# logging and dll loading
-LOCAL_SHARED_LIBRARIES += \
- libcutils \
- libdl \
- liblog
-
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE := libantradio
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/src/qcomm-hidl/AntHidlClient.cpp b/src/qcomm-hidl/AntHidlClient.cpp
deleted file mode 100644
index 616a5a6..0000000
--- a/src/qcomm-hidl/AntHidlClient.cpp
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
- *Copyright (c) 2017, The Linux Foundation. All rights reserved.
- *
- *
- *Redistribution and use in source and binary forms, with or without
- *modification, are permitted provided that the following conditions are
- *met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * * Neither the name of The Linux Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- *
- *THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
- *WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
- *ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
- *BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- *CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- *SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- *WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- *OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
- *IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-#include <iostream> // std::cin, std::cout
-#include <queue> // std::queue
-#include <mutex> // std::mutex, std::unique_lock
-#include <condition_variable> // std::condition_variable
-#include <cstdlib>
-#include <thread>
-
-#include <hwbinder/ProcessState.h>
-
-#include <com/qualcomm/qti/ant/1.0/IAntHci.h>
-#include <com/qualcomm/qti/ant/1.0/IAntHciCallbacks.h>
-#include <com/qualcomm/qti/ant/1.0/types.h>
-
-#include <utils/Log.h>
-
-
-#include <hidl/Status.h>
-#include <hwbinder/ProcessState.h>
-#include "ant_types.h"
-#include "AntHidlClient.h"
-
-using com::qualcomm::qti::ant::V1_0::IAntHci;
-using com::qualcomm::qti::ant::V1_0::IAntHciCallbacks;
-using com::qualcomm::qti::ant::V1_0::AntPacket;
-using com::qualcomm::qti::ant::V1_0::Status;
-
-using ::android::hardware::hidl_vec;
-
-
-using android::hardware::ProcessState;
-using ::android::hardware::Return;
-using ::android::hardware::Void;
-using ::android::sp;
-android::sp<IAntHci> anthci;
-typedef std::unique_lock<std::mutex> Lock;
-
-#define POLL_TIMEOUT_MS 100
-
-struct ant_hci_t {
-public:
- std::condition_variable rx_cond;
- std::condition_variable on_cond;
- std::condition_variable data_cond;
- std::mutex on_mtx;
- std::mutex rx_mtx;
- std::mutex data_mtx;
- ant_power_state_t state;
- volatile bool rx_processing;
-};
-
-static struct ant_hci_t ant_hci;
-
-Return<void> initialization_complete(bool is_hci_initialize)
-{
- ALOGI("%s start ", __func__ );
-
- Lock lk(ant_hci.on_mtx);
- if (is_hci_initialize)
- {
- ant_hci.state = ANT_RADIO_ENABLED;
- }
- else
- {
- ALOGE("%s:Ant hci init failed :%d", __func__, is_hci_initialize);
- ant_hci.state = ANT_RADIO_DISABLED;
- }
- ant_hci.on_cond.notify_all();
- ALOGI("%s: exit", __func__);
- return Void();
-}
-
-
-class AntHciCallbacks : public IAntHciCallbacks {
-public:
- AntHciCallbacks() {};
- virtual ~AntHciCallbacks() = default;
-
- Return<void> initializationComplete(Status status)
- {
- ALOGI("%s", __func__);
- if(status == Status::SUCCESS)
- {
- initialization_complete(true);
- } else {
- initialization_complete(false);
- }
- ALOGI("%s: exit", __func__);
- return Void();
- }
-
- Return<void> antControlReceived(const hidl_vec<uint8_t>& event)
- {
- ALOGV("%s:start ", __func__);
- // Make sure we don't overwrite a message still processing.
- Lock lk(ant_hci.rx_mtx);
- if(ant_hci.rx_processing && ant_hci.state == ANT_RADIO_ENABLED)
- {
- ant_hci.rx_cond.wait(lk);
- }
-
- memcpy(&aucRxBuffer[0][0], event.data(), event.size());
- iRxBufferLength[0] = event.size();
- std::unique_lock< std::mutex> lock(ant_hci.data_mtx);
- ALOGD("%s: notify data avail", __func__);
- ant_hci.rx_processing = true;
- ant_hci.data_cond.notify_all();
- ALOGV("%s: End", __func__);
- return Void();
- }
-
- Return<void> antDataReceived(const hidl_vec<uint8_t>& event)
- {
- ALOGV("%s:start ", __func__);
- // Make sure we don't overwrite a message still processing.
- Lock lk(ant_hci.rx_mtx);
- if(ant_hci.rx_processing && ant_hci.state == ANT_RADIO_ENABLED)
- {
- ant_hci.rx_cond.wait(lk);
- }
-
- memcpy(&aucRxBuffer[0][0], event.data(), event.size());
- iRxBufferLength[0] = event.size();
- std::unique_lock< std::mutex> lock(ant_hci.data_mtx);
- ALOGD("%s: notify data avail", __func__);
- ant_hci.rx_processing = true;
- ant_hci.data_cond.notify_all();
- ALOGV("%s: exit", __func__);
- return Void();
- }
-};
-
-bool hci_initialize()
-{
- ALOGI("%s", __func__);
-
- anthci = IAntHci::getService();
-
- if(anthci != nullptr)
- {
- ant_hci.state = ANT_RADIO_ENABLING;
- ant_hci.rx_processing = false;
- android::sp<IAntHciCallbacks> callbacks = new AntHciCallbacks();
- anthci->initialize(callbacks);
- ALOGV("%s: exit", __func__);
- return true;
- } else {
- return false;
- }
-}
-
-void hci_close() {
- ALOGV("%s", __func__);
-
- if(anthci != nullptr)
- {
- std::unique_lock< std::mutex> lock(ant_hci.data_mtx);
- ant_hci.data_cond.notify_all();
- auto hidl_daemon_status = anthci->close();
- if(!hidl_daemon_status.isOk())
- {
- ALOGE("%s: HIDL daemon is dead", __func__);
- }
- }
- ant_hci.state = ANT_RADIO_DISABLED;
- ant_rx_clear();
- anthci =nullptr;
- ALOGI("%s: exit", __func__);
-}
-
-ANT_UINT ant_get_status()
-{
- return ant_hci.state;
-}
-
-ANTStatus ant_tx_write(ANT_U8 *pucTxMessage,ANT_U8 ucMessageLength)
-{
- AntPacket data;
- ANT_U8 packet_type;
- ALOGI("%s: start", __func__);
- packet_type = *pucTxMessage;
- ALOGV("%s: proto type :%d", __func__, packet_type);
- if (anthci != nullptr)
- {
- data.setToExternal(pucTxMessage+1, ucMessageLength-1);
- if (packet_type == ANT_DATA_TYPE_PACKET)
- {
- auto hidl_daemon_status = anthci->sendAntData(data);
- if (!hidl_daemon_status.isOk())
- {
- ALOGE("%s:sendAntData failed,HIDL dead", __func__);
- return -1;
- }
- } else {
- auto hidl_daemon_status = anthci->sendAntControl(data);
- if (!hidl_daemon_status.isOk())
- {
- ALOGE("%s:sendAntControl failed,HIDL dead", __func__);
- return -1;
- }
- }
- } else {
- ALOGE("%s: antHci is NULL", __func__);
- return -1;
- }
- ALOGI("%s: exit", __func__);
- return ucMessageLength;
-}
-
-ANTStatus ant_rx_check()
-{
- ALOGV("%s: start", __func__);
- Lock lock(ant_hci.data_mtx);
- while (ant_hci.rx_processing == 0)
- {
- ant_hci.data_cond.wait_for(lock,std::chrono::milliseconds(POLL_TIMEOUT_MS));
- if (ant_hci.state != ANT_RADIO_ENABLED)
- {
- return ANT_STATUS_NO_VALUE_AVAILABLE;
- }
- }
- ALOGV("%s: exit rx_processing =%d", __func__,ant_hci.rx_processing);
- return ANT_STATUS_SUCCESS;
-}
-
-void ant_rx_clear()
-{
- ALOGI("%s: start", __func__);
- Lock lk(ant_hci.rx_mtx);
- ant_hci.rx_processing = false;
- ant_hci.rx_cond.notify_all();
- ALOGI("%s: exit", __func__);
-}
-
-void ant_interface_init()
-{
- ALOGI("%s: start", __func__);
- bool status;
- status = hci_initialize();
- if (status)
- {
- ALOGV("%s waiting for iniialization complete hci state: %d ", __func__, ant_hci.state);
- Lock lk(ant_hci.on_mtx);
- while(ant_hci.state == ANT_RADIO_ENABLING)
- {
- ant_hci.on_cond.wait(lk);
- ALOGV(LOG_TAG,"%s:after on_cond wait ",__func__);
- }
- } else {
- ALOGE(LOG_TAG,"%s:Failed ",__func__);
- ant_hci.state = ANT_RADIO_DISABLED;
- }
- ALOGI(LOG_TAG,"%s:exit ",__func__);
-}
diff --git a/src/qcomm-hidl/ant_native_chardev.c b/src/qcomm-hidl/ant_native_chardev.c
deleted file mode 100644
index 072dbb7..0000000
--- a/src/qcomm-hidl/ant_native_chardev.c
+++ /dev/null
@@ -1,918 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2011 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/******************************************************************************\
-*
-* FILE NAME: ant_native_chardev.c
-*
-* BRIEF:
-* This file provides the VFS implementation of ant_native.h
-* VFS could be Character Device, TTY, etc.
-*
-*
-\******************************************************************************/
-
-#include <errno.h>
-#include <fcntl.h> /* for open() */
-#include <linux/ioctl.h> /* For hard reset */
-#include <pthread.h>
-#include <dlfcn.h> /* needed for runtime dll loading. */
-#include <stdint.h> /* for uint64_t */
-#include <sys/eventfd.h> /* For eventfd() */
-#include <unistd.h> /* for read(), write(), and close() */
-#include <string.h>
-
-#include "ant_types.h"
-#include "ant_native.h"
-#include "ant_version.h"
-
-#include "AntHidlClient.h"
-#include "antradio_power.h"
-#include "ant_rx_chardev.h"
-#include "ant_hci_defines.h"
-#include "ant_log.h"
-#include <cutils/properties.h> /* used by qualcomms additions for logging. */
-
-
-#if ANT_HCI_SIZE_SIZE > 1
-#include "ant_utils.h" // Put HCI Size value across multiple bytes
-#endif
-
-#define MESG_BROADCAST_DATA_ID ((ANT_U8)0x4E)
-#define MESG_ACKNOWLEDGED_DATA_ID ((ANT_U8)0x4F)
-#define MESG_BURST_DATA_ID ((ANT_U8)0x50)
-#define MESG_EXT_BROADCAST_DATA_ID ((ANT_U8)0x5D)
-#define MESG_EXT_ACKNOWLEDGED_DATA_ID ((ANT_U8)0x5E)
-#define MESG_EXT_BURST_DATA_ID ((ANT_U8)0x5F)
-#define MESG_ADV_BURST_DATA_ID ((ANT_U8)0x72)
-
-static ant_rx_thread_info_t stRxThreadInfo;
-static pthread_mutex_t stEnabledStatusLock = PTHREAD_MUTEX_INITIALIZER;
-static pthread_mutex_t stFlowControlLock = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t stFlowControlCond = PTHREAD_COND_INITIALIZER;
-ANTNativeANTStateCb g_fnStateCallback;
-
-static const uint64_t EVENT_FD_PLUS_ONE = 1L;
-
-static void ant_channel_init(ant_channel_info_t *pstChnlInfo, const char *pcCharDevName);
-
-////////////////////////////////////////////////////////////////////
-// ant_init
-//
-// Initialises the native environment.
-//
-// Parameters:
-// -
-//
-// Returns:
-// ANT_STATUS_SUCCESS if intialize completed, else ANT_STATUS_FAILED
-//
-// Psuedocode:
-/*
-Set variables to defaults
-Initialise each supported path to chip
-Setup eventfd object.
-RESULT = ANT_STATUS_SUCCESS if no problems else ANT_STATUS_FAILED
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_init(void)
-{
- ANTStatus status = ANT_STATUS_FAILED;
- ANT_FUNC_START();
-
- stRxThreadInfo.stRxThread = 0;
- stRxThreadInfo.ucRunThread = 0;
- stRxThreadInfo.ucChipResetting = 0;
- stRxThreadInfo.pstEnabledStatusLock = &stEnabledStatusLock;
- g_fnStateCallback = 0;
-
-#ifdef ANT_DEVICE_NAME // Single transport path
- ant_channel_init(&stRxThreadInfo.astChannels[SINGLE_CHANNEL], ANT_DEVICE_NAME);
-#else // Separate data/command paths
- ant_channel_init(&stRxThreadInfo.astChannels[COMMAND_CHANNEL], ANT_COMMANDS_DEVICE_NAME);
- ant_channel_init(&stRxThreadInfo.astChannels[DATA_CHANNEL], ANT_DATA_DEVICE_NAME);
-#endif // Separate data/command paths
-
- // Make the eventfd. Want it non blocking so that we can easily reset it by reading.
- stRxThreadInfo.iRxShutdownEventFd = eventfd(0, EFD_NONBLOCK);
-
- // Check for error case
- if(stRxThreadInfo.iRxShutdownEventFd == -1)
- {
- ANT_ERROR("ANT init failed. Could not create event fd. Reason: %s", strerror(errno));
- } else {
- status = ANT_STATUS_SUCCESS;
- }
-
- ANT_FUNC_END();
- return status;
-}
-
-////////////////////////////////////////////////////////////////////
-// ant_deinit
-//
-// clean up eventfd object
-//
-// Parameters:
-// -
-//
-// Returns:
-// ANT_STATUS_SUCCESS
-//
-// Psuedocode:
-/*
-RESULT = SUCCESS
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_deinit(void)
-{
- ANTStatus result_status = ANT_STATUS_FAILED;
- ANT_FUNC_START();
-
- if(close(stRxThreadInfo.iRxShutdownEventFd) < 0)
- {
- ANT_ERROR("Could not close eventfd in deinit. Reason: %s", strerror(errno));
- } else {
- result_status = ANT_STATUS_SUCCESS;
- }
-
- ANT_FUNC_END();
- return result_status;
-}
-
-
-////////////////////////////////////////////////////////////////////
-// ant_enable_radio
-//
-// Powers on the ANT part and initialises the transport to the chip.
-// Changes occur in part implementing ant_enable() call
-//
-// Parameters:
-// -
-//
-// Returns:
-// Success:
-// ANT_STATUS_SUCCESS
-// Failures:
-// ANT_STATUS_TRANSPORT_INIT_ERR if could not enable
-// ANT_STATUS_FAILED if failed to get mutex or init rx thread
-//
-// Psuedocode:
-/*
-LOCK enable_LOCK
- State callback: STATE = ENABLING
- ant enable
- IF ant_enable success
- State callback: STATE = ENABLED
- RESULT = SUCCESS
- ELSE
- ant disable
- State callback: STATE = Current state
- RESULT = FAILURE
- ENDIF
-UNLOCK
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_enable_radio(void)
-{
- int iLockResult;
- ANTStatus result_status = ANT_STATUS_FAILED;
- ANT_FUNC_START();
-
- ANT_DEBUG_V("getting stEnabledStatusLock in %s", __FUNCTION__);
- iLockResult = pthread_mutex_lock(&stEnabledStatusLock);
- if(iLockResult) {
- ANT_ERROR("enable failed to get state lock: %s", strerror(iLockResult));
- goto out;
- }
- ANT_DEBUG_V("got stEnabledStatusLock in %s", __FUNCTION__);
-
- if (g_fnStateCallback) {
- g_fnStateCallback(RADIO_STATUS_ENABLING);
- }
-
- if (ant_enable() < 0) {
- ANT_ERROR("ant enable failed: %s", strerror(errno));
-
- ant_disable();
-
- if (g_fnStateCallback) {
- g_fnStateCallback(ant_radio_enabled_status());
- }
- } else {
- if (g_fnStateCallback) {
- g_fnStateCallback(RADIO_STATUS_ENABLED);
- }
-
- result_status = ANT_STATUS_SUCCESS;
- }
-
- ANT_DEBUG_V("releasing stEnabledStatusLock in %s", __FUNCTION__);
- pthread_mutex_unlock(&stEnabledStatusLock);
- ANT_DEBUG_V("released stEnabledStatusLock in %s", __FUNCTION__);
-
-out:
- ANT_FUNC_END();
- return result_status;
-}
-
-////////////////////////////////////////////////////////////////////
-// ant_radio_hard_reset
-//
-// IF SUPPORTED triggers a hard reset of the chip providing ANT functionality.
-//
-// Parameters:
-// -
-//
-// Returns:
-// Success:
-// ANT_STATUS_SUCCESS
-// Failures:
-// ANT_STATUS_NOT_SUPPORTED if the chip can't hard reset
-// ANT_STATUS_FAILED if failed to get mutex or enable
-//
-// Psuedocode:
-/*
-IF Hard Reset not supported
- RESULT = NOT SUPPORTED
-ELSE
- LOCK enable_LOCK
- IF Lock failed
- RESULT = FAILED
- ELSE
- Set Flag Rx thread that chip is resetting
- FOR each path to chip
- Send Reset IOCTL to path
- ENDFOR
- ant disable
- ant enable
- IF ant_enable success
- State callback: STATE = RESET
- RESULT = SUCCESS
- ELSE
- State callback: STATE = DISABLED
- RESULT = FAILURE
- ENDIF
- Clear Flag Rx thread that chip is resetting
- UNLOCK
-ENDIF
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_radio_hard_reset(void)
-{
- ANTStatus result_status = ANT_STATUS_NOT_SUPPORTED;
- ANT_FUNC_START();
-
-#ifdef ANT_IOCTL_RESET
- ant_channel_type eChannel;
- int iLockResult;
-
- result_status = ANT_STATUS_FAILED;
-
- ANT_DEBUG_V("getting stEnabledStatusLock in %s", __FUNCTION__);
- iLockResult = pthread_mutex_lock(&stEnabledStatusLock);
- if(iLockResult) {
- ANT_ERROR("enable failed to get state lock: %s", strerror(iLockResult));
- goto out;
- }
- ANT_DEBUG_V("got stEnabledStatusLock in %s", __FUNCTION__);
-
- stRxThreadInfo.ucChipResetting = 1;
- if (g_fnStateCallback)
- g_fnStateCallback(RADIO_STATUS_RESETTING);
-
-#ifdef ANT_IOCTL_RESET_PARAMETER
- ioctl(stRxThreadInfo.astChannels[0].iFd, ANT_IOCTL_RESET, ANT_IOCTL_RESET_PARAMETER);
-#else
- ioctl(stRxThreadInfo.astChannels[0].iFd, ANT_IOCTL_RESET);
-#endif // ANT_IOCTL_RESET_PARAMETER
-
- ant_disable();
-
- if (ant_enable()) { /* failed */
- if (g_fnStateCallback)
- g_fnStateCallback(RADIO_STATUS_DISABLED);
- } else { /* success */
- if (g_fnStateCallback)
- g_fnStateCallback(RADIO_STATUS_RESET);
- result_status = ANT_STATUS_SUCCESS;
- }
- stRxThreadInfo.ucChipResetting = 0;
-
- ANT_DEBUG_V("releasing stEnabledStatusLock in %s", __FUNCTION__);
- pthread_mutex_unlock(&stEnabledStatusLock);
- ANT_DEBUG_V("released stEnabledStatusLock in %s", __FUNCTION__);
-out:
-#endif // ANT_IOCTL_RESET
-
- ANT_FUNC_END();
- return result_status;
-}
-
-////////////////////////////////////////////////////////////////////
-// ant_disable_radio
-//
-// Powers off the ANT part and closes the transport to the chip.
-//
-// Parameters:
-// -
-//
-// Returns:
-// Success:
-// ANT_STATUS_SUCCESS
-// Failures:
-// ANT_STATUS_FAILED if failed to get mutex
-//
-// Psuedocode:
-/*
-LOCK enable_LOCK
- State callback: STATE = DISABLING
- ant disable
- State callback: STATE = Current state
- RESULT = SUCCESS
-UNLOCK
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_disable_radio(void)
-{
- int iLockResult;
- ANTStatus ret = ANT_STATUS_FAILED;
- ANT_FUNC_START();
-
- ANT_DEBUG_V("getting stEnabledStatusLock in %s", __FUNCTION__);
- iLockResult = pthread_mutex_lock(&stEnabledStatusLock);
- if(iLockResult) {
- ANT_ERROR("disable failed to get state lock: %s", strerror(iLockResult));
- goto out;
- }
- ANT_DEBUG_V("got stEnabledStatusLock in %s", __FUNCTION__);
-
- if (g_fnStateCallback) {
- g_fnStateCallback(RADIO_STATUS_DISABLING);
- }
-
- ant_disable();
-
- if (g_fnStateCallback) {
- g_fnStateCallback(ant_radio_enabled_status());
- }
-
- ret = ANT_STATUS_SUCCESS;
-
- ANT_DEBUG_V("releasing stEnabledStatusLock in %s", __FUNCTION__);
- pthread_mutex_unlock(&stEnabledStatusLock);
- ANT_DEBUG_V("released stEnabledStatusLock in %s", __FUNCTION__);
-
-out:
- ANT_FUNC_END();
- return ret;
-}
-
-////////////////////////////////////////////////////////////////////
-// ant_radio_enabled_status
-//
-// Gets the current chip/transport state; either disabled, disabling,
-// enabling, enabled, or resetting. Determines this on the fly by checking
-// if Rx thread is running and how many of the paths for the ANT chip have
-// open VFS files.
-//
-// Parameters:
-// -
-//
-// Returns:
-// The current radio status (ANTRadioEnabledStatus)
-//
-// Psuedocode:
-/*
-IF Thread Resetting Flag is set
- RESULT = Resetting
-ELSE
- COUNT the number of open files
- IF Thread Run Flag is Not Set
- IF there are open files OR Rx thread exists
- RESULT = Disabling
- ELSE
- RESULT = Disabled
- ENDIF
- ELSE
- IF All files are open (all paths) AND Rx thread exists
- RESULT = ENABLED
- ELSE IF there are open files (Not 0 open files) AND Rx thread exists
- RESULT = UNKNOWN
- ELSE (0 open files or Rx thread does not exist [while Thread Run set])
- RESULT = ENABLING
- ENDIF
- ENDIF
-ENDIF
-*/
-////////////////////////////////////////////////////////////////////
-ANTRadioEnabledStatus ant_radio_enabled_status(void)
-{
- ant_channel_type eChannel;
- int iOpenFiles = 0;
- int iOpenThread;
- ANTRadioEnabledStatus uiRet = RADIO_STATUS_UNKNOWN;
- ANT_FUNC_START();
-
- if (stRxThreadInfo.ucChipResetting) {
- uiRet = RADIO_STATUS_RESETTING;
- goto out;
- }
-
- uiRet = ant_get_status();
- ANT_ERROR("ANT radio status =%d",uiRet);
-
-out:
- ANT_DEBUG_D("get radio enabled status returned %d", uiRet);
-
- ANT_FUNC_END();
- return uiRet;
-}
-
-////////////////////////////////////////////////////////////////////
-// set_ant_rx_callback
-//
-// Sets which function to call when an ANT message is received.
-//
-// Parameters:
-// rx_callback_func the ANTNativeANTEventCb function to be used for
-// received messages (from all transport paths).
-//
-// Returns:
-// ANT_STATUS_SUCCESS
-//
-// Psuedocode:
-/*
-FOR each transport path
- Path Rx Callback = rx_callback_func
-ENDFOR
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus set_ant_rx_callback(ANTNativeANTEventCb rx_callback_func)
-{
- ANTStatus status = ANT_STATUS_SUCCESS;
- ANT_FUNC_START();
-
-#ifdef ANT_DEVICE_NAME // Single transport path
- stRxThreadInfo.astChannels[SINGLE_CHANNEL].fnRxCallback = rx_callback_func;
-#else // Separate data/command paths
- stRxThreadInfo.astChannels[COMMAND_CHANNEL].fnRxCallback = rx_callback_func;
- stRxThreadInfo.astChannels[DATA_CHANNEL].fnRxCallback = rx_callback_func;
-#endif // Separate data/command paths
-
- ANT_FUNC_END();
- return status;
-}
-
-////////////////////////////////////////////////////////////////////
-// set_ant_state_callback
-//
-// Sets which function to call when an ANT state change occurs.
-//
-// Parameters:
-// state_callback_func the ANTNativeANTStateCb function to be used
-// for received state changes.
-//
-// Returns:
-// ANT_STATUS_SUCCESS
-//
-// Psuedocode:
-/*
- State Callback = state_callback_func
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus set_ant_state_callback(ANTNativeANTStateCb state_callback_func)
-{
- ANTStatus status = ANT_STATUS_SUCCESS;
- ANT_FUNC_START();
-
- g_fnStateCallback = state_callback_func;
-
- ANT_FUNC_END();
- return status;
-}
-
-////////////////////////////////////////////////////////////////////
-// ant_tx_message_flowcontrol_wait
-//
-// Sends an ANT message to the chip and waits for a CTS signal
-//
-// Parameters:
-// eTxPath device to transmit message on
-// eFlowMessagePath device that receives CTS
-// ucMessageLength the length of the message
-// pucMesg pointer to the message data
-//
-// Returns:
-// Success:
-// ANT_STATUS_SUCCESS
-// Failure:
-// ANT_STATUS_NOT_ENABLED
-//
-// Psuedocode:
-/*
- LOCK flow control
- IF Lock failed
- RESULT = FAILED
- ELSE
- SET flowMessagePath Flow Control response as FLOW_STOP
- WRITE txBuffer to txPath (only length of packet part)
- IF Wrote less then 0 bytes
- Log error
- RESULT = FAILED
- ELSE IF Didn't write 'length of packet' bytes
- Log error
- RESULT = FAILED
- ELSE
- IF flowMessagePath Flow Control response is not FLOW_GO
- WAIT until flowMessagePath Flow Control response is FLOW_GO, UNTIL FLOW_GO Wait Timeout seconds (10) from Now
- IF error Waiting
- IF error is Timeout
- RESULT = HARDWARE ERROR
- ELSE
- RESULT = FAILED
- ENDIF
- ELSE
- RESULT = SUCCESS
- ENDIF
- ELSE
- RESULT = SUCCESS;
- ENDIF
- ENDIF
- UNLOCK flow control
- ENDIF
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_tx_message_flowcontrol_wait(ant_channel_type eTxPath, ant_channel_type eFlowMessagePath, ANT_U8 ucMessageLength, ANT_U8 *pucTxMessage)
-{
- int iMutexResult;
- int iResult;
- struct timespec stTimeout;
- int iCondWaitResult;
- ANTStatus status = ANT_STATUS_FAILED;
- ANT_FUNC_START();
-
- ANT_DEBUG_V("getting stFlowControlLock in %s", __FUNCTION__);
- iMutexResult = pthread_mutex_lock(&stFlowControlLock);
- if (iMutexResult) {
- ANT_ERROR("failed to lock flow control mutex during tx: %s", strerror(iMutexResult));
- goto out;
- }
- ANT_DEBUG_V("got stFlowControlLock in %s", __FUNCTION__);
-
- stRxThreadInfo.astChannels[eFlowMessagePath].ucFlowControlResp = ANT_FLOW_STOP;
-
-#ifdef ANT_FLOW_RESEND
- // Store Tx message so can resend it from Rx thread
- stRxThreadInfo.astChannels[eFlowMessagePath].ucResendMessageLength = ucMessageLength;
- stRxThreadInfo.astChannels[eFlowMessagePath].pucResendMessage = pucTxMessage;
-#endif // ANT_FLOW_RESEND
-
- iResult = ant_tx_write(pucTxMessage,ucMessageLength);
- if (iResult < 0) {
- ANT_ERROR("failed to write data message to device: %s", strerror(errno));
- } else if (iResult != ucMessageLength) {
- ANT_ERROR("bytes written and message size don't match up");
- } else {
- stTimeout.tv_sec = time(0) + ANT_FLOW_GO_WAIT_TIMEOUT_SEC;
- stTimeout.tv_nsec = 0;
-
- while (stRxThreadInfo.astChannels[eFlowMessagePath].ucFlowControlResp != ANT_FLOW_GO) {
- iCondWaitResult = pthread_cond_timedwait(&stFlowControlCond, &stFlowControlLock, &stTimeout);
- if (iCondWaitResult) {
- ANT_ERROR("failed to wait for flow control response: %s", strerror(iCondWaitResult));
-
- if (iCondWaitResult == ETIMEDOUT) {
- status = ANT_STATUS_HARDWARE_ERR;
-
-#ifdef ANT_FLOW_RESEND
- // Clear Tx message so will stop resending it from Rx thread
- stRxThreadInfo.astChannels[eFlowMessagePath].ucResendMessageLength = 0;
- stRxThreadInfo.astChannels[eFlowMessagePath].pucResendMessage = NULL;
-#endif // ANT_FLOW_RESEND
- }
- goto wait_error;
- }
- }
-
- status = ANT_STATUS_SUCCESS;
- }
-
-wait_error:
- ANT_DEBUG_V("releasing stFlowControlLock in %s", __FUNCTION__);
- pthread_mutex_unlock(&stFlowControlLock);
- ANT_DEBUG_V("released stFlowControlLock in %s", __FUNCTION__);
-
-out:
- ANT_FUNC_END();
- return status;
-}
-
-////////////////////////////////////////////////////////////////////
-// ant_tx_message_flowcontrol_none
-//
-// Sends an ANT message to the chip without waiting for flow control
-//
-// Parameters:
-// eTxPath device to transmit on
-// ucMessageLength the length of the message
-// pucMesg pointer to the message data
-//
-// Returns:
-// Success:
-// ANT_STATUS_SUCCESS
-// Failure:
-// ANT_STATUS_NOT_ENABLED
-//
-// Psuedocode:
-/*
- WRITE txBuffer to Tx Path (only length of packet part)
- IF Wrote less then 0 bytes
- Log error
- RESULT = FAILED
- ELSE IF Didn't write 'length of packet' bytes
- Log error
- RESULT = FAILED
- ELSE
- RESULT = SUCCESS
- ENDIF
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_tx_message_flowcontrol_none(ant_channel_type eTxPath, ANT_U8 ucMessageLength, ANT_U8 *pucTxMessage)
-{
- int iResult;
- ANTStatus status = ANT_STATUS_FAILED;\
- ANT_FUNC_START();
-
- iResult = ant_tx_write(pucTxMessage, ucMessageLength);
- if (iResult < 0) {
- ANT_ERROR("failed to write message to device: %s", strerror(errno));
- } else if (iResult != ucMessageLength) {
- ANT_ERROR("bytes written and message size don't match up");
- } else {
- status = ANT_STATUS_SUCCESS;
- }
-
- ANT_FUNC_END();
- return status;
-}
-
-////////////////////////////////////////////////////////////////////
-// ant_tx_message
-//
-// Frames ANT data and decides which flow control method to use for sending the
-// ANT message to the chip
-//
-// Parameters:
-// ucLen the length of the message
-// pucMesg pointer to the message data
-//
-// Returns:
-// Success:
-// ANT_STATUS_SUCCESS
-// Failure:
-// ANT_STATUS_NOT_ENABLED
-//
-// Psuedocode:
-/*
-IF not enabled
- RESULT = BT NOT INITIALIZED
-ELSE
- Create txBuffer, MAX HCI Message Size large
- PUT ucLen in txBuffer AT ANT HCI Size Offset (0)
- COPY pucMesg to txBuffer AT ANT HCI Header Size (1) <- ? Not at offset?
- LOG txBuffer as a serial Tx (only length of packet part)
- IF is a data message
- Tx message on Data Path with FLOW_GO/FLOW_STOP flow control (ant_tx_message_flowcontrol_go_stop())
- ELSE
- Tx message on Command Path with no flow control (ant_tx_message_flowcontrol_none())
- ENDIF
-ENDIF
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_tx_message(ANT_U8 ucLen, ANT_U8 *pucMesg)
-{
- // During a tx we must prepend a packet type byte. Thus HCI_PACKET_TYPE_SIZE is added
- // to all offsets when writing into the tx buffer.
- ANTStatus status = ANT_STATUS_FAILED;
- // TODO ANT_HCI_MAX_MSG_SIZE is transport (driver) dependent.
- ANT_U8 txBuffer[HCI_PACKET_TYPE_SIZE + ANT_HCI_MAX_MSG_SIZE];
- // TODO Message length can be greater than ANT_U8 can hold.
- // Not changed as ANT_SERIAL takes length as ANT_U8.
- ANT_U8 txMessageLength = HCI_PACKET_TYPE_SIZE + ucLen + ANT_HCI_HEADER_SIZE;
- ANT_FUNC_START();
-
- if (ant_radio_enabled_status() != RADIO_STATUS_ENABLED) {
- status = ANT_STATUS_FAILED_BT_NOT_INITIALIZED;
- goto out;
- }
-
-#if ANT_HCI_OPCODE_SIZE == 1
- txBuffer[HCI_PACKET_TYPE_SIZE + ANT_HCI_OPCODE_OFFSET] = ANT_HCI_OPCODE_TX;
-#elif ANT_HCI_OPCODE_SIZE > 1
-#error "Specified ANT_HCI_OPCODE_SIZE not currently supported"
-#endif
-
-#if ANT_HCI_SIZE_SIZE == 1
- txBuffer[HCI_PACKET_TYPE_SIZE + ANT_HCI_SIZE_OFFSET] = ucLen;
-#elif ANT_HCI_SIZE_SIZE == 2
- ANT_UTILS_StoreLE16(txBuffer + HCI_PACKET_TYPE_SIZE + ANT_HCI_SIZE_OFFSET, (ANT_U16)ucLen);
-#else
-#error "Specified ANT_HCI_SIZE_SIZE not currently supported"
-#endif
-
- memcpy(txBuffer + HCI_PACKET_TYPE_SIZE + ANT_HCI_HEADER_SIZE, pucMesg, ucLen);
-
-// We no longer do the serial logging here because the packet type byte is not yet written.
-//ANT_SERIAL(txBuffer, txMessageLength, 'T');
-
-// We only do this if we are using single physical and logical channels.
-#if defined(ANT_DEVICE_NAME) && (HCI_PACKET_TYPE_SIZE == 0) // Single transport path
- ANT_SERIAL(txBuffer, txMessageLength, 'T');
- status = ant_tx_message_flowcontrol_wait(SINGLE_CHANNEL, SINGLE_CHANNEL, txMessageLength, txBuffer);
-#else // Separate data/command paths
- // Each path follows this structure:
- // write the packet type if needed.
- // log the packet
- // Send using the appropriate physical channel, waiting for flow control for data commands.
- switch (txBuffer[HCI_PACKET_TYPE_SIZE + ANT_HCI_DATA_OFFSET + ANT_MSG_ID_OFFSET]) {
- case MESG_BROADCAST_DATA_ID:
- case MESG_ACKNOWLEDGED_DATA_ID:
- case MESG_BURST_DATA_ID:
- case MESG_EXT_BROADCAST_DATA_ID:
- case MESG_EXT_ACKNOWLEDGED_DATA_ID:
- case MESG_EXT_BURST_DATA_ID:
- case MESG_ADV_BURST_DATA_ID:
- ANT_DEBUG_V("Data Path");
- #if HCI_PACKET_TYPE_SIZE == 1
- txBuffer[0] = ANT_DATA_TYPE_PACKET;
- #elif HCI_PACKET_TYPE_SIZE > 1
- #error "Specified HCI_PACKET_TYPE_SIZE not supported"
- #endif
- ANT_SERIAL(txBuffer, txMessageLength, 'T');
- #ifdef ANT_DEVICE_NAME
- status = ant_tx_message_flowcontrol_wait(SINGLE_CHANNEL, SINGLE_CHANNEL, txMessageLength, txBuffer);
- #else
- status = ant_tx_message_flowcontrol_wait(DATA_CHANNEL, COMMAND_CHANNEL, txMessageLength, txBuffer);
- #endif
- break;
- default:
- ANT_DEBUG_V("Control Path");
- #if HCI_PACKET_TYPE_SIZE == 1
- txBuffer[0] = ANT_CMD_TYPE_PACKET;
- #elif HCI_PACKET_TYPE_SIZE > 1
- #error "Specified HCI_PACKET_TYPE_SIZE not supported"
- #endif
- ANT_SERIAL(txBuffer, txMessageLength, 'T');
- #ifdef ANT_DEVICE_NAME
- status = ant_tx_message_flowcontrol_none(SINGLE_CHANNEL, txMessageLength, txBuffer);
- #else
- status = ant_tx_message_flowcontrol_none(COMMAND_CHANNEL, txMessageLength, txBuffer);
- #endif
- }
-#endif // Separate data/command paths
-
-out:
- ANT_FUNC_END();
- return status;
-}
-
-//----------------- TODO Move these somewhere for multi transport path / dedicated channel support:
-
-static void ant_channel_init(ant_channel_info_t *pstChnlInfo, const char *pcCharDevName)
-{
- ANT_FUNC_START();
-
- // TODO Don't need to store, only accessed when trying to open:
- // Is however useful for logs.
- pstChnlInfo->pcDevicePath = pcCharDevName;
-
- // This is the only piece of info that needs to be stored per channel
- pstChnlInfo->iFd = -1;
-
- // TODO Only 1 of these (not per-channel) is actually ever used:
- pstChnlInfo->fnRxCallback = NULL;
- pstChnlInfo->ucFlowControlResp = ANT_FLOW_GO;
-#ifdef ANT_FLOW_RESEND
- pstChnlInfo->ucResendMessageLength = 0;
- pstChnlInfo->pucResendMessage = NULL;
-#endif // ANT_FLOW_RESEND
- // TODO Only used when Flow Control message received, so must only be Command path Rx thread
- pstChnlInfo->pstFlowControlCond = &stFlowControlCond;
- pstChnlInfo->pstFlowControlLock = &stFlowControlLock;
-
- ANT_FUNC_END();
-}
-
-static void ant_disable_channel(ant_channel_info_t *pstChnlInfo)
-{
- ANT_FUNC_START();
- if (!pstChnlInfo) {
- ANT_ERROR("null channel info passed to channel disable function");
- goto out;
- }
-
- hci_close();
-
-out:
- ANT_FUNC_END();
-}
-
-static int ant_enable_channel(ant_channel_info_t *pstChnlInfo)
-{
- int iRet = -1;
- ANT_FUNC_START();
- if (!pstChnlInfo) {
- ANT_ERROR("null channel info passed to channel enable function");
- errno = EINVAL;
- goto out;
- }
- ANT_DEBUG_V("call HIDL init");
- ant_interface_init();
- iRet = 0;
-out:
- ANT_FUNC_END();
- return iRet;
-}
-
-//----------------------------------------------------------------------- This is antradio_power.h:
-
-int ant_enable(void)
-{
- int iRet = -1;
- ant_channel_type eChannel;
- ANT_FUNC_START();
-
- stRxThreadInfo.ucRunThread = 1;
-
- for (eChannel = 0; eChannel < NUM_ANT_CHANNELS; eChannel++) {
- if (ant_enable_channel(&stRxThreadInfo.astChannels[eChannel]) < 0) {
- ANT_ERROR("failed to enable channel %s: %s",
- stRxThreadInfo.astChannels[eChannel].pcDevicePath,
- strerror(errno));
- goto out;
- }
- }
-
- if (stRxThreadInfo.stRxThread == 0) {
- if (pthread_create(&stRxThreadInfo.stRxThread, NULL, fnRxThread, &stRxThreadInfo) < 0) {
- ANT_ERROR("failed to start rx thread: %s", strerror(errno));
- goto out;
- }
- } else {
- ANT_DEBUG_D("rx thread is already running");
- }
-
- if (!stRxThreadInfo.ucRunThread) {
- ANT_ERROR("rx thread crashed during init");
- goto out;
- }
-
- iRet = 0;
-
-out:
- ANT_FUNC_END();
- return iRet;
-}
-
-int ant_disable(void)
-{
- int iRet = -1;
- ant_channel_type eChannel;
- ANT_FUNC_START();
-
- stRxThreadInfo.ucRunThread = 0;
-
- for (eChannel = 0; eChannel < NUM_ANT_CHANNELS; eChannel++) {
- ant_disable_channel(&stRxThreadInfo.astChannels[eChannel]);
- }
-
- iRet = 0;
-
-out:
- stRxThreadInfo.stRxThread = 0;
- ANT_FUNC_END();
- return iRet;
-}
-
-//---------------------------------------------------------
-
-const char *ant_get_lib_version()
-{
- return "libantradio.so: "ANT_CHIP_NAME". Version "
- LIBANT_STACK_MAJOR"."LIBANT_STACK_MINOR"."LIBANT_STACK_INCRE;
-}
diff --git a/src/qcomm-hidl/ant_rx_chardev.c b/src/qcomm-hidl/ant_rx_chardev.c
deleted file mode 100644
index 3e102d2..0000000
--- a/src/qcomm-hidl/ant_rx_chardev.c
+++ /dev/null
@@ -1,351 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2011 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/******************************************************************************\
-*
-* FILE NAME: ant_rx_chardev.c
-*
-* BRIEF:
-* This file implements the receive thread function which will loop reading
-* ANT messages until told to exit.
-*
-*
-\******************************************************************************/
-
-#include <errno.h>
-#include <poll.h>
-#include <pthread.h>
-#include <stdint.h> /* for uint64_t */
-#include <string.h>
-
-#include "ant_types.h"
-#include "antradio_power.h"
-#include "ant_rx_chardev.h"
-#include "ant_hci_defines.h"
-#include "ant_log.h"
-#include "ant_native.h" // ANT_HCI_MAX_MSG_SIZE, ANT_MSG_ID_OFFSET, ANT_MSG_DATA_OFFSET,
- // ant_radio_enabled_status()
-
-#include "AntHidlClient.h"
-extern ANTStatus ant_tx_message_flowcontrol_none(ant_channel_type eTxPath, ANT_U8 ucMessageLength, ANT_U8 *pucTxMessage);
-
-#undef LOG_TAG
-#define LOG_TAG "antradio_rx"
-
-#define ANT_POLL_TIMEOUT ((int)30000)
-#define KEEPALIVE_TIMEOUT ((int)5000)
-
-ANT_U8 aucRxBuffer[NUM_ANT_CHANNELS][ANT_HCI_MAX_MSG_SIZE];
-
-#ifdef ANT_DEVICE_NAME // Single transport path
- int iRxBufferLength[NUM_ANT_CHANNELS] = {0};
-#else
- int iRxBufferLength[NUM_ANT_CHANNELS] = {0, 0};
-#endif //
-
-// Plus one is for the eventfd shutdown signal.
-#define NUM_POLL_FDS (NUM_ANT_CHANNELS + 1)
-#define EVENTFD_IDX NUM_ANT_CHANNELS
-
-static ANT_U8 KEEPALIVE_MESG[] = {0x01, 0x00, 0x00};
-static ANT_U8 KEEPALIVE_RESP[] = {0x03, 0x40, 0x00, 0x00, 0x28};
-
-void doReset(ant_rx_thread_info_t *stRxThreadInfo);
-int readChannelMsg(ant_channel_type eChannel, ant_channel_info_t *pstChnlInfo);
-
-
-/*
- * This thread is run occasionally as a detached thread in order to send a keepalive message to the
- * chip.
- */
-void *fnKeepAliveThread(void *unused)
-{
- ANT_DEBUG_V("Sending dummy keepalive message.");
- ant_tx_message(sizeof(KEEPALIVE_MESG)/sizeof(ANT_U8), KEEPALIVE_MESG);
- return NULL;
-}
-
-/*
- * This thread waits for ANT messages from a VFS file.
- */
-void *fnRxThread(void *ant_rx_thread_info)
-{
- int iMutexLockResult;
- int iPollRet;
- ant_rx_thread_info_t *stRxThreadInfo;
- struct pollfd astPollFd[NUM_POLL_FDS];
- ANT_FUNC_START();
-
- stRxThreadInfo = (ant_rx_thread_info_t *)ant_rx_thread_info;
- // Fill out poll request for the shutdown signaller.
- astPollFd[EVENTFD_IDX].fd = stRxThreadInfo->iRxShutdownEventFd;
- astPollFd[EVENTFD_IDX].events = POLL_IN;
-
- // Reset the waiting for response, since we don't want a stale value if we were reset.
- stRxThreadInfo->bWaitingForKeepaliveResponse = ANT_FALSE;
-
- /* continue running as long as not terminated */
- while (stRxThreadInfo->ucRunThread) {
- iPollRet = ant_rx_check();
- if(iPollRet == 0)
- {
- readChannelMsg(0, &stRxThreadInfo->astChannels[0]);
- }
- else
- {
- ANT_WARN("rx check failed , cleaning up");
- break;
- }
- // Need to indicate that we are done handling the rx buffer and it can be
- // overwritten again.
- ant_rx_clear();
- }
-
- /* disable ANT radio if not already disabling */
- // Try to get stEnabledStatusLock.
- // if you get it then no one is enabling or disabling
- // if you can't get it assume something made you exit
- ANT_DEBUG_V("try getting stEnabledStatusLock in %s", __FUNCTION__);
- iMutexLockResult = pthread_mutex_trylock(stRxThreadInfo->pstEnabledStatusLock);
- if (!iMutexLockResult) {
- ANT_DEBUG_V("got stEnabledStatusLock in %s", __FUNCTION__);
- ANT_WARN("rx thread has unexpectedly crashed, cleaning up");
-
- // spoof our handle as closed so we don't try to join ourselves in disable
- stRxThreadInfo->stRxThread = 0;
-
- if (g_fnStateCallback) {
- g_fnStateCallback(RADIO_STATUS_DISABLING);
- }
-
- ant_disable();
-
- if (g_fnStateCallback) {
- g_fnStateCallback(ant_radio_enabled_status());
- }
-
- ANT_DEBUG_V("releasing stEnabledStatusLock in %s", __FUNCTION__);
- pthread_mutex_unlock(stRxThreadInfo->pstEnabledStatusLock);
- ANT_DEBUG_V("released stEnabledStatusLock in %s", __FUNCTION__);
- } else if (iMutexLockResult != EBUSY) {
- ANT_ERROR("rx thread closing code, trylock on state lock failed: %s",
- strerror(iMutexLockResult));
- } else {
- ANT_DEBUG_V("stEnabledStatusLock busy");
- }
-
- out:
- ANT_FUNC_END();
-#ifdef ANDROID
- return NULL;
-#endif
-}
-
-void doReset(ant_rx_thread_info_t *stRxThreadInfo)
-{
- int iMutexLockResult;
-
- ANT_FUNC_START();
- /* Chip was reset or other error, only way to recover is to
- * close and open ANT chardev */
- stRxThreadInfo->ucChipResetting = 1;
-
- if (g_fnStateCallback) {
- g_fnStateCallback(RADIO_STATUS_RESETTING);
- }
-
- stRxThreadInfo->ucRunThread = 0;
-
- ANT_DEBUG_V("getting stEnabledStatusLock in %s", __FUNCTION__);
- iMutexLockResult = pthread_mutex_lock(stRxThreadInfo->pstEnabledStatusLock);
- if (iMutexLockResult < 0) {
- ANT_ERROR("chip was reset, getting state mutex failed: %s",
- strerror(iMutexLockResult));
- stRxThreadInfo->stRxThread = 0;
- stRxThreadInfo->ucChipResetting = 0;
- } else {
- ANT_DEBUG_V("got stEnabledStatusLock in %s", __FUNCTION__);
-
- stRxThreadInfo->stRxThread = 0; /* spoof our handle as closed so we don't
- * try to join ourselves in disable */
-
- ant_disable();
-
- int enableResult = ant_enable();
-
- stRxThreadInfo->ucChipResetting = 0;
- if (enableResult) { /* failed */
- if (g_fnStateCallback) {
- g_fnStateCallback(RADIO_STATUS_DISABLED);
- }
- } else { /* success */
- if (g_fnStateCallback) {
- g_fnStateCallback(RADIO_STATUS_RESET);
- }
- }
-
- ANT_DEBUG_V("releasing stEnabledStatusLock in %s", __FUNCTION__);
- pthread_mutex_unlock(stRxThreadInfo->pstEnabledStatusLock);
- ANT_DEBUG_V("released stEnabledStatusLock in %s", __FUNCTION__);
- }
-
- ANT_FUNC_END();
-}
-
-////////////////////////////////////////////////////////////////////
-// setFlowControl
-//
-// Sets the flow control "flag" to the value provided and signals the transmit
-// thread to check the value.
-//
-// Parameters:
-// pstChnlInfo the details of the channel being updated
-// ucFlowSetting the value to use
-//
-// Returns:
-// Success:
-// 0
-// Failure:
-// -1
-////////////////////////////////////////////////////////////////////
-int setFlowControl(ant_channel_info_t *pstChnlInfo, ANT_U8 ucFlowSetting)
-{
- int iRet = -1;
- int iMutexResult;
- ANT_FUNC_START();
-
- ANT_DEBUG_V("getting stFlowControlLock in %s", __FUNCTION__);
- iMutexResult = pthread_mutex_lock(pstChnlInfo->pstFlowControlLock);
- if (iMutexResult) {
- ANT_ERROR("failed to lock flow control mutex during response: %s", strerror(iMutexResult));
- } else {
- ANT_DEBUG_V("got stFlowControlLock in %s", __FUNCTION__);
-
- pstChnlInfo->ucFlowControlResp = ucFlowSetting;
-
- ANT_DEBUG_V("releasing stFlowControlLock in %s", __FUNCTION__);
- pthread_mutex_unlock(pstChnlInfo->pstFlowControlLock);
- ANT_DEBUG_V("released stFlowControlLock in %s", __FUNCTION__);
-
- pthread_cond_signal(pstChnlInfo->pstFlowControlCond);
-
- iRet = 0;
- }
-
- ANT_FUNC_END();
- return iRet;
-}
-
-int readChannelMsg(ant_channel_type eChannel, ant_channel_info_t *pstChnlInfo)
-{
- int iRet = -1;
- int iRxLenRead = 0;
- int iCurrentHciPacketOffset;
- int iHciDataSize;
- ANT_FUNC_START();
-
- // Keep trying to read while there is an error, and that error is EAGAIN
- {
- iRxLenRead += iRxBufferLength[eChannel]; // add existing data on
- ANT_DEBUG_D("iRxLenRead %d",iRxLenRead);
- ANT_SERIAL(aucRxBuffer[eChannel], iRxLenRead, 'R');
-
- // if we didn't get a full packet, then just exit
- if (iRxLenRead < (aucRxBuffer[eChannel][ANT_HCI_SIZE_OFFSET] + ANT_HCI_HEADER_SIZE + ANT_HCI_FOOTER_SIZE)) {
- iRxBufferLength[eChannel] = iRxLenRead;
- iRet = 0;
- goto out;
- }
-
- iRxBufferLength[eChannel] = 0; // reset buffer length here since we should have a full packet
-
-#if ANT_HCI_OPCODE_SIZE == 1 // Check the different message types by opcode
- ANT_U8 opcode = aucRxBuffer[eChannel][ANT_HCI_OPCODE_OFFSET];
-
- if(ANT_HCI_OPCODE_COMMAND_COMPLETE == opcode) {
- // Command Complete, so signal a FLOW_GO
- if(setFlowControl(pstChnlInfo, ANT_FLOW_GO)) {
- goto out;
- }
- } else if(ANT_HCI_OPCODE_FLOW_ON == opcode) {
- // FLow On, so resend the last Tx
-#ifdef ANT_FLOW_RESEND
- // Check if there is a message to resend
- if(pstChnlInfo->ucResendMessageLength > 0) {
- ant_tx_message_flowcontrol_none(eChannel, pstChnlInfo->ucResendMessageLength, pstChnlInfo->pucResendMessage);
- } else {
- ANT_DEBUG_D("Resend requested by chip, but tx request cancelled");
- }
-#endif // ANT_FLOW_RESEND
- } else if(ANT_HCI_OPCODE_ANT_EVENT == opcode)
- // ANT Event, send ANT packet to Rx Callback
-#endif // ANT_HCI_OPCODE_SIZE == 1
- {
- // Received an ANT packet
- iCurrentHciPacketOffset = 0;
-
- while(iCurrentHciPacketOffset < iRxLenRead) {
- ANT_DEBUG_D("iRxLenRead = %d",iRxLenRead);
-
- // TODO Allow HCI Packet Size value to be larger than 1 byte
- // This currently works as no size value is greater than 255, and little endian
- iHciDataSize = aucRxBuffer[eChannel][iCurrentHciPacketOffset + ANT_HCI_SIZE_OFFSET];
-
- if ((iHciDataSize + ANT_HCI_HEADER_SIZE + ANT_HCI_FOOTER_SIZE + iCurrentHciPacketOffset) >
- iRxLenRead) {
- // we don't have a whole packet
- iRxBufferLength[eChannel] = iRxLenRead - iCurrentHciPacketOffset;
- memcpy(aucRxBuffer[eChannel], &aucRxBuffer[eChannel][iCurrentHciPacketOffset], iRxBufferLength[eChannel]);
- // the increment at the end should push us out of the while loop
- } else
-#ifdef ANT_MESG_FLOW_CONTROL
- if (aucRxBuffer[eChannel][iCurrentHciPacketOffset + ANT_HCI_DATA_OFFSET + ANT_MSG_ID_OFFSET] ==
- ANT_MESG_FLOW_CONTROL) {
- // This is a flow control packet, not a standard ANT message
- if(setFlowControl(pstChnlInfo, \
- aucRxBuffer[eChannel][iCurrentHciPacketOffset + ANT_HCI_DATA_OFFSET + ANT_MSG_DATA_OFFSET])) {
- goto out;
- }
- } else
-#endif // ANT_MESG_FLOW_CONTROL
- {
- ANT_U8 *msg = aucRxBuffer[eChannel] + iCurrentHciPacketOffset + ANT_HCI_DATA_OFFSET;
- ANT_BOOL bIsKeepAliveResponse = memcmp(msg, KEEPALIVE_RESP, sizeof(KEEPALIVE_RESP)/sizeof(ANT_U8)) == 0;
- if (bIsKeepAliveResponse) {
- ANT_DEBUG_V("Filtered out keepalive response.");
- } else if (pstChnlInfo->fnRxCallback != NULL) {
- ANT_DEBUG_V("call rx callback hci data size = %d",iHciDataSize);
-
- // Loop through read data until all HCI packets are written to callback
- pstChnlInfo->fnRxCallback(iHciDataSize, \
- msg);
- } else {
- ANT_WARN("%s rx callback is null", pstChnlInfo->pcDevicePath);
- }
- }
-
- iCurrentHciPacketOffset = iCurrentHciPacketOffset + ANT_HCI_HEADER_SIZE + ANT_HCI_FOOTER_SIZE + iHciDataSize;
- }
- }
-
- iRet = 0;
- }
-
-out:
- ANT_FUNC_END();
- return iRet;
-}
diff --git a/src/qcomm-hidl/inc/AntHidlClient.h b/src/qcomm-hidl/inc/AntHidlClient.h
deleted file mode 100644
index cbb81d8..0000000
--- a/src/qcomm-hidl/inc/AntHidlClient.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- *Copyright (c) 2017, The Linux Foundation. All rights reserved.
- *
- *
- *Redistribution and use in source and binary forms, with or without
- *modification, are permitted provided that the following conditions are
- *met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * * Neither the name of The Linux Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- *
- *THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
- *WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
- *ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
- *BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- *CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- *SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- *WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- *OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
- *IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-#include "ant_driver_defines.h"
-#include "ant_rx_chardev.h"
-
-extern ANT_U8 aucRxBuffer[NUM_ANT_CHANNELS][ANT_HCI_MAX_MSG_SIZE];
-
-extern int iRxBufferLength[NUM_ANT_CHANNELS];
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
- void ant_interface_init();
- void hci_close();
-
- ANTStatus ant_tx_write(ANT_U8 *pucTxMessage,ANT_U8 ucMessageLength);
- ANTStatus ant_rx_check();
- void ant_rx_clear();
-
- ANT_UINT ant_get_status();
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/src/qcomm-hidl/inc/ant_hci_defines.h b/src/qcomm-hidl/inc/ant_hci_defines.h
deleted file mode 100644
index 3ffe672..0000000
--- a/src/qcomm-hidl/inc/ant_hci_defines.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2013 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*******************************************************************************\
-*
-* FILE NAME: ant_hci_defines.h
-*
-* BRIEF:
-* This file defines ANT specific HCI values used by the ANT chip that are
-* not specific to the underlying chip. These should not need to be modified,
-* but should be verified they are correct.
-*
-\*******************************************************************************/
-
-#ifndef __VFS_INDEPENDENT_H
-#define __VFS_INDEPENDENT_H
-
-// ANT HCI Packet Structure
-// -----------------------------------------
-// | Header | Data | Footer |
-// |----------------------|-----------------|
-// |Optional| Data | Opt. | ... | Optional |
-// | Opcode | Size | Sync | | Checksum |
-// Data may include any number of ANT packets, with no sync byte or checksum.
-// A read from the driver may return any number of ANT HCI packets.
-
-#include "ant_driver_defines.h"
-
-#define ANT_HCI_HEADER_SIZE ((ANT_HCI_OPCODE_SIZE) + (ANT_HCI_SIZE_SIZE) + (ANT_HCI_SYNC_SIZE))
-#define ANT_HCI_FOOTER_SIZE (ANT_HCI_CHECKSUM_SIZE)
-
-#define ANT_HCI_OPCODE_OFFSET 0
-#define ANT_HCI_SIZE_OFFSET ((ANT_HCI_OPCODE_OFFSET) + (ANT_HCI_OPCODE_SIZE))
-#define ANT_HCI_SYNC_OFFSET ((ANT_HCI_SIZE_OFFSET) + (ANT_HCI_SIZE_SIZE))
-#define ANT_HCI_DATA_OFFSET (ANT_HCI_HEADER_SIZE)
-
-#define ANT_FLOW_GO_WAIT_TIMEOUT_SEC 10
-
-#endif /* ifndef __VFS_INDEPENDENT_H */
diff --git a/src/qcomm-hidl/inc/ant_rx_chardev.h b/src/qcomm-hidl/inc/ant_rx_chardev.h
deleted file mode 100644
index 12ba629..0000000
--- a/src/qcomm-hidl/inc/ant_rx_chardev.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2011 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*******************************************************************************\
-*
-* FILE NAME: ant_rx_chardev.h
-*
-* BRIEF:
-* This file defines the receive thread function, the ant_rx_thread_info_t
-* type for storing the -configuration- <state> of the receive thread, the
-* ant_channel_info_t type for storing a channel's (transport path)
-* configuration, and an enumeration of all ANT channels (transport paths).
-*
-*
-\*******************************************************************************/
-
-#ifndef __ANT_RX_NATIVE_H
-#define __ANT_RX_NATIVE_H
-
-#include "ant_native.h"
-#include "ant_hci_defines.h"
-
-/* same as HCI_MAX_EVENT_SIZE from hci.h, but hci.h is not included for vfs */
-#define ANT_HCI_MAX_MSG_SIZE 260
-
-#define ANT_MSG_SIZE_OFFSET ((ANT_U8)0)
-#define ANT_MSG_ID_OFFSET ((ANT_U8)1)
-#define ANT_MSG_DATA_OFFSET ((ANT_U8)2)
-
-/* This struct defines the info passed to an rx thread */
-typedef struct {
- /* Device path */
- const char *pcDevicePath;
- /* File descriptor to read from */
- int iFd;
- /* Callback to call with ANT packet */
- ANTNativeANTEventCb fnRxCallback;
- /* Flow control response if channel supports it */
- ANT_U8 ucFlowControlResp;
- /* Handle to flow control condition */
- pthread_cond_t *pstFlowControlCond;
- /* Handle to flow control mutex */
- pthread_mutex_t *pstFlowControlLock;
-#ifdef ANT_FLOW_RESEND
- /* Length of message to resend on request from chip */
- ANT_U8 ucResendMessageLength;
- /* The message to resend on request from chip */
- ANT_U8 *pucResendMessage;
-#endif // ANT_FLOW_RESEND
-} ant_channel_info_t;
-
-typedef enum {
-#ifdef ANT_DEVICE_NAME // Single transport path
- SINGLE_CHANNEL,
-#else // Separate data/command paths
- DATA_CHANNEL,
- COMMAND_CHANNEL,
-#endif // Separate data/command paths
- NUM_ANT_CHANNELS
-} ant_channel_type;
-
-typedef struct {
- /* Thread handle */
- pthread_t stRxThread;
- /* Exit condition */
- ANT_U8 ucRunThread;
- /* Set state as resetting override */
- ANT_U8 ucChipResetting;
- /* Handle to state change lock for crash cleanup */
- pthread_mutex_t *pstEnabledStatusLock;
- /* ANT channels */
- ant_channel_info_t astChannels[NUM_ANT_CHANNELS];
- /* Event file descriptor used to interrupt the poll() loop in the rx thread. */
- int iRxShutdownEventFd;
- /* Indicates whether thread is waiting for a keepalive response. */
- ANT_BOOL bWaitingForKeepaliveResponse;
-} ant_rx_thread_info_t;
-
-extern ANTNativeANTStateCb g_fnStateCallback; // TODO State callback should be inside ant_rx_thread_info_t.
-
-/* This is the rx thread function. It loops reading ANT packets until told to
- * exit */
-void *fnRxThread(void *ant_rx_thread_info);
-
-#endif /* ifndef __ANT_RX_NATIVE_H */
-
diff --git a/src/qcomm-hidl/inc/antradio_power.h b/src/qcomm-hidl/inc/antradio_power.h
deleted file mode 100644
index d0f8478..0000000
--- a/src/qcomm-hidl/inc/antradio_power.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __ANTRADIOPM_H
-#define __ANTRADIOPM_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Enable the ANT radio interface.
- *
- * Responsible for power on, and bringing up HCI interface.
- * Will block until the HCI interface is ready to use.
- *
- * Returns 0 on success, -ve on error */
-int ant_enable();
-
-/* Disable the ANT radio interface.
- *
- * Responsbile for pulling down the HCI interface, and powering down the chip.
- * Will block until power down is complete, and it is safe to immediately call
- * enable().
- *
- * Returns 0 on success, -ve on error */
-int ant_disable();
-
-/* Returns 1 if enabled, 0 if disabled, and -ve on error */
-int ant_is_enabled();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/qcomm-hidl/qualcomm/hidl/ant_driver_defines.h b/src/qcomm-hidl/qualcomm/hidl/ant_driver_defines.h
deleted file mode 100644
index 0f4ed7a..0000000
--- a/src/qcomm-hidl/qualcomm/hidl/ant_driver_defines.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2011 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*******************************************************************************\
-*
-* FILE NAME: ant_driver_defines.h
-*
-* BRIEF:
-* This file defines ANT specific HCI values used by the ANT chip for a
-* Qualcomm UART implementation.
-*
-*
-\*******************************************************************************/
-
-#ifndef __VFS_PRERELEASE_H
-#define __VFS_PRERELEASE_H
-
-// Packets may be prefixed with an optional packet type byte when being sent to
-// the chip. Will not be present in messages received.
-
-// -----------------------------------------
-// | Header | Data | Footer |
-// |----------------------|-----------------|
-// |Optional| Data | Opt. | ... | Optional |
-// | Opcode | Size | Sync | | Checksum |
-
-// Data may include any number of ANT packets, with no sync byte or checksum.
-// A read from the driver may return any number of ANT HCI packets.
-
-
-// ---------------------- REQUIRED
-
-// Which chip is this library being built for:
-#define ANT_CHIP_NAME "Qualcomm HIDL"
-
-// Set the file name the driver creates for the ANT device:
-// If chip uses separate command and data paths:
-// #define ANT_COMMANDS_DEVICE_NAME "/dev/X"
-// #define ANT_DATA_DEVICE_NAME "/dev/Y"
-// OR
-// If chip uses one path:
-
-#define ANT_DEVICE_NAME "/dev/ttyHS0"
-
-// Optional Packet prefix byte.
-#define HCI_PACKET_TYPE_SIZE 1
-
-// Set to the number of bytes of header is for Opcode:
-#define ANT_HCI_OPCODE_SIZE 0
-
-// Set to the number of bytes of header is for Data Size:
-#define ANT_HCI_SIZE_SIZE 1
-
-// Set to the number of bytes of header is for Sync:
-#define ANT_HCI_SYNC_SIZE 0
-
-// Set to the number of bytes of footer is for Checksum:
-#define ANT_HCI_CHECKSUM_SIZE 0
-
-// ---------------------- OPTIONAL
-
-// If hard reset is supported, define ANT_IOCTL_RESET
-// #define ANT_IOCTL_RESET _IOW('U', 210, int)
-// #define ANT_IOCTL_RESET_PARAMETER (0)
-
-// If the chip sends flow control messages:
-// Define the Opcode for a Flow Control message:
-#define ANT_MESG_FLOW_CONTROL ((ANT_U8)0xC9)
-// AND
-// define the message content:
-// That signals Flow Go:
-#define ANT_FLOW_GO ((ANT_U8)0x00)
-
-// That signals Flow Stop:
-#define ANT_FLOW_STOP ((ANT_U8)0x80)
-
-// Define protocol byte to be added
-// as multiple data will be sent/received over
-// same transport(BT, ANT ..etc)
-// needed for HCI_PACKET_TYPE_SIZE > 1.
-#define ANT_CMD_TYPE_PACKET ((ANT_U8)0x0C)
-#define ANT_DATA_TYPE_PACKET ((ANT_U8)0x0E)
-
-
-typedef enum {
- ANT_RADIO_UNKNOWN,
- ANT_RADIO_ENABLING,
- ANT_RADIO_ENABLED,
- ANT_RADIO_DISABLING,
- ANT_RADIO_DISABLED
-} ant_power_state_t;
-
-
-
-#endif /* ifndef __VFS_PRERELEASE_H */
diff --git a/src/vfs/Android.mk b/src/vfs/Android.mk
deleted file mode 100644
index 3d0af04..0000000
--- a/src/vfs/Android.mk
+++ /dev/null
@@ -1,59 +0,0 @@
-#
-# Copyright (C) 2011 Dynastream Innovations
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-include $(CLEAR_VARS)
-
-LOCAL_CFLAGS := -g -c -W -Wall -O2
-
-LOCAL_C_INCLUDES := \
- $(LOCAL_PATH)/src/common/inc \
- $(LOCAL_PATH)/$(ANT_DIR)/inc \
-
-ifeq ($(BOARD_ANT_WIRELESS_DEVICE),"cg29xx")
-LOCAL_C_INCLUDES += \
- $(LOCAL_PATH)/$(ANT_DIR)/ste/cg29xx \
-
-else ifeq ($(BOARD_ANT_WIRELESS_DEVICE),"qualcomm-smd")
-LOCAL_C_INCLUDES += \
- $(LOCAL_PATH)/$(ANT_DIR)/qualcomm/smd \
-
-else ifeq ($(BOARD_ANT_WIRELESS_DEVICE),"vfs-prerelease")
-LOCAL_C_INCLUDES += \
- $(LOCAL_PATH)/$(ANT_DIR)/prerelease \
-
-endif # BOARD_ANT_WIRELESS_DEVICE = "vfs-prerelease"
-
-LOCAL_SRC_FILES := \
- $(COMMON_DIR)/JAntNative.cpp \
- $(COMMON_DIR)/ant_utils.c \
- $(ANT_DIR)/ant_native_chardev.c \
- $(ANT_DIR)/ant_rx_chardev.c \
-
-# JNI
-LOCAL_C_INCLUDE += $(JNI_H_INCLUDE)
-
-LOCAL_SHARED_LIBRARIES += \
- libnativehelper \
-
-# logging
-LOCAL_SHARED_LIBRARIES += \
- libcutils \
-
-LOCAL_MODULE_TAGS := optional
-LOCAL_PRELINK_MODULE := false
-LOCAL_MODULE := libantradio
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/src/vfs/ant_native_chardev.c b/src/vfs/ant_native_chardev.c
deleted file mode 100644
index 1ab8f29..0000000
--- a/src/vfs/ant_native_chardev.c
+++ /dev/null
@@ -1,1001 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2011 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/******************************************************************************\
-*
-* FILE NAME: ant_native_chardev.c
-*
-* BRIEF:
-* This file provides the VFS implementation of ant_native.h
-* VFS could be Character Device, TTY, etc.
-*
-*
-\******************************************************************************/
-
-#include <errno.h>
-#include <fcntl.h> /* for open() */
-#include <linux/ioctl.h> /* For hard reset */
-#include <pthread.h>
-#include <stdint.h> /* for uint64_t */
-#include <sys/eventfd.h> /* For eventfd() */
-#include <unistd.h> /* for read(), write(), and close() */
-#include <string.h>
-
-#include "ant_types.h"
-#include "ant_native.h"
-#include "ant_version.h"
-
-#include "antradio_power.h"
-#include "ant_rx_chardev.h"
-#include "ant_hci_defines.h"
-#include "ant_log.h"
-
-#if (ANT_HCI_CHANNEL_SIZE > 0) || !defined(ANT_DEVICE_NAME)
-#define MULTIPATH_TX
-#endif
-
-#if ANT_HCI_SIZE_SIZE > 1
-#include "ant_utils.h" // Put HCI Size value across multiple bytes
-#endif
-
-#define MESG_BROADCAST_DATA_ID ((ANT_U8)0x4E)
-#define MESG_ACKNOWLEDGED_DATA_ID ((ANT_U8)0x4F)
-#define MESG_BURST_DATA_ID ((ANT_U8)0x50)
-#define MESG_EXT_BROADCAST_DATA_ID ((ANT_U8)0x5D)
-#define MESG_EXT_ACKNOWLEDGED_DATA_ID ((ANT_U8)0x5E)
-#define MESG_EXT_BURST_DATA_ID ((ANT_U8)0x5F)
-#define MESG_ADV_BURST_DATA_ID ((ANT_U8)0x72)
-
-static ant_rx_thread_info_t stRxThreadInfo;
-static pthread_mutex_t stEnabledStatusLock = PTHREAD_MUTEX_INITIALIZER;
-static pthread_mutex_t stFlowControlLock = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t stFlowControlCond = PTHREAD_COND_INITIALIZER;
-ANTNativeANTStateCb g_fnStateCallback;
-
-static const uint64_t EVENT_FD_PLUS_ONE = 1L;
-
-static void ant_channel_init(ant_channel_info_t *pstChnlInfo, const char *pcCharDevName);
-
-////////////////////////////////////////////////////////////////////
-// ant_init
-//
-// Initialises the native environment.
-//
-// Parameters:
-// -
-//
-// Returns:
-// ANT_STATUS_SUCCESS if intialize completed, else ANT_STATUS_FAILED
-//
-// Psuedocode:
-/*
-Set variables to defaults
-Initialise each supported path to chip
-Setup eventfd object.
-RESULT = ANT_STATUS_SUCCESS if no problems else ANT_STATUS_FAILED
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_init(void)
-{
- ANTStatus status = ANT_STATUS_FAILED;
- ANT_FUNC_START();
-
- stRxThreadInfo.stRxThread = 0;
- stRxThreadInfo.ucRunThread = 0;
- stRxThreadInfo.ucChipResetting = 0;
- stRxThreadInfo.pstEnabledStatusLock = &stEnabledStatusLock;
- g_fnStateCallback = 0;
-
-#ifdef ANT_DEVICE_NAME // Single transport path
- ant_channel_init(&stRxThreadInfo.astChannels[SINGLE_CHANNEL], ANT_DEVICE_NAME);
-#else // Separate data/command paths
- ant_channel_init(&stRxThreadInfo.astChannels[COMMAND_CHANNEL], ANT_COMMANDS_DEVICE_NAME);
- ant_channel_init(&stRxThreadInfo.astChannels[DATA_CHANNEL], ANT_DATA_DEVICE_NAME);
-#endif // Separate data/command paths
-
- // Make the eventfd. Want it non blocking so that we can easily reset it by reading.
- stRxThreadInfo.iRxShutdownEventFd = eventfd(0, EFD_NONBLOCK);
-
- // Check for error case
- if(stRxThreadInfo.iRxShutdownEventFd == -1)
- {
- ANT_ERROR("ANT init failed. Could not create event fd. Reason: %s", strerror(errno));
- } else {
- status = ANT_STATUS_SUCCESS;
- }
-
- ANT_FUNC_END();
- return status;
-}
-
-////////////////////////////////////////////////////////////////////
-// ant_deinit
-//
-// clean up eventfd object
-//
-// Parameters:
-// -
-//
-// Returns:
-// ANT_STATUS_SUCCESS
-//
-// Psuedocode:
-/*
-RESULT = SUCCESS
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_deinit(void)
-{
- ANTStatus result_status = ANT_STATUS_FAILED;
- ANT_FUNC_START();
-
- if(close(stRxThreadInfo.iRxShutdownEventFd) < 0)
- {
- ANT_ERROR("Could not close eventfd in deinit. Reason: %s", strerror(errno));
- } else {
- result_status = ANT_STATUS_SUCCESS;
- }
-
- ANT_FUNC_END();
- return result_status;
-}
-
-
-////////////////////////////////////////////////////////////////////
-// ant_enable_radio
-//
-// Powers on the ANT part and initialises the transport to the chip.
-// Changes occur in part implementing ant_enable() call
-//
-// Parameters:
-// -
-//
-// Returns:
-// Success:
-// ANT_STATUS_SUCCESS
-// Failures:
-// ANT_STATUS_TRANSPORT_INIT_ERR if could not enable
-// ANT_STATUS_FAILED if failed to get mutex or init rx thread
-//
-// Psuedocode:
-/*
-LOCK enable_LOCK
- IF current_state != ENABLED
- State callback: STATE = ENABLING
- ant enable
- IF ant_enable success
- State callback: STATE = ENABLED
- RESULT = SUCCESS
- ELSE
- ant disable
- State callback: STATE = Current state
- RESULT = FAILURE
- ENDIF
- ELSE
- RESULT = SUCCESS
- ENDIF
-UNLOCK
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_enable_radio(void)
-{
- int iLockResult;
- ANTStatus result_status = ANT_STATUS_FAILED;
- ANT_FUNC_START();
-
- ANT_DEBUG_V("getting stEnabledStatusLock in %s", __FUNCTION__);
- iLockResult = pthread_mutex_lock(&stEnabledStatusLock);
- if(iLockResult) {
- ANT_ERROR("enable failed to get state lock: %s", strerror(iLockResult));
- goto out;
- }
- ANT_DEBUG_V("got stEnabledStatusLock in %s", __FUNCTION__);
-
- if (ant_radio_enabled_status() != RADIO_STATUS_ENABLED) {
- if (g_fnStateCallback) {
- g_fnStateCallback(RADIO_STATUS_ENABLING);
- }
-
- if (ant_enable() < 0) {
- ANT_ERROR("ant enable failed: %s", strerror(errno));
-
- ant_disable();
-
- if (g_fnStateCallback) {
- g_fnStateCallback(ant_radio_enabled_status());
- }
- } else {
- if (g_fnStateCallback) {
- g_fnStateCallback(RADIO_STATUS_ENABLED);
- }
-
- result_status = ANT_STATUS_SUCCESS;
- }
- } else {
- ANT_DEBUG_D("Ignoring redundant enable call.");
- result_status = ANT_STATUS_SUCCESS;
- }
-
- ANT_DEBUG_V("releasing stEnabledStatusLock in %s", __FUNCTION__);
- pthread_mutex_unlock(&stEnabledStatusLock);
- ANT_DEBUG_V("released stEnabledStatusLock in %s", __FUNCTION__);
-
-out:
- ANT_FUNC_END();
- return result_status;
-}
-
-////////////////////////////////////////////////////////////////////
-// ant_radio_hard_reset
-//
-// IF SUPPORTED triggers a hard reset of the chip providing ANT functionality.
-//
-// Parameters:
-// -
-//
-// Returns:
-// Success:
-// ANT_STATUS_SUCCESS
-// Failures:
-// ANT_STATUS_NOT_SUPPORTED if the chip can't hard reset
-// ANT_STATUS_FAILED if failed to get mutex or enable
-//
-// Psuedocode:
-/*
-IF Hard Reset not supported
- RESULT = NOT SUPPORTED
-ELSE
- LOCK enable_LOCK
- IF Lock failed
- RESULT = FAILED
- ELSE
- Set Flag Rx thread that chip is resetting
- FOR each path to chip
- Send Reset IOCTL to path
- ENDFOR
- ant disable
- ant enable
- IF ant_enable success
- State callback: STATE = RESET
- RESULT = SUCCESS
- ELSE
- State callback: STATE = DISABLED
- RESULT = FAILURE
- ENDIF
- Clear Flag Rx thread that chip is resetting
- UNLOCK
-ENDIF
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_radio_hard_reset(void)
-{
- ANTStatus result_status = ANT_STATUS_NOT_SUPPORTED;
- ANT_FUNC_START();
-
-#ifdef ANT_IOCTL_RESET
- ant_channel_type eChannel;
- int iLockResult;
-
- result_status = ANT_STATUS_FAILED;
-
- ANT_DEBUG_V("getting stEnabledStatusLock in %s", __FUNCTION__);
- iLockResult = pthread_mutex_lock(&stEnabledStatusLock);
- if(iLockResult) {
- ANT_ERROR("enable failed to get state lock: %s", strerror(iLockResult));
- goto out;
- }
- ANT_DEBUG_V("got stEnabledStatusLock in %s", __FUNCTION__);
-
- stRxThreadInfo.ucChipResetting = 1;
- if (g_fnStateCallback)
- g_fnStateCallback(RADIO_STATUS_RESETTING);
-
-#ifdef ANT_IOCTL_RESET_PARAMETER
- ioctl(stRxThreadInfo.astChannels[0].iFd, ANT_IOCTL_RESET, ANT_IOCTL_RESET_PARAMETER);
-#else
- ioctl(stRxThreadInfo.astChannels[0].iFd, ANT_IOCTL_RESET);
-#endif // ANT_IOCTL_RESET_PARAMETER
-
- ant_disable();
-
- if (ant_enable()) { /* failed */
- if (g_fnStateCallback)
- g_fnStateCallback(RADIO_STATUS_DISABLED);
- } else { /* success */
- if (g_fnStateCallback)
- g_fnStateCallback(RADIO_STATUS_RESET);
- result_status = ANT_STATUS_SUCCESS;
- }
- stRxThreadInfo.ucChipResetting = 0;
-
- ANT_DEBUG_V("releasing stEnabledStatusLock in %s", __FUNCTION__);
- pthread_mutex_unlock(&stEnabledStatusLock);
- ANT_DEBUG_V("released stEnabledStatusLock in %s", __FUNCTION__);
-out:
-#endif // ANT_IOCTL_RESET
-
- ANT_FUNC_END();
- return result_status;
-}
-
-////////////////////////////////////////////////////////////////////
-// ant_disable_radio
-//
-// Powers off the ANT part and closes the transport to the chip.
-//
-// Parameters:
-// -
-//
-// Returns:
-// Success:
-// ANT_STATUS_SUCCESS
-// Failures:
-// ANT_STATUS_FAILED if failed to get mutex
-//
-// Psuedocode:
-/*
-LOCK enable_LOCK
- IF current_state != DISABLED
- State callback: STATE = DISABLING
- ant disable
- State callback: STATE = Current state
- ENDIF
- RESULT = SUCCESS
-UNLOCK
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_disable_radio(void)
-{
- int iLockResult;
- ANTStatus ret = ANT_STATUS_FAILED;
- ANT_FUNC_START();
-
- ANT_DEBUG_V("getting stEnabledStatusLock in %s", __FUNCTION__);
- iLockResult = pthread_mutex_lock(&stEnabledStatusLock);
- if(iLockResult) {
- ANT_ERROR("disable failed to get state lock: %s", strerror(iLockResult));
- goto out;
- }
- ANT_DEBUG_V("got stEnabledStatusLock in %s", __FUNCTION__);
-
- if (ant_radio_enabled_status() != RADIO_STATUS_DISABLED) {
- if (g_fnStateCallback) {
- g_fnStateCallback(RADIO_STATUS_DISABLING);
- }
-
- ant_disable();
-
- if (g_fnStateCallback) {
- g_fnStateCallback(ant_radio_enabled_status());
- }
- } else {
- ANT_DEBUG_D("Ignoring redundant disable call.");
- }
-
- ret = ANT_STATUS_SUCCESS;
-
- ANT_DEBUG_V("releasing stEnabledStatusLock in %s", __FUNCTION__);
- pthread_mutex_unlock(&stEnabledStatusLock);
- ANT_DEBUG_V("released stEnabledStatusLock in %s", __FUNCTION__);
-
-out:
- ANT_FUNC_END();
- return ret;
-}
-
-////////////////////////////////////////////////////////////////////
-// ant_radio_enabled_status
-//
-// Gets the current chip/transport state; either disabled, disabling,
-// enabling, enabled, or resetting. Determines this on the fly by checking
-// if Rx thread is running and how many of the paths for the ANT chip have
-// open VFS files.
-//
-// Parameters:
-// -
-//
-// Returns:
-// The current radio status (ANTRadioEnabledStatus)
-//
-// Psuedocode:
-/*
-IF Thread Resetting Flag is set
- RESULT = Resetting
-ELSE
- COUNT the number of open files
- IF Thread Run Flag is Not Set
- IF there are open files OR Rx thread exists
- RESULT = Disabling
- ELSE
- RESULT = Disabled
- ENDIF
- ELSE
- IF All files are open (all paths) AND Rx thread exists
- RESULT = ENABLED
- ELSE IF there are open files (Not 0 open files) AND Rx thread exists
- RESULT = UNKNOWN
- ELSE (0 open files or Rx thread does not exist [while Thread Run set])
- RESULT = ENABLING
- ENDIF
- ENDIF
-ENDIF
-*/
-////////////////////////////////////////////////////////////////////
-ANTRadioEnabledStatus ant_radio_enabled_status(void)
-{
- ant_channel_type eChannel;
- int iOpenFiles = 0;
- int iOpenThread;
- ANTRadioEnabledStatus uiRet = RADIO_STATUS_UNKNOWN;
- ANT_FUNC_START();
-
- if (stRxThreadInfo.ucChipResetting) {
- uiRet = RADIO_STATUS_RESETTING;
- goto out;
- }
-
- for (eChannel = 0; eChannel < NUM_ANT_CHANNELS; eChannel++) {
- if (stRxThreadInfo.astChannels[eChannel].iFd != -1) {
- iOpenFiles++;
- }
- }
-
- iOpenThread = (stRxThreadInfo.stRxThread) ? 1 : 0;
-
- if (!stRxThreadInfo.ucRunThread) {
- if (iOpenFiles || iOpenThread) {
- uiRet = RADIO_STATUS_DISABLING;
- } else {
- uiRet = RADIO_STATUS_DISABLED;
- }
- } else {
- if ((iOpenFiles == NUM_ANT_CHANNELS) && iOpenThread) {
- uiRet = RADIO_STATUS_ENABLED;
- } else if (!iOpenFiles && iOpenThread) {
- uiRet = RADIO_STATUS_UNKNOWN;
- } else {
- uiRet = RADIO_STATUS_ENABLING;
- }
- }
-
-out:
- ANT_DEBUG_D("get radio enabled status returned %d", uiRet);
-
- ANT_FUNC_END();
- return uiRet;
-}
-
-////////////////////////////////////////////////////////////////////
-// set_ant_rx_callback
-//
-// Sets which function to call when an ANT message is received.
-//
-// Parameters:
-// rx_callback_func the ANTNativeANTEventCb function to be used for
-// received messages (from all transport paths).
-//
-// Returns:
-// ANT_STATUS_SUCCESS
-//
-// Psuedocode:
-/*
-FOR each transport path
- Path Rx Callback = rx_callback_func
-ENDFOR
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus set_ant_rx_callback(ANTNativeANTEventCb rx_callback_func)
-{
- ANTStatus status = ANT_STATUS_SUCCESS;
- ANT_FUNC_START();
-
-#ifdef ANT_DEVICE_NAME // Single transport path
- stRxThreadInfo.astChannels[SINGLE_CHANNEL].fnRxCallback = rx_callback_func;
-#else // Separate data/command paths
- stRxThreadInfo.astChannels[COMMAND_CHANNEL].fnRxCallback = rx_callback_func;
- stRxThreadInfo.astChannels[DATA_CHANNEL].fnRxCallback = rx_callback_func;
-#endif // Separate data/command paths
-
- ANT_FUNC_END();
- return status;
-}
-
-////////////////////////////////////////////////////////////////////
-// set_ant_state_callback
-//
-// Sets which function to call when an ANT state change occurs.
-//
-// Parameters:
-// state_callback_func the ANTNativeANTStateCb function to be used
-// for received state changes.
-//
-// Returns:
-// ANT_STATUS_SUCCESS
-//
-// Psuedocode:
-/*
- State Callback = state_callback_func
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus set_ant_state_callback(ANTNativeANTStateCb state_callback_func)
-{
- ANTStatus status = ANT_STATUS_SUCCESS;
- ANT_FUNC_START();
-
- g_fnStateCallback = state_callback_func;
-
- ANT_FUNC_END();
- return status;
-}
-
-////////////////////////////////////////////////////////////////////
-// ant_tx_message_flowcontrol_wait
-//
-// Sends an ANT message to the chip and waits for a CTS signal
-//
-// Parameters:
-// eTxPath device to transmit message on
-// eFlowMessagePath device that receives CTS
-// ucMessageLength the length of the message
-// pucMesg pointer to the message data
-//
-// Returns:
-// Success:
-// ANT_STATUS_SUCCESS
-// Failure:
-// ANT_STATUS_NOT_ENABLED
-//
-// Psuedocode:
-/*
- LOCK flow control
- IF Lock failed
- RESULT = FAILED
- ELSE
- SET flowMessagePath Flow Control response as FLOW_STOP
- WRITE txBuffer to txPath (only length of packet part)
- IF Wrote less then 0 bytes
- Log error
- RESULT = FAILED
- ELSE IF Didn't write 'length of packet' bytes
- Log error
- RESULT = FAILED
- ELSE
- IF flowMessagePath Flow Control response is not FLOW_GO
- WAIT until flowMessagePath Flow Control response is FLOW_GO, UNTIL FLOW_GO Wait Timeout seconds (10) from Now
- IF error Waiting
- IF error is Timeout
- RESULT = HARDWARE ERROR
- ELSE
- RESULT = FAILED
- ENDIF
- ELSE
- RESULT = SUCCESS
- ENDIF
- ELSE
- RESULT = SUCCESS;
- ENDIF
- ENDIF
- UNLOCK flow control
- ENDIF
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_tx_message_flowcontrol_wait(ant_channel_type eTxPath, ant_channel_type eFlowMessagePath, ANT_U8 ucMessageLength, ANT_U8 *pucTxMessage)
-{
- int iMutexResult;
- int iResult;
- struct timespec stTimeout;
- int iCondWaitResult;
- ANTStatus status = ANT_STATUS_FAILED;
- ANT_FUNC_START();
-
- ANT_DEBUG_V("getting stFlowControlLock in %s", __FUNCTION__);
- iMutexResult = pthread_mutex_lock(&stFlowControlLock);
- if (iMutexResult) {
- ANT_ERROR("failed to lock flow control mutex during tx: %s", strerror(iMutexResult));
- goto out;
- }
- ANT_DEBUG_V("got stFlowControlLock in %s", __FUNCTION__);
-
- stRxThreadInfo.astChannels[eFlowMessagePath].ucFlowControlResp = ANT_FLOW_STOP;
-
-#ifdef ANT_FLOW_RESEND
- // Store Tx message so can resend it from Rx thread
- stRxThreadInfo.astChannels[eFlowMessagePath].ucResendMessageLength = ucMessageLength;
- stRxThreadInfo.astChannels[eFlowMessagePath].pucResendMessage = pucTxMessage;
-#endif // ANT_FLOW_RESEND
-
- iResult = write(stRxThreadInfo.astChannels[eTxPath].iFd, pucTxMessage, ucMessageLength);
- if (iResult < 0) {
- ANT_ERROR("failed to write data message to device: %s", strerror(errno));
- } else if (iResult != ucMessageLength) {
- ANT_ERROR("bytes written and message size don't match up");
- } else {
- stTimeout.tv_sec = time(0) + ANT_FLOW_GO_WAIT_TIMEOUT_SEC;
- stTimeout.tv_nsec = 0;
-
- while (stRxThreadInfo.astChannels[eFlowMessagePath].ucFlowControlResp != ANT_FLOW_GO) {
- iCondWaitResult = pthread_cond_timedwait(&stFlowControlCond, &stFlowControlLock, &stTimeout);
- if (iCondWaitResult) {
- ANT_ERROR("failed to wait for flow control response: %s", strerror(iCondWaitResult));
-
- if (iCondWaitResult == ETIMEDOUT) {
- status = ANT_STATUS_HARDWARE_ERR;
-
-#ifdef ANT_FLOW_RESEND
- // Clear Tx message so will stop resending it from Rx thread
- stRxThreadInfo.astChannels[eFlowMessagePath].ucResendMessageLength = 0;
- stRxThreadInfo.astChannels[eFlowMessagePath].pucResendMessage = NULL;
-#endif // ANT_FLOW_RESEND
- }
- goto wait_error;
- }
- }
-
- status = ANT_STATUS_SUCCESS;
- }
-
-wait_error:
- ANT_DEBUG_V("releasing stFlowControlLock in %s", __FUNCTION__);
- pthread_mutex_unlock(&stFlowControlLock);
- ANT_DEBUG_V("released stFlowControlLock in %s", __FUNCTION__);
-
-out:
- ANT_FUNC_END();
- return status;
-}
-
-////////////////////////////////////////////////////////////////////
-// ant_tx_message_flowcontrol_none
-//
-// Sends an ANT message to the chip without waiting for flow control
-//
-// Parameters:
-// eTxPath device to transmit on
-// ucMessageLength the length of the message
-// pucMesg pointer to the message data
-//
-// Returns:
-// Success:
-// ANT_STATUS_SUCCESS
-// Failure:
-// ANT_STATUS_NOT_ENABLED
-//
-// Psuedocode:
-/*
- WRITE txBuffer to Tx Path (only length of packet part)
- IF Wrote less then 0 bytes
- Log error
- RESULT = FAILED
- ELSE IF Didn't write 'length of packet' bytes
- Log error
- RESULT = FAILED
- ELSE
- RESULT = SUCCESS
- ENDIF
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_tx_message_flowcontrol_none(ant_channel_type eTxPath, ANT_U8 ucMessageLength, ANT_U8 *pucTxMessage)
-{
- int iResult;
- ANTStatus status = ANT_STATUS_FAILED;\
- ANT_FUNC_START();
-
- iResult = write(stRxThreadInfo.astChannels[eTxPath].iFd, pucTxMessage, ucMessageLength);
- if (iResult < 0) {
- ANT_ERROR("failed to write message to device: %s", strerror(errno));
- } else if (iResult != ucMessageLength) {
- ANT_ERROR("bytes written and message size don't match up");
- } else {
- status = ANT_STATUS_SUCCESS;
- }
-
- ANT_FUNC_END();
- return status;
-}
-
-////////////////////////////////////////////////////////////////////
-// ant_tx_message
-//
-// Frames ANT data and decides which flow control method to use for sending the
-// ANT message to the chip
-//
-// Parameters:
-// ucLen the length of the message
-// pucMesg pointer to the message data
-//
-// Returns:
-// Success:
-// ANT_STATUS_SUCCESS
-// Failure:
-// ANT_STATUS_NOT_ENABLED
-//
-// Psuedocode:
-/*
-IF not enabled
- RESULT = BT NOT INITIALIZED
-ELSE
- Create txBuffer, MAX HCI Message Size large
- PUT ucLen in txBuffer AT ANT HCI Size Offset (0)
- COPY pucMesg to txBuffer AT ANT HCI Header Size (1) <- ? Not at offset?
- LOG txBuffer as a serial Tx (only length of packet part)
- IF is a data message
- Tx message on Data Path with FLOW_GO/FLOW_STOP flow control (ant_tx_message_flowcontrol_go_stop())
- ELSE
- Tx message on Command Path with no flow control (ant_tx_message_flowcontrol_none())
- ENDIF
-ENDIF
-*/
-////////////////////////////////////////////////////////////////////
-ANTStatus ant_tx_message(ANT_U8 ucLen, ANT_U8 *pucMesg)
-{
-#if defined(MULTIPATH_TX)
- ANT_BOOL bIsData;
-#endif
- ant_channel_type eTxChannel;
- ant_channel_type eFlowChannel;
- ANTStatus status = ANT_STATUS_FAILED;
- // TODO ANT_HCI_MAX_MSG_SIZE is transport (driver) dependent.
- ANT_U8 txBuffer[ANT_HCI_MAX_MSG_SIZE];
- // TODO Message length can be greater than ANT_U8 can hold.
- // Not changed as ANT_SERIAL takes length as ANT_U8.
- ANT_U8 txMessageLength = ucLen + ANT_HCI_HEADER_SIZE;
- ANT_FUNC_START();
-
- if (ant_radio_enabled_status() != RADIO_STATUS_ENABLED) {
- status = ANT_STATUS_FAILED_BT_NOT_INITIALIZED;
- goto out;
- }
-
-#if defined(MULTIPATH_TX)
-switch (pucMesg[ANT_MSG_ID_OFFSET]) {
- case MESG_BROADCAST_DATA_ID:
- case MESG_ACKNOWLEDGED_DATA_ID:
- case MESG_BURST_DATA_ID:
- case MESG_EXT_BROADCAST_DATA_ID:
- case MESG_EXT_ACKNOWLEDGED_DATA_ID:
- case MESG_EXT_BURST_DATA_ID:
- case MESG_ADV_BURST_DATA_ID:
- bIsData = ANT_TRUE;
- break;
- default:
- bIsData = ANT_FALSE;
- break;
- }
-
- ANT_DEBUG_V("tx message: bIsData=%d", bIsData);
-#endif
-
-#if ANT_HCI_OPCODE_SIZE == 1
- txBuffer[ANT_HCI_OPCODE_OFFSET] = ANT_HCI_OPCODE_TX;
-#elif ANT_HCI_OPCODE_SIZE > 1
-#error "Specified ANT_HCI_OPCODE_SIZE not currently supported"
-#endif
-
-#if ANT_HCI_CHANNEL_SIZE == 1
- txBuffer[ANT_HCI_CHANNEL_OFFSET] = bIsData ? ANT_HCI_DATA_CHANNEL : ANT_HCI_COMMAND_CHANNEL;
-#elif ANT_HCI_OPCODE_SIZE > 1
-#error "Specified ANT_HCI_CHANNEL_SIZE not currently supported"
-#endif
-
-#if ANT_HCI_SIZE_SIZE == 1
- txBuffer[ANT_HCI_SIZE_OFFSET] = ucLen;
-#elif ANT_HCI_SIZE_SIZE == 2
- ANT_UTILS_StoreLE16(txBuffer + ANT_HCI_SIZE_OFFSET, (ANT_U16)ucLen);
-#else
-#error "Specified ANT_HCI_SIZE_SIZE not currently supported"
-#endif
-
- memcpy(txBuffer + ANT_HCI_HEADER_SIZE, pucMesg, ucLen);
-
- ANT_SERIAL(txBuffer, txMessageLength, 'T');
-
-#ifdef ANT_DEVICE_NAME
- eTxChannel = SINGLE_CHANNEL;
- eFlowChannel = SINGLE_CHANNEL;
-#else
- eTxChannel = bIsData ? DATA_CHANNEL : COMMAND_CHANNEL;
- eFlowChannel = COMMAND_CHANNEL;
-#endif
-
-#if !defined(MULTIPATH_TX) // Single transport path
- status = ant_tx_message_flowcontrol_wait(eTxChannel, eFlowChannel, txMessageLength, txBuffer);
-#else // Separate data/command paths
- if (bIsData)
- {
- status = ant_tx_message_flowcontrol_wait(eTxChannel, eFlowChannel, txMessageLength, txBuffer);
- }
- else
- {
- status = ant_tx_message_flowcontrol_none(eTxChannel, txMessageLength, txBuffer);
- }
-#endif // Separate data/command paths
-
-out:
- ANT_FUNC_END();
- return status;
-}
-
-//----------------- TODO Move these somewhere for multi transport path / dedicated channel support:
-
-static void ant_channel_init(ant_channel_info_t *pstChnlInfo, const char *pcCharDevName)
-{
- ANT_FUNC_START();
-
- // TODO Don't need to store, only accessed when trying to open:
- // Is however useful for logs.
- pstChnlInfo->pcDevicePath = pcCharDevName;
-
- // This is the only piece of info that needs to be stored per channel
- pstChnlInfo->iFd = -1;
-
- // TODO Only 1 of these (not per-channel) is actually ever used:
- pstChnlInfo->fnRxCallback = NULL;
- pstChnlInfo->ucFlowControlResp = ANT_FLOW_GO;
-#ifdef ANT_FLOW_RESEND
- pstChnlInfo->ucResendMessageLength = 0;
- pstChnlInfo->pucResendMessage = NULL;
-#endif // ANT_FLOW_RESEND
- // TODO Only used when Flow Control message received, so must only be Command path Rx thread
- pstChnlInfo->pstFlowControlCond = &stFlowControlCond;
- pstChnlInfo->pstFlowControlLock = &stFlowControlLock;
-
- ANT_FUNC_END();
-}
-
-static void ant_disable_channel(ant_channel_info_t *pstChnlInfo)
-{
- ANT_FUNC_START();
-
- if (!pstChnlInfo) {
- ANT_ERROR("null channel info passed to channel disable function");
- goto out;
- }
-
- if (pstChnlInfo->iFd != -1) {
- if (close(pstChnlInfo->iFd) < 0) {
- ANT_ERROR("failed to close channel %s(%#x): %s", pstChnlInfo->pcDevicePath, pstChnlInfo->iFd, strerror(errno));
- }
-
- pstChnlInfo->iFd = -1; //TODO can this overwrite a still valid fd?
- } else {
- ANT_DEBUG_D("%s file is already closed", pstChnlInfo->pcDevicePath);
- }
-
-out:
- ANT_FUNC_END();
-}
-
-static int ant_enable_channel(ant_channel_info_t *pstChnlInfo)
-{
- int iRet = -1;
- ANT_FUNC_START();
- if (!pstChnlInfo) {
- ANT_ERROR("null channel info passed to channel enable function");
- errno = EINVAL;
- goto out;
- }
- if (pstChnlInfo->iFd == -1) {
- pstChnlInfo->iFd = open(pstChnlInfo->pcDevicePath, O_RDWR);
- if (pstChnlInfo->iFd < 0) {
- ANT_ERROR("failed to open dev %s: %s", pstChnlInfo->pcDevicePath, strerror(errno));
- goto out;
- }
- } else {
- ANT_DEBUG_D("%s is already enabled", pstChnlInfo->pcDevicePath);
- }
- iRet = 0;
-out:
- ANT_FUNC_END();
- return iRet;
-}
-
-//----------------------------------------------------------------------- This is antradio_power.h:
-
-int ant_enable(void)
-{
- int iRet = -1;
- ant_channel_type eChannel;
- ANT_FUNC_START();
-
- // Reset the shutdown signal.
- uint64_t counter;
- ssize_t result = read(stRxThreadInfo.iRxShutdownEventFd, &counter, sizeof(counter));
- // EAGAIN result indicates that the counter was already 0 in non-blocking mode.
- if(result < 0 && errno != EAGAIN)
- {
- ANT_ERROR("Could not clear shutdown signal in enable. Reason: %s", strerror(errno));
- goto out;
- }
-
- stRxThreadInfo.ucRunThread = 1;
-
- for (eChannel = 0; eChannel < NUM_ANT_CHANNELS; eChannel++) {
- if (ant_enable_channel(&stRxThreadInfo.astChannels[eChannel]) < 0) {
- ANT_ERROR("failed to enable channel %s: %s",
- stRxThreadInfo.astChannels[eChannel].pcDevicePath,
- strerror(errno));
- goto out;
- }
- }
-
- if (stRxThreadInfo.stRxThread == 0) {
- if (pthread_create(&stRxThreadInfo.stRxThread, NULL, fnRxThread, &stRxThreadInfo) < 0) {
- ANT_ERROR("failed to start rx thread: %s", strerror(errno));
- goto out;
- }
- } else {
- ANT_DEBUG_D("rx thread is already running");
- }
-
- if (!stRxThreadInfo.ucRunThread) {
- ANT_ERROR("rx thread crashed during init");
- goto out;
- }
-
- iRet = 0;
-
-out:
- if (stRxThreadInfo.stRxThread == 0) {
- stRxThreadInfo.ucRunThread = 0;
- }
- ANT_FUNC_END();
- return iRet;
-}
-
-int ant_disable(void)
-{
- int iRet = -1;
- ant_channel_type eChannel;
- ANT_FUNC_START();
-
- stRxThreadInfo.ucRunThread = 0;
-
- if (stRxThreadInfo.stRxThread != 0) {
- ANT_DEBUG_I("Sending shutdown signal to rx thread.");
- if(write(stRxThreadInfo.iRxShutdownEventFd, &EVENT_FD_PLUS_ONE, sizeof(EVENT_FD_PLUS_ONE)) < 0)
- {
- ANT_ERROR("failed to signal rx thread with eventfd. Reason: %s", strerror(errno));
- goto out;
- }
- ANT_DEBUG_I("Waiting for rx thread to finish.");
- if (pthread_join(stRxThreadInfo.stRxThread, NULL) < 0) {
- ANT_ERROR("failed to join rx thread: %s", strerror(errno));
- goto out;
- }
- } else {
- ANT_DEBUG_D("rx thread is not running");
- }
-
- for (eChannel = 0; eChannel < NUM_ANT_CHANNELS; eChannel++) {
- ant_disable_channel(&stRxThreadInfo.astChannels[eChannel]);
- }
-
- iRet = 0;
-
-out:
- stRxThreadInfo.stRxThread = 0;
- ANT_FUNC_END();
- return iRet;
-}
-
-//---------------------------------------------------------
-
-const char *ant_get_lib_version()
-{
- return "libantradio.so: "ANT_CHIP_NAME". Version "
- LIBANT_STACK_MAJOR"."LIBANT_STACK_MINOR"."LIBANT_STACK_INCRE;
-}
diff --git a/src/vfs/ant_rx_chardev.c b/src/vfs/ant_rx_chardev.c
deleted file mode 100644
index c1027d5..0000000
--- a/src/vfs/ant_rx_chardev.c
+++ /dev/null
@@ -1,467 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2011 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/******************************************************************************\
-*
-* FILE NAME: ant_rx_chardev.c
-*
-* BRIEF:
-* This file implements the receive thread function which will loop reading
-* ANT messages until told to exit.
-*
-*
-\******************************************************************************/
-
-#include <errno.h>
-#include <poll.h>
-#include <pthread.h>
-#include <stdint.h> /* for uint64_t */
-#include <string.h>
-
-#include "ant_types.h"
-#include "antradio_power.h"
-#include "ant_rx_chardev.h"
-#include "ant_hci_defines.h"
-#include "ant_log.h"
-#include "ant_native.h" // ANT_HCI_MAX_MSG_SIZE, ANT_MSG_ID_OFFSET, ANT_MSG_DATA_OFFSET,
- // ant_radio_enabled_status()
-
-extern ANTStatus ant_tx_message_flowcontrol_none(ant_channel_type eTxPath, ANT_U8 ucMessageLength, ANT_U8 *pucTxMessage);
-
-#undef LOG_TAG
-#define LOG_TAG "antradio_rx"
-
-#define ANT_POLL_TIMEOUT ((int)30000)
-#define KEEPALIVE_TIMEOUT ((int)5000)
-
-static ANT_U8 aucRxBuffer[NUM_ANT_CHANNELS][ANT_HCI_MAX_MSG_SIZE];
-
-#ifdef ANT_DEVICE_NAME // Single transport path
- static int iRxBufferLength[NUM_ANT_CHANNELS] = {0};
-#else
- static int iRxBufferLength[NUM_ANT_CHANNELS] = {0, 0};
-#endif //
-
-// Defines for use with the poll() call
-#define EVENT_DATA_AVAILABLE (POLLIN|POLLRDNORM)
-#define EVENT_CHIP_SHUTDOWN (POLLHUP)
-#define EVENT_HARD_RESET (POLLERR|POLLPRI|POLLRDHUP)
-
-#define EVENTS_TO_LISTEN_FOR (EVENT_DATA_AVAILABLE|EVENT_CHIP_SHUTDOWN|EVENT_HARD_RESET)
-
-// Plus one is for the eventfd shutdown signal.
-#define NUM_POLL_FDS (NUM_ANT_CHANNELS + 1)
-#define EVENTFD_IDX NUM_ANT_CHANNELS
-
-static ANT_U8 KEEPALIVE_MESG[] = {0x01, 0x00, 0x00};
-static ANT_U8 KEEPALIVE_RESP[] = {0x03, 0x40, 0x00, 0x00, 0x28};
-
-void doReset(ant_rx_thread_info_t *stRxThreadInfo);
-int readChannelMsg(ant_channel_type eChannel, ant_channel_info_t *pstChnlInfo);
-
-/*
- * Function to check that all given flags are set in a particular value.
- * Designed for use with the revents field of pollfds filled out by poll().
- *
- * Parameters:
- * - value: The value that will be checked to contain all flags.
- * - flags: Bitwise-or of the flags that value should be checked for.
- *
- * Returns:
- * - true IFF all the bits that are set in 'flags' are also set in 'value'
- */
-ANT_BOOL areAllFlagsSet(short value, short flags)
-{
- value &= flags;
- return (value == flags);
-}
-
-/*
- * This thread is run occasionally as a detached thread in order to send a keepalive message to the
- * chip.
- */
-void *fnKeepAliveThread(void *unused)
-{
- ANT_DEBUG_V("Sending dummy keepalive message.");
- ant_tx_message(sizeof(KEEPALIVE_MESG)/sizeof(ANT_U8), KEEPALIVE_MESG);
- return NULL;
-}
-
-/*
- * This thread waits for ANT messages from a VFS file.
- */
-void *fnRxThread(void *ant_rx_thread_info)
-{
- int iMutexLockResult;
- int iPollRet;
- ant_rx_thread_info_t *stRxThreadInfo;
- struct pollfd astPollFd[NUM_POLL_FDS];
- ant_channel_type eChannel;
- ANT_FUNC_START();
-
- stRxThreadInfo = (ant_rx_thread_info_t *)ant_rx_thread_info;
- for (eChannel = 0; eChannel < NUM_ANT_CHANNELS; eChannel++) {
- astPollFd[eChannel].fd = stRxThreadInfo->astChannels[eChannel].iFd;
- astPollFd[eChannel].events = EVENTS_TO_LISTEN_FOR;
- }
- // Fill out poll request for the shutdown signaller.
- astPollFd[EVENTFD_IDX].fd = stRxThreadInfo->iRxShutdownEventFd;
- astPollFd[EVENTFD_IDX].events = POLL_IN;
-
- // Reset the waiting for response, since we don't want a stale value if we were reset.
- stRxThreadInfo->bWaitingForKeepaliveResponse = ANT_FALSE;
-
- /* continue running as long as not terminated */
- while (stRxThreadInfo->ucRunThread) {
- /* Wait for data available on any file (transport path), shorter wait if we just timed out. */
- int timeout = stRxThreadInfo->bWaitingForKeepaliveResponse ? KEEPALIVE_TIMEOUT : ANT_POLL_TIMEOUT;
- iPollRet = poll(astPollFd, NUM_POLL_FDS, timeout);
- if (!iPollRet) {
- if(!stRxThreadInfo->bWaitingForKeepaliveResponse)
- {
- stRxThreadInfo->bWaitingForKeepaliveResponse = ANT_TRUE;
- // Keep alive is done on a separate thread so that rxThread can handle flow control during
- // the message.
- pthread_t thread;
- // Don't care if it failed as the consequence is just a missed keep-alive.
- pthread_create(&thread, NULL, fnKeepAliveThread, NULL);
- // Detach the thread so that we don't need to join it later.
- pthread_detach(thread);
- ANT_DEBUG_V("poll timed out, checking exit cond");
- } else
- {
- ANT_DEBUG_E("No response to keepalive, attempting recovery.");
- doReset(stRxThreadInfo);
- goto out;
- }
- } else if (iPollRet < 0) {
- ANT_ERROR("unhandled error: %s, attempting recovery.", strerror(errno));
- doReset(stRxThreadInfo);
- goto out;
- } else {
- for (eChannel = 0; eChannel < NUM_ANT_CHANNELS; eChannel++) {
- if (areAllFlagsSet(astPollFd[eChannel].revents, EVENT_HARD_RESET)) {
- ANT_ERROR("Hard reset indicated by %s. Attempting recovery.",
- stRxThreadInfo->astChannels[eChannel].pcDevicePath);
- doReset(stRxThreadInfo);
- goto out;
- } else if (areAllFlagsSet(astPollFd[eChannel].revents, EVENT_CHIP_SHUTDOWN)) {
- /* chip reported it was unexpectedly disabled */
- ANT_DEBUG_D(
- "poll hang-up from %s. Attempting recovery.",
- stRxThreadInfo->astChannels[eChannel].pcDevicePath);
-
- doReset(stRxThreadInfo);
- goto out;
- } else if (areAllFlagsSet(astPollFd[eChannel].revents, EVENT_DATA_AVAILABLE)) {
- ANT_DEBUG_D("data on %s. reading it",
- stRxThreadInfo->astChannels[eChannel].pcDevicePath);
-
- // Doesn't matter what data we received, we know the chip is alive.
- stRxThreadInfo->bWaitingForKeepaliveResponse = ANT_FALSE;
-
- if (readChannelMsg(eChannel, &stRxThreadInfo->astChannels[eChannel]) < 0) {
- ANT_ERROR("Read of data failed. Attempting recovery.");
- doReset(stRxThreadInfo);
- goto out;
- }
- } else if (areAllFlagsSet(astPollFd[eChannel].revents, POLLNVAL)) {
- ANT_ERROR("poll was called on invalid file descriptor %s. Attempting recovery.",
- stRxThreadInfo->astChannels[eChannel].pcDevicePath);
- doReset(stRxThreadInfo);
- goto out;
- } else if (areAllFlagsSet(astPollFd[eChannel].revents, POLLERR)) {
- ANT_ERROR("Unknown error from %s. Attempting recovery.",
- stRxThreadInfo->astChannels[eChannel].pcDevicePath);
- doReset(stRxThreadInfo);
- goto out;
- } else if (astPollFd[eChannel].revents) {
- ANT_DEBUG_W("unhandled poll result %#x from %s",
- astPollFd[eChannel].revents,
- stRxThreadInfo->astChannels[eChannel].pcDevicePath);
- }
- }
- // Now check for shutdown signal
- if(areAllFlagsSet(astPollFd[EVENTFD_IDX].revents, POLLIN))
- {
- ANT_DEBUG_I("rx thread caught shutdown signal.");
- // reset the counter by reading.
- uint64_t counter;
- read(stRxThreadInfo->iRxShutdownEventFd, &counter, sizeof(counter));
- // don't care if read error, going to close the thread anyways.
- stRxThreadInfo->ucRunThread = 0;
- } else if (astPollFd[EVENTFD_IDX].revents != 0) {
- ANT_ERROR("Shutdown event descriptor had unexpected event: %#x. exiting rx thread.",
- astPollFd[EVENTFD_IDX].revents);
- stRxThreadInfo->ucRunThread = 0;
- }
- }
- }
-
- /* disable ANT radio if not already disabling */
- // Try to get stEnabledStatusLock.
- // if you get it then no one is enabling or disabling
- // if you can't get it assume something made you exit
- ANT_DEBUG_V("try getting stEnabledStatusLock in %s", __FUNCTION__);
- iMutexLockResult = pthread_mutex_trylock(stRxThreadInfo->pstEnabledStatusLock);
- if (!iMutexLockResult) {
- ANT_DEBUG_V("got stEnabledStatusLock in %s", __FUNCTION__);
- ANT_WARN("rx thread has unexpectedly crashed, cleaning up");
-
- // spoof our handle as closed so we don't try to join ourselves in disable
- stRxThreadInfo->stRxThread = 0;
-
- if (g_fnStateCallback) {
- g_fnStateCallback(RADIO_STATUS_DISABLING);
- }
-
- ant_disable();
-
- if (g_fnStateCallback) {
- g_fnStateCallback(ant_radio_enabled_status());
- }
-
- ANT_DEBUG_V("releasing stEnabledStatusLock in %s", __FUNCTION__);
- pthread_mutex_unlock(stRxThreadInfo->pstEnabledStatusLock);
- ANT_DEBUG_V("released stEnabledStatusLock in %s", __FUNCTION__);
- } else if (iMutexLockResult != EBUSY) {
- ANT_ERROR("rx thread closing code, trylock on state lock failed: %s",
- strerror(iMutexLockResult));
- } else {
- ANT_DEBUG_V("stEnabledStatusLock busy");
- }
-
- out:
- ANT_FUNC_END();
-#ifdef ANDROID
- return NULL;
-#endif
-}
-
-void doReset(ant_rx_thread_info_t *stRxThreadInfo)
-{
- int iMutexLockResult;
-
- ANT_FUNC_START();
- /* Chip was reset or other error, only way to recover is to
- * close and open ANT chardev */
- stRxThreadInfo->ucChipResetting = 1;
-
- if (g_fnStateCallback) {
- g_fnStateCallback(RADIO_STATUS_RESETTING);
- }
-
- stRxThreadInfo->ucRunThread = 0;
-
- ANT_DEBUG_V("getting stEnabledStatusLock in %s", __FUNCTION__);
- iMutexLockResult = pthread_mutex_lock(stRxThreadInfo->pstEnabledStatusLock);
- if (iMutexLockResult < 0) {
- ANT_ERROR("chip was reset, getting state mutex failed: %s",
- strerror(iMutexLockResult));
- stRxThreadInfo->stRxThread = 0;
- stRxThreadInfo->ucChipResetting = 0;
- } else {
- ANT_DEBUG_V("got stEnabledStatusLock in %s", __FUNCTION__);
-
- stRxThreadInfo->stRxThread = 0; /* spoof our handle as closed so we don't
- * try to join ourselves in disable */
-
- ant_disable();
-
- int enableResult = ant_enable();
-
- stRxThreadInfo->ucChipResetting = 0;
- if (enableResult) { /* failed */
- if (g_fnStateCallback) {
- g_fnStateCallback(RADIO_STATUS_DISABLED);
- }
- } else { /* success */
- if (g_fnStateCallback) {
- g_fnStateCallback(RADIO_STATUS_RESET);
- }
- }
-
- ANT_DEBUG_V("releasing stEnabledStatusLock in %s", __FUNCTION__);
- pthread_mutex_unlock(stRxThreadInfo->pstEnabledStatusLock);
- ANT_DEBUG_V("released stEnabledStatusLock in %s", __FUNCTION__);
- }
-
- ANT_FUNC_END();
-}
-
-////////////////////////////////////////////////////////////////////
-// setFlowControl
-//
-// Sets the flow control "flag" to the value provided and signals the transmit
-// thread to check the value.
-//
-// Parameters:
-// pstChnlInfo the details of the channel being updated
-// ucFlowSetting the value to use
-//
-// Returns:
-// Success:
-// 0
-// Failure:
-// -1
-////////////////////////////////////////////////////////////////////
-int setFlowControl(ant_channel_info_t *pstChnlInfo, ANT_U8 ucFlowSetting)
-{
- int iRet = -1;
- int iMutexResult;
- ANT_FUNC_START();
-
- ANT_DEBUG_V("getting stFlowControlLock in %s", __FUNCTION__);
- iMutexResult = pthread_mutex_lock(pstChnlInfo->pstFlowControlLock);
- if (iMutexResult) {
- ANT_ERROR("failed to lock flow control mutex during response: %s", strerror(iMutexResult));
- } else {
- ANT_DEBUG_V("got stFlowControlLock in %s", __FUNCTION__);
-
- pstChnlInfo->ucFlowControlResp = ucFlowSetting;
-
- ANT_DEBUG_V("releasing stFlowControlLock in %s", __FUNCTION__);
- pthread_mutex_unlock(pstChnlInfo->pstFlowControlLock);
- ANT_DEBUG_V("released stFlowControlLock in %s", __FUNCTION__);
-
- pthread_cond_signal(pstChnlInfo->pstFlowControlCond);
-
- iRet = 0;
- }
-
- ANT_FUNC_END();
- return iRet;
-}
-
-int readChannelMsg(ant_channel_type eChannel, ant_channel_info_t *pstChnlInfo)
-{
- int iRet = -1;
- int iRxLenRead;
- int iCurrentHciPacketOffset;
- int iHciDataSize;
- ANT_FUNC_START();
-
- // Keep trying to read while there is an error, and that error is EAGAIN
- while (((iRxLenRead = read(pstChnlInfo->iFd, &aucRxBuffer[eChannel][iRxBufferLength[eChannel]], (sizeof(aucRxBuffer[eChannel]) - iRxBufferLength[eChannel]))) < 0)
- && errno == EAGAIN)
- ;
-
- if (iRxLenRead < 0) {
- if (errno == ENODEV) {
- ANT_ERROR("%s not enabled",
- pstChnlInfo->pcDevicePath);
-
- goto out;
- } else if (errno == ENXIO) {
- ANT_ERROR("%s there is no physical ANT device connected",
- pstChnlInfo->pcDevicePath);
-
- goto out;
- } else {
- ANT_ERROR("%s: unhandled error: %s",
- pstChnlInfo->pcDevicePath, strerror(errno));
-
- goto out;
- }
- } else {
- ANT_SERIAL(aucRxBuffer[eChannel], iRxLenRead, 'R');
-
- iRxLenRead += iRxBufferLength[eChannel]; // add existing data on
-
- // if we didn't get a full packet, then just exit
- if (iRxLenRead < (aucRxBuffer[eChannel][ANT_HCI_SIZE_OFFSET] + ANT_HCI_HEADER_SIZE + ANT_HCI_FOOTER_SIZE)) {
- iRxBufferLength[eChannel] = iRxLenRead;
- iRet = 0;
- goto out;
- }
-
- iRxBufferLength[eChannel] = 0; // reset buffer length here since we should have a full packet
-
-#if ANT_HCI_OPCODE_SIZE == 1 // Check the different message types by opcode
- ANT_U8 opcode = aucRxBuffer[eChannel][ANT_HCI_OPCODE_OFFSET];
-
- if(ANT_HCI_OPCODE_COMMAND_COMPLETE == opcode) {
- // Command Complete, so signal a FLOW_GO
- if(setFlowControl(pstChnlInfo, ANT_FLOW_GO)) {
- goto out;
- }
- } else if(ANT_HCI_OPCODE_FLOW_ON == opcode) {
- // FLow On, so resend the last Tx
-#ifdef ANT_FLOW_RESEND
- // Check if there is a message to resend
- if(pstChnlInfo->ucResendMessageLength > 0) {
- ant_tx_message_flowcontrol_none(eChannel, pstChnlInfo->ucResendMessageLength, pstChnlInfo->pucResendMessage);
- } else {
- ANT_DEBUG_D("Resend requested by chip, but tx request cancelled");
- }
-#endif // ANT_FLOW_RESEND
- } else if(ANT_HCI_OPCODE_ANT_EVENT == opcode)
- // ANT Event, send ANT packet to Rx Callback
-#endif // ANT_HCI_OPCODE_SIZE == 1
- {
- // Received an ANT packet
- iCurrentHciPacketOffset = 0;
-
- while(iCurrentHciPacketOffset < iRxLenRead) {
-
- // TODO Allow HCI Packet Size value to be larger than 1 byte
- // This currently works as no size value is greater than 255, and little endian
- iHciDataSize = aucRxBuffer[eChannel][iCurrentHciPacketOffset + ANT_HCI_SIZE_OFFSET];
-
- if ((iHciDataSize + ANT_HCI_HEADER_SIZE + ANT_HCI_FOOTER_SIZE + iCurrentHciPacketOffset) >
- iRxLenRead) {
- // we don't have a whole packet
- iRxBufferLength[eChannel] = iRxLenRead - iCurrentHciPacketOffset;
- memcpy(aucRxBuffer[eChannel], &aucRxBuffer[eChannel][iCurrentHciPacketOffset], iRxBufferLength[eChannel]);
- // the increment at the end should push us out of the while loop
- } else
-#ifdef ANT_MESG_FLOW_CONTROL
- if (aucRxBuffer[eChannel][iCurrentHciPacketOffset + ANT_HCI_DATA_OFFSET + ANT_MSG_ID_OFFSET] ==
- ANT_MESG_FLOW_CONTROL) {
- // This is a flow control packet, not a standard ANT message
- if(setFlowControl(pstChnlInfo, \
- aucRxBuffer[eChannel][iCurrentHciPacketOffset + ANT_HCI_DATA_OFFSET + ANT_MSG_DATA_OFFSET])) {
- goto out;
- }
- } else
-#endif // ANT_MESG_FLOW_CONTROL
- {
- ANT_U8 *msg = aucRxBuffer[eChannel] + iCurrentHciPacketOffset + ANT_HCI_DATA_OFFSET;
- ANT_BOOL bIsKeepAliveResponse = memcmp(msg, KEEPALIVE_RESP, sizeof(KEEPALIVE_RESP)/sizeof(ANT_U8)) == 0;
- if (bIsKeepAliveResponse) {
- ANT_DEBUG_V("Filtered out keepalive response.");
- } else if (pstChnlInfo->fnRxCallback != NULL) {
-
- // Loop through read data until all HCI packets are written to callback
- pstChnlInfo->fnRxCallback(iHciDataSize, \
- msg);
- } else {
- ANT_WARN("%s rx callback is null", pstChnlInfo->pcDevicePath);
- }
- }
-
- iCurrentHciPacketOffset = iCurrentHciPacketOffset + ANT_HCI_HEADER_SIZE + ANT_HCI_FOOTER_SIZE + iHciDataSize;
- }
- }
-
- iRet = 0;
- }
-
-out:
- ANT_FUNC_END();
- return iRet;
-}
diff --git a/src/vfs/inc/ant_hci_defines.h b/src/vfs/inc/ant_hci_defines.h
deleted file mode 100644
index b51eb8a..0000000
--- a/src/vfs/inc/ant_hci_defines.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2013 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*******************************************************************************\
-*
-* FILE NAME: ant_hci_defines.h
-*
-* BRIEF:
-* This file defines ANT specific HCI values used by the ANT chip that are
-* not specific to the underlying chip. These should not need to be modified,
-* but should be verified they are correct.
-*
-\*******************************************************************************/
-
-#ifndef __VFS_INDEPENDENT_H
-#define __VFS_INDEPENDENT_H
-
-// ANT HCI Packet Structure
-// -----------------------------------------
-// | Header | Data | Footer |
-// |----------------------|-----------------|
-// |Optional| Data | Opt. | ... | Optional |
-// | Opcode | Size | Sync | | Checksum |
-// Data may include any number of ANT packets, with no sync byte or checksum.
-// A read from the driver may return any number of ANT HCI packets.
-
-#include "ant_driver_defines.h"
-
-#define ANT_HCI_HEADER_SIZE ((ANT_HCI_OPCODE_SIZE) + (ANT_HCI_CHANNEL_SIZE) + (ANT_HCI_SIZE_SIZE) + (ANT_HCI_SYNC_SIZE))
-#define ANT_HCI_FOOTER_SIZE (ANT_HCI_CHECKSUM_SIZE)
-
-#define ANT_HCI_OPCODE_OFFSET 0
-#define ANT_HCI_CHANNEL_OFFSET ((ANT_HCI_OPCODE_OFFSET) + (ANT_HCI_OPCODE_SIZE))
-#define ANT_HCI_SIZE_OFFSET ((ANT_HCI_CHANNEL_OFFSET) + (ANT_HCI_CHANNEL_SIZE))
-#define ANT_HCI_SYNC_OFFSET ((ANT_HCI_SIZE_OFFSET) + (ANT_HCI_SIZE_SIZE))
-#define ANT_HCI_DATA_OFFSET (ANT_HCI_HEADER_SIZE)
-
-#define ANT_FLOW_GO_WAIT_TIMEOUT_SEC 10
-
-#endif /* ifndef __VFS_INDEPENDENT_H */
diff --git a/src/vfs/inc/ant_rx_chardev.h b/src/vfs/inc/ant_rx_chardev.h
deleted file mode 100644
index d76184e..0000000
--- a/src/vfs/inc/ant_rx_chardev.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2011 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*******************************************************************************\
-*
-* FILE NAME: ant_rx_chardev.h
-*
-* BRIEF:
-* This file defines the receive thread function, the ant_rx_thread_info_t
-* type for storing the -configuration- <state> of the receive thread, the
-* ant_channel_info_t type for storing a channel's (transport path)
-* configuration, and an enumeration of all ANT channels (transport paths).
-*
-*
-\*******************************************************************************/
-
-#ifndef __ANT_RX_NATIVE_H
-#define __ANT_RX_NATIVE_H
-
-#include "ant_native.h"
-#include "ant_hci_defines.h"
-
-/* same as HCI_MAX_EVENT_SIZE from hci.h, but hci.h is not included for vfs */
-#define ANT_HCI_MAX_MSG_SIZE 260
-
-#define ANT_MSG_SIZE_OFFSET ((ANT_U8)0)
-#define ANT_MSG_ID_OFFSET ((ANT_U8)1)
-#define ANT_MSG_DATA_OFFSET ((ANT_U8)2)
-
-/* This struct defines the info passed to an rx thread */
-typedef struct {
- /* Device path */
- const char *pcDevicePath;
- /* File descriptor to read from */
- int iFd;
- /* Callback to call with ANT packet */
- ANTNativeANTEventCb fnRxCallback;
- /* Flow control response if channel supports it */
- ANT_U8 ucFlowControlResp;
- /* Handle to flow control condition */
- pthread_cond_t *pstFlowControlCond;
- /* Handle to flow control mutex */
- pthread_mutex_t *pstFlowControlLock;
-#ifdef ANT_FLOW_RESEND
- /* Length of message to resend on request from chip */
- ANT_U8 ucResendMessageLength;
- /* The message to resend on request from chip */
- ANT_U8 *pucResendMessage;
-#endif // ANT_FLOW_RESEND
-} ant_channel_info_t;
-
-typedef enum {
-#ifdef ANT_DEVICE_NAME // Single transport path
- SINGLE_CHANNEL,
-#else // Separate data/command paths
- DATA_CHANNEL,
- COMMAND_CHANNEL,
-#endif // Separate data/command paths
- NUM_ANT_CHANNELS
-} ant_channel_type;
-
-typedef struct {
- /* Thread handle */
- pthread_t stRxThread;
- /* Exit condition */
- ANT_U8 ucRunThread;
- /* Set state as resetting override */
- ANT_U8 ucChipResetting;
- /* Handle to state change lock for crash cleanup */
- pthread_mutex_t *pstEnabledStatusLock;
- /* ANT channels */
- ant_channel_info_t astChannels[NUM_ANT_CHANNELS];
- /* Event file descriptor used to interrupt the poll() loop in the rx thread. */
- int iRxShutdownEventFd;
- /* Indicates whether thread is waiting for a keepalive response. */
- ANT_BOOL bWaitingForKeepaliveResponse;
-} ant_rx_thread_info_t;
-
-extern ANTNativeANTStateCb g_fnStateCallback; // TODO State callback should be inside ant_rx_thread_info_t.
-
-/* This is the rx thread function. It loops reading ANT packets until told to
- * exit */
-void *fnRxThread(void *ant_rx_thread_info);
-
-#endif /* ifndef __ANT_RX_NATIVE_H */
-
diff --git a/src/vfs/inc/antradio_power.h b/src/vfs/inc/antradio_power.h
deleted file mode 100644
index 1aa0b24..0000000
--- a/src/vfs/inc/antradio_power.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __ANTRADIOPM_H
-#define __ANTRADIOPM_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Enable the ANT radio interface.
- *
- * Responsible for power on, and bringing up HCI interface.
- * Will block until the HCI interface is ready to use.
- *
- * Returns 0 on success, -ve on error */
-int ant_enable();
-
-/* Disable the ANT radio interface.
- *
- * Responsbile for pulling down the HCI interface, and powering down the chip.
- * Will block until power down is complete, and it is safe to immediately call
- * enable().
- *
- * Returns 0 on success, -ve on error */
-int ant_disable();
-
-/* Returns 1 if enabled, 0 if disabled, and -ve on error */
-int ant_is_enabled();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/vfs/prerelease/ant_driver_defines.h b/src/vfs/prerelease/ant_driver_defines.h
deleted file mode 100644
index 3eb5c31..0000000
--- a/src/vfs/prerelease/ant_driver_defines.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2011 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*******************************************************************************\
-*
-* FILE NAME: ant_driver_defines.h
-*
-* BRIEF:
-* This file defines ANT specific HCI values used by the ANT chip for a
-* sample TTY implementation.
-*
-*
-\*******************************************************************************/
-
-#ifndef __VFS_PRERELEASE_H
-#define __VFS_PRERELEASE_H
-
-// -----------------------------------------
-// | Header | Data | Footer |
-// |----------------------|-----------------|
-// |Optional| Data | Opt. | ... | Optional |
-// | Opcode | Size | Sync | | Checksum |
-
-// Data may include any number of ANT packets, with no sync byte or checksum.
-// A read from the driver may return any number of ANT HCI packets.
-
-
-// ---------------------- REQUIRED
-
-// Which chip is this library being built for:
-#define ANT_CHIP_NAME "TTY"
-
-// Set the file name the driver creates for the ANT device:
-// If chip uses separate command and data paths:
-// #define ANT_COMMANDS_DEVICE_NAME "/dev/smd5"
-// #define ANT_DATA_DEVICE_NAME "/dev/smd6"
-// OR
-// If chip uses one path:
-#define ANT_DEVICE_NAME "/dev/ant"
-
-// Set to the number of bytes of header is for Opcode:
-#define ANT_HCI_OPCODE_SIZE 0
-
-// Set to the number of bytes of header for channel ID
-#define ANT_HCI_CHANNEL_SIZE 1
-
-// Set to the number of bytes of header is for Data Size:
-#define ANT_HCI_SIZE_SIZE 1
-
-// Set to the number of bytes of header is for Sync:
-#define ANT_HCI_SYNC_SIZE 0
-
-// Set to the number of bytes of footer is for Checksum:
-#define ANT_HCI_CHECKSUM_SIZE 0
-
-// ---------------------- OPTIONAL
-
-// If hard reset is supported, define ANT_IOCTL_RESET
-// #define ANT_IOCTL_RESET _IOW('U', 210, int)
-// #define ANT_IOCTL_RESET_PARAMETER (0)
-
-// If the chip sends flow control messages:
-// Define the Opcode for a Flow Control message:
-#define ANT_MESG_FLOW_CONTROL ((ANT_U8)0xC9)
-// AND
-// define the message content:
-// That signals Flow Go:
-#define ANT_FLOW_GO ((ANT_U8)0x00)
-
-// That signals Flow Stop:
-#define ANT_FLOW_STOP ((ANT_U8)0x80)
-
-// If using a channel ID byte, define the ids.
-#define ANT_HCI_COMMAND_CHANNEL ((ANT_U8)0x0C)
-#define ANT_HCI_DATA_CHANNEL ((ANT_U8)0x0E)
-
-#endif /* ifndef __VFS_PRERELEASE_H */
diff --git a/src/vfs/qualcomm/smd/ant_driver_defines.h b/src/vfs/qualcomm/smd/ant_driver_defines.h
deleted file mode 100644
index 948c524..0000000
--- a/src/vfs/qualcomm/smd/ant_driver_defines.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2011 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*******************************************************************************\
-*
-* FILE NAME: ant_driver_defines.h
-*
-* BRIEF:
-* This file defines ANT specific HCI values used by the ANT chip for a
-* sample TTY implementation.
-*
-*
-\*******************************************************************************/
-
-#ifndef __VFS_PRERELEASE_H
-#define __VFS_PRERELEASE_H
-
-// -----------------------------------------
-// | Header | Data | Footer |
-// |----------------------|-----------------|
-// |Optional| Data | Opt. | ... | Optional |
-// | Opcode | Size | Sync | | Checksum |
-
-// Data may include any number of ANT packets, with no sync byte or checksum.
-// A read from the driver may return any number of ANT HCI packets.
-
-
-// ---------------------- REQUIRED
-
-// Which chip is this library being built for:
-#define ANT_CHIP_NAME "Qualcomm SMD"
-
-// Set the file name the driver creates for the ANT device:
-// If chip uses separate command and data paths:
-#define ANT_COMMANDS_DEVICE_NAME "/dev/smd5"
-#define ANT_DATA_DEVICE_NAME "/dev/smd6"
-// OR
-// If chip uses one path:
-// #define ANT_DEVICE_NAME "/dev/Z"
-
-// Set to the number of bytes of header is for Opcode:
-#define ANT_HCI_OPCODE_SIZE 0
-
-// Set to the number of bytes of header for channel ID
-#define ANT_HCI_CHANNEL_SIZE 0
-
-// Set to the number of bytes of header is for Data Size:
-#define ANT_HCI_SIZE_SIZE 1
-
-// Set to the number of bytes of header is for Sync:
-#define ANT_HCI_SYNC_SIZE 0
-
-// Set to the number of bytes of footer is for Checksum:
-#define ANT_HCI_CHECKSUM_SIZE 0
-
-// ---------------------- OPTIONAL
-
-// If hard reset is supported, define ANT_IOCTL_RESET
-// #define ANT_IOCTL_RESET _IOW('U', 210, int)
-// #define ANT_IOCTL_RESET_PARAMETER (0)
-
-// If the chip sends flow control messages:
-// Define the Opcode for a Flow Control message:
-#define ANT_MESG_FLOW_CONTROL ((ANT_U8)0xC9)
-// AND
-// define the message content:
-// That signals Flow Go:
-#define ANT_FLOW_GO ((ANT_U8)0x00)
-
-// That signals Flow Stop:
-#define ANT_FLOW_STOP ((ANT_U8)0x80)
-
-#endif /* ifndef __VFS_PRERELEASE_H */
diff --git a/src/vfs/ste/cg29xx/ant_driver_defines.h b/src/vfs/ste/cg29xx/ant_driver_defines.h
deleted file mode 100644
index b72439f..0000000
--- a/src/vfs/ste/cg29xx/ant_driver_defines.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * ANT Stack
- *
- * Copyright 2011 Dynastream Innovations
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*******************************************************************************\
-*
-* FILE NAME: ant_driver_defines.h
-*
-* BRIEF:
-* This file defines ANT specific HCI values used by the ANT stack for a
-* ST-E CG29XX.
-*
-*
-\*******************************************************************************/
-
-#ifndef __VFS_PRERELEASE_H
-#define __VFS_PRERELEASE_H
-
-// ANT HCI Packet Structure
-// -----------------------------------------
-// | Header | Data | Footer |
-// |----------------------|-----------------|
-// |Optional| Data | Opt. | ... | Optional |
-// | Opcode | Size | Sync | | Checksum |
-// Data may include any number of ANT packets, with no sync byte or checksum.
-// A read from the driver may return any number of ANT HCI packets.
-
-
-// ---------------------- REQUIRED
-
-// Which chip is this library being built for:
-#define ANT_CHIP_NAME "ST-E CG29XX"
-
-// Set the file name the driver creates for the ANT device:
-// If chip uses separate command and data paths:
-#define ANT_COMMANDS_DEVICE_NAME "/dev/cg2900_antradio_cmd"
-#define ANT_DATA_DEVICE_NAME "/dev/cg2900_antradio_data"
-// OR
-// If chip uses one path:
-// #define ANT_DEVICE_NAME "/dev/Z"
-
-// Set to the number of bytes of header is for Opcode:
-#define ANT_HCI_OPCODE_SIZE 0
-// Set to the number of bytes of header for channel ID
-#define ANT_HCI_CHANNEL_SIZE 0
-// Set to the number of bytes of header is for Data Size:
-#define ANT_HCI_SIZE_SIZE 1
-
-// Set to the number of bytes of header is for Sync:
-#define ANT_HCI_SYNC_SIZE 0
-// Set to the number of bytes of footer is for Checksum:
-#define ANT_HCI_CHECKSUM_SIZE 0
-
-
-// ---------------------- OPTIONAL
-
-// If hard reset is supported, define ANT_IOCTL_RESET
-#define ANT_IOCTL_RESET _IOW('U', 210, int)
-#define ANT_IOCTL_RESET_PARAMETER (0)
-
-// If the chip sends flow control messages:
-// Define the Opcode for a Flow Control message:
-#define ANT_MESG_FLOW_CONTROL ((ANT_U8)0xC9)
-// AND
-// define the message content:
-// That signals Flow Go:
-#define ANT_FLOW_GO ((ANT_U8)0x00)
-// That signals Flow Stop:
-#define ANT_FLOW_STOP ((ANT_U8)0x80)
-
-#endif /* ifndef __VFS_PRERELEASE_H */