Merge commit '15a5a06e7ce0ad04ea49ad7bb5226d5e98560145' into merge
diff --git a/hardware.c b/hardware.c
index 6713ea0..79d0a2f 100644
--- a/hardware.c
+++ b/hardware.c
@@ -67,9 +67,9 @@
const char *path,
const struct hw_module_t **pHmi)
{
- int status;
- void *handle;
- struct hw_module_t *hmi;
+ int status = -EINVAL;
+ void *handle = NULL;
+ struct hw_module_t *hmi = NULL;
/*
* load the symbols resolving undefined symbols before
@@ -145,11 +145,12 @@
int hw_get_module_by_class(const char *class_id, const char *inst,
const struct hw_module_t **module)
{
- int i;
- char prop[PATH_MAX];
- char path[PATH_MAX];
- char name[PATH_MAX];
- char prop_name[PATH_MAX];
+ int i = 0;
+ char prop[PATH_MAX] = {0};
+ char path[PATH_MAX] = {0};
+ char name[PATH_MAX] = {0};
+ char prop_name[PATH_MAX] = {0};
+
if (inst)
snprintf(name, PATH_MAX, "%s.%s", class_id, inst);
diff --git a/include/hardware/audio_effect.h b/include/hardware/audio_effect.h
index ee48e4c..41cd2e6 100644
--- a/include/hardware/audio_effect.h
+++ b/include/hardware/audio_effect.h
@@ -344,9 +344,10 @@
// Output:
// returned value: 0 successful operation
// -EINVAL invalid interface handle or
- // invalid command/reply size or format according to command code
- // The return code should be restricted to indicate problems related to the this
- // API specification. Status related to the execution of a particular command should be
+ // invalid command/reply size or format according to
+ // command code
+ // The return code should be restricted to indicate problems related to this API
+ // specification. Status related to the execution of a particular command should be
// indicated as part of the reply field.
//
// *pReplyData updated with command response
@@ -937,11 +938,12 @@
//
// Input:
// uuid: pointer to the effect uuid.
- // sessionId: audio session to which this effect instance will be attached. All effects
- // created with the same session ID are connected in series and process the same signal
- // stream. Knowing that two effects are part of the same effect chain can help the
- // library implement some kind of optimizations.
- // ioId: identifies the output or input stream this effect is directed to at audio HAL.
+ // sessionId: audio session to which this effect instance will be attached.
+ // All effects created with the same session ID are connected in series and process
+ // the same signal stream. Knowing that two effects are part of the same effect
+ // chain can help the library implement some kind of optimizations.
+ // ioId: identifies the output or input stream this effect is directed to in
+ // audio HAL.
// For future use especially with tunneled HW accelerated effects
//
// Input/Output:
diff --git a/include/hardware/fingerprint.h b/include/hardware/fingerprint.h
index 458ca2d..1fe8cc9 100644
--- a/include/hardware/fingerprint.h
+++ b/include/hardware/fingerprint.h
@@ -18,6 +18,7 @@
#define ANDROID_INCLUDE_HARDWARE_FINGERPRINT_H
#define FINGERPRINT_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
+#define FINGERPRINT_MODULE_API_VERSION_2_0 HARDWARE_MODULE_API_VERSION(2, 0)
#define FINGERPRINT_HARDWARE_MODULE_ID "fingerprint"
typedef enum fingerprint_msg_type {
@@ -25,50 +26,71 @@
FINGERPRINT_ACQUIRED = 1,
FINGERPRINT_PROCESSED = 2,
FINGERPRINT_TEMPLATE_ENROLLING = 3,
- FINGERPRINT_TEMPLATE_REMOVED = 4
+ FINGERPRINT_TEMPLATE_REMOVED = 4,
+ FINGERPRINT_AUTHENTICATED = 5
} fingerprint_msg_type_t;
typedef enum fingerprint_error {
FINGERPRINT_ERROR_HW_UNAVAILABLE = 1,
FINGERPRINT_ERROR_UNABLE_TO_PROCESS = 2,
FINGERPRINT_ERROR_TIMEOUT = 3,
- FINGERPRINT_ERROR_NO_SPACE = 4 /* No space available to store a template */
+ FINGERPRINT_ERROR_NO_SPACE = 4, /* No space available to store a template */
+ FINGERPRINT_ERROR_CANCELED = 5,
+ FINGERPRINT_ERROR_UNABLE_TO_REMOVE = 6, /* fingerprint id can't be removed */
+ FINGERPRINT_ERROR_VENDOR_BASE = 1000 /* vendor-specific error messages start here */
} fingerprint_error_t;
typedef enum fingerprint_acquired_info {
FINGERPRINT_ACQUIRED_GOOD = 0,
FINGERPRINT_ACQUIRED_PARTIAL = 1,
FINGERPRINT_ACQUIRED_INSUFFICIENT = 2,
- FINGERPRINT_ACQUIRED_IMAGER_DIRTY = 4,
- FINGERPRINT_ACQUIRED_TOO_SLOW = 8,
- FINGERPRINT_ACQUIRED_TOO_FAST = 16
+ FINGERPRINT_ACQUIRED_IMAGER_DIRTY = 3,
+ FINGERPRINT_ACQUIRED_TOO_SLOW = 4,
+ FINGERPRINT_ACQUIRED_TOO_FAST = 5,
+ FINGERPRINT_ACQUIRED_VENDOR_BASE = 1000 /* vendor-specific acquisition messages start here */
} fingerprint_acquired_info_t;
+typedef struct fingerprint_finger_id {
+ uint32_t gid;
+ uint32_t fid;
+} fingerprint_finger_id_t;
+
+/* The progress indication may be augmented by a bitmap encoded indication
+* of what finger area is considered as collected.
+* Bit numbers mapped to physical location:
+*
+* distal
+* +--+--+--+--+--+
+* | 4| 3| 2| 1| 0|
+* | 9| 8| 7| 6| 5|
+* medial |14|13|12|11|10| lateral
+* |19|18|17|16|15|
+* |24|23|22|21|20|
+* +--+--+--+--+--+
+* proximal
+*
+*/
+typedef uint32_t finger_map_bmp;
+
+typedef enum fingerprint_enroll_msg_type {
+ FINGERPRINT_ENROLL_MSG_NONE = 0,
+ FINGERPRINT_ENROLL_MSG_PREDEFINED = 1, /* TODO: define standard enroll cues */
+ FINGERPRINT_ENROLL_MSG_BITMAP = 2, /* typeof(fingerprint_enroll.msg) == *finger_map_bmp */
+ FINGERPRINT_ENROLL_MSG_VENDOR = 3
+} fingerprint_enroll_msg_type_t;
+
typedef struct fingerprint_enroll {
- uint32_t id;
+ fingerprint_finger_id_t finger;
/* samples_remaining goes from N (no data collected, but N scans needed)
- * to 0 (no more data is needed to build a template).
- * The progress indication may be augmented by a bitmap encoded indication
- * of finger area that needs to be presented by the user.
- * Bit numbers mapped to physical location:
- *
- * distal
- * +-+-+-+
- * |2|1|0|
- * |5|4|3|
- * medial |8|7|6| lateral
- * |b|a|9|
- * |e|d|c|
- * +-+-+-+
- * proximal
- *
- */
- uint16_t data_collected_bmp;
- uint16_t samples_remaining;
+ * to 0 (no more data is needed to build a template). */
+ uint32_t samples_remaining;
+ fingerprint_enroll_msg_type_t msg_type;
+ size_t msg_size;
+ void *msg;
} fingerprint_enroll_t;
typedef struct fingerprint_removed {
- uint32_t id;
+ fingerprint_finger_id_t finger;
} fingerprint_removed_t;
typedef struct fingerprint_acquired {
@@ -76,18 +98,29 @@
} fingerprint_acquired_t;
typedef struct fingerprint_processed {
- uint32_t id; /* 0 is a special id and means no match */
+ fingerprint_finger_id_t finger; /* all 0s is a special case and means no match */
} fingerprint_processed_t;
+typedef struct fingerprint_authenticated {
+ uint32_t user_id;
+ uint32_t auth_id;
+ uint32_t timestamp;
+ uint32_t app_id;
+ uint64_t crypto_op_id;
+ uint8_t hmac[16]; /* 128-bit */
+ uint32_t auth_token_size;
+ uint8_t *auth_token;
+} fingerprint_authenticated_t;
+
typedef struct fingerprint_msg {
fingerprint_msg_type_t type;
union {
- uint64_t raw;
fingerprint_error_t error;
fingerprint_enroll_t enroll;
fingerprint_removed_t removed;
fingerprint_acquired_t acquired;
fingerprint_processed_t processed;
+ fingerprint_authenticated_t authenticated;
} data;
} fingerprint_msg_t;
@@ -111,12 +144,14 @@
* (fingerprint_msg.type == FINGERPRINT_TEMPLATE_ENROLLING &&
* fingerprint_msg.data.enroll.samples_remaining == 0)
* or after timeout_sec seconds.
+ * The fingerprint template will be assigned to the group gid. User has a choice
+ * to supply the gid or set it to 0 in which case a unique group id will be generated.
*
* Function return: 0 if enrollment process can be successfully started
* -1 otherwise. A notify() function may be called
* indicating the error condition.
*/
- int (*enroll)(struct fingerprint_device *dev, uint32_t timeout_sec);
+ int (*enroll)(struct fingerprint_device *dev, uint32_t gid, uint32_t timeout_sec);
/*
* Cancel fingerprint enroll request:
@@ -133,7 +168,9 @@
/*
* Fingerprint remove request:
* deletes a fingerprint template.
- * If the fingerprint id is 0 the entire template database will be removed.
+ * If the fingerprint id is 0 and the group is 0 then the entire template
+ * database will be removed. A combinaiton of fingerprint id 0 and a valid
+ * group id deletes all fingreprints in that group.
* notify() will be called for each template deleted with
* fingerprint_msg.type == FINGERPRINT_TEMPLATE_REMOVED and
* fingerprint_msg.data.removed.id indicating each template id removed.
@@ -141,7 +178,24 @@
* Function return: 0 if fingerprint template(s) can be successfully deleted
* -1 otherwise.
*/
- int (*remove)(struct fingerprint_device *dev, uint32_t fingerprint_id);
+ int (*remove)(struct fingerprint_device *dev, fingerprint_finger_id_t finger);
+
+ /*
+ * Restricts the HAL operation to a set of fingerprints belonging to a
+ * group provided. Gid of 0 signals global operation.
+ *
+ * Function return: 0 on success
+ * -1 if the group does not exist.
+ */
+ int (*set_active_group)(struct fingerprint_device *dev, uint32_t gid);
+
+ /*
+ * Authenticates an operation identifed by operation_id
+ *
+ * Function return: 0 on success
+ * -1 if the size is out of bounds.
+ */
+ int (*authenticate)(struct fingerprint_device *dev, uint64_t operation_id, uint32_t gid);
/*
* Set notification callback:
diff --git a/include/hardware/gatekeeper.h b/include/hardware/gatekeeper.h
new file mode 100644
index 0000000..9150e70
--- /dev/null
+++ b/include/hardware/gatekeeper.h
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2015 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 ANDROID_HARDWARE_GATEKEEPER_H
+#define ANDROID_HARDWARE_GATEKEEPER_H
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <hardware/hardware.h>
+
+__BEGIN_DECLS
+
+#define GATEKEEPER_HARDWARE_MODULE_ID "gatekeeper"
+
+#define GATEKEEPER_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
+
+#define HARDWARE_GATEKEEPER "gatekeeper"
+
+struct gatekeeper_module {
+ /**
+ * Comon methods of the gatekeeper module. This *must* be the first member of
+ * gatekeeper_module as users of this structure will cast a hw_module_t to
+ * a gatekeeper_module pointer in the appropriate context.
+ */
+ hw_module_t common;
+};
+
+struct gatekeeper_device {
+ /**
+ * Common methods of the gatekeeper device. As above, this must be the first
+ * member of keymaster_device.
+ */
+ hw_device_t common;
+
+ /**
+ * Enrolls desired_password, which should be derived from a user selected pin or password,
+ * with the authentication factor private key used only for enrolling authentication
+ * factor data.
+ *
+ * If there was already a password enrolled, it should be provided in
+ * current_password_handle, along with the current password in current_password
+ * that should validate against current_password_handle.
+ *
+ * Returns: 0 on success or an error code less than 0 on error.
+ * On error, enrolled_password_handle will not be allocated.
+ */
+ int (*enroll)(const struct gatekeeper_device *dev, uint32_t uid,
+ const uint8_t *current_password_handle, size_t current_password_handle_length,
+ const uint8_t *current_password, size_t current_password_length,
+ const uint8_t *desired_password, size_t desired_password_length,
+ uint8_t **enrolled_password_handle, size_t *enrolled_password_handle_length);
+
+ /**
+ * Verifies provided_password matches enrolled_password_handle.
+ *
+ * Implementations of this module may retain the result of this call
+ * to attest to the recency of authentication.
+ *
+ * On success, writes the address of a verification token to auth_token,
+ * usable to attest password verification to other trusted services. Clients
+ * may pass NULL for this value.
+ *
+ * Returns: 0 on success or an error code less than 0 on error
+ * On error, verification token will not be allocated
+ */
+ int (*verify)(const struct gatekeeper_device *dev, uint32_t uid,
+ const uint8_t *enrolled_password_handle, size_t enrolled_password_handle_length,
+ const uint8_t *provided_password, size_t provided_password_length,
+ uint8_t **auth_token, size_t *auth_token_length);
+
+};
+typedef struct gatekeeper_device gatekeeper_device_t;
+
+static inline int gatekeeper_open(const struct hw_module_t *module,
+ gatekeeper_device_t **device) {
+ return module->methods->open(module, HARDWARE_GATEKEEPER,
+ (struct hw_device_t **) device);
+}
+
+static inline int gatekeeper_close(gatekeeper_device_t *device) {
+ return device->common.close(&device->common);
+}
+
+__END_DECLS
+
+#endif // ANDROID_HARDWARE_GATEKEEPER_H
diff --git a/include/hardware/hw_auth_token.h b/include/hardware/hw_auth_token.h
new file mode 100644
index 0000000..154c1fd
--- /dev/null
+++ b/include/hardware/hw_auth_token.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+
+#include <stdint.h>
+
+#ifndef ANDROID_HARDWARE_HW_AUTH_TOKEN_H
+#define ANDROID_HARDWARE_HW_AUTH_TOKEN_H
+
+#ifndef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+typedef enum {
+ HW_AUTH_NONE = 0,
+ HW_AUTH_PASSWORD = 1 << 1,
+ HW_AUTH_FINGERPRINT = 1 << 2,
+ // Additional entries should be powers of 2.
+ HW_AUTH_ANY = UINT32_MAX,
+} hw_authenticator_type_t;
+
+/**
+ * Data format for an authentication record used to prove successful authentication.
+ */
+typedef struct __attribute__((__packed__)) {
+ uint8_t version; // Current version is 0
+ uint64_t challenge;
+ uint64_t user_id; // secure user ID, not Android user ID
+ uint64_t authenticator_id; // secure authenticator ID
+ uint32_t authenticator_type; // hw_authenticator_type_t, in network order
+ uint32_t timestamp; // in network order
+ uint8_t hmac[32];
+} hw_auth_token_t;
+
+#ifndef __cplusplus
+} // extern "C"
+#endif // __cplusplus
+
+#endif // ANDROID_HARDWARE_HW_AUTH_TOKEN_H
diff --git a/include/hardware/input.h b/include/hardware/input.h
new file mode 100644
index 0000000..dad1bc0
--- /dev/null
+++ b/include/hardware/input.h
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) 2015 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 ANDROID_INCLUDE_HARDWARE_INPUT_H
+#define ANDROID_INCLUDE_HARDWARE_INPUT_H
+
+#include <hardware/hardware.h>
+#include <stdint.h>
+
+__BEGIN_DECLS
+
+#define INPUT_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
+#define INPUT_HARDWARE_MODULE_ID "input"
+
+#define INPUT_INSTANCE_EVDEV "evdev"
+
+typedef enum input_bus {
+ INPUT_BUS_BT,
+ INPUT_BUS_USB,
+ INPUT_BUS_SERIAL,
+ INPUT_BUS_BUILTIN
+} input_bus_t;
+
+typedef struct input_host input_host_t;
+
+typedef struct input_device_handle input_device_handle_t;
+
+typedef struct input_device_identifier input_device_identifier_t;
+
+typedef struct input_device_definition input_device_definition_t;
+
+typedef struct input_report_definition input_report_definition_t;
+
+typedef struct input_report input_report_t;
+
+typedef struct input_collection input_collection_t;
+
+typedef enum {
+ INPUT_USAGE_TOUCHPAD_X,
+ INPUT_USAGE_TOUCHPAD_Y,
+ // etc
+} input_usage_t;
+
+typedef enum {
+ INPUT_COLLECTION_ID_TOUCH,
+ INPUT_COLLECTION_ID_KEYBOARD,
+ INPUT_COLLECTION_ID_MOUSE,
+ INPUT_COLLECTION_ID_TOUCHPAD,
+ // etc
+} input_collection_id_t;
+
+typedef struct input_message input_message_t;
+
+typedef struct input_host_callbacks {
+
+ /**
+ * Creates a device identifier with the given properties.
+ * The unique ID should be a string that precisely identifies a given piece of hardware. For
+ * example, an input device connected via Bluetooth could use its MAC address as its unique ID.
+ */
+ input_device_identifier_t* (*create_device_identifier)(input_host_t* host,
+ const char* name, int32_t product_id, int32_t vendor_id,
+ input_bus_t bus, const char* unique_id);
+
+ /**
+ * Allocates the device definition which will describe the input capabilities of a device. A
+ * device definition may be used to register as many devices as desired.
+ */
+ input_device_definition_t* (*create_device_definition)(input_host_t* host);
+
+ /**
+ * Allocate either an input report, which the HAL will use to tell the host of incoming input
+ * events, or an output report, which the host will use to tell the HAL of desired state
+ * changes (e.g. setting an LED).
+ */
+ input_report_definition_t* (*create_input_report_definition)(input_host_t* host);
+ input_report_definition_t* (*create_output_report_definition)(input_host_t* host);
+
+ /**
+ * Append the report to the given input device.
+ */
+ void (*input_device_definition_add_report)(input_host_t* host,
+ input_device_definition_t* d, input_report_definition_t* r);
+
+ /**
+ * Add a collection with the given arity and ID. A collection describes a set
+ * of logically grouped properties such as the X and Y coordinates of a single finger touch or
+ * the set of keys on a keyboard. The arity declares how many repeated instances of this
+ * collection will appear in whatever report it is attached to. The ID describes the type of
+ * grouping being represented by the collection. For example, a touchscreen capable of
+ * reporting up to 2 fingers simultaneously might have a collection with the X and Y
+ * coordinates, an arity of 2, and an ID of INPUT_COLLECTION_USAGE_TOUCHSCREEN. Any given ID
+ * may only be present once for a given report.
+ */
+ void (*input_report_definition_add_collection)(input_host_t* host,
+ input_report_definition_t* report, input_collection_id_t id, int32_t arity);
+
+ /**
+ * Declare an int usage with the given properties. The report and collection defines where the
+ * usage is being declared.
+ */
+ void (*input_report_definition_declare_usage_int)(input_host_t* host,
+ input_report_definition_t* report, input_collection_id_t id,
+ input_usage_t usage, int32_t min, int32_t max, float resolution);
+
+ /**
+ * Declare a set of boolean usages with the given properties. The report and collection
+ * defines where the usages are being declared.
+ */
+ void (*input_report_definition_declare_usages_bool)(input_host_t* host,
+ input_report_definition_t* report, input_collection_id_t id,
+ input_usage_t* usage, size_t usage_count);
+
+
+ /**
+ * Register a given input device definition. This notifies the host that an input device has
+ * been connected and gives a description of all its capabilities.
+ */
+ input_device_handle_t* (*register_device)(input_host_t* host,
+ input_device_identifier_t* id, input_device_definition_t* d);
+
+ /** Unregister the given device */
+ void (*unregister_device)(input_host_t* host, input_device_handle_t* handle);
+
+ /**
+ * Allocate a report that will contain all of the state as described by the given report.
+ */
+ input_report_t* (*input_allocate_report)(input_host_t* host, input_report_definition_t* r);
+
+ void (*report_event)(input_host_t* host, input_device_handle_t* d, input_report_t* report);
+} input_host_callbacks_t;
+
+typedef struct input_module input_module_t;
+
+struct input_module {
+ /**
+ * Common methods of the input module. This *must* be the first member
+ * of input_module as users of this structure will cast a hw_module_t
+ * to input_module pointer in contexts where it's known
+ * the hw_module_t references a input_module.
+ */
+ struct hw_module_t common;
+
+ /**
+ * Initialize the module with host callbacks. At this point the HAL should start up whatever
+ * infrastructure it needs to in order to process input events.
+ */
+ void (*init)(const input_module_t* module, input_host_t* host, input_host_callbacks_t cb);
+
+ /**
+ * Sends an output report with a new set of state the host would like the given device to
+ * assume.
+ */
+ void (*notify_report)(input_report_t* report);
+};
+
+static inline int input_open(const struct hw_module_t** module, const char* type) {
+ return hw_get_module_by_class(INPUT_HARDWARE_MODULE_ID, type, module);
+}
+
+__END_DECLS
+
+#endif /* ANDROID_INCLUDE_HARDWARE_INPUT_H */
diff --git a/include/hardware/keymaster.h b/include/hardware/keymaster.h
deleted file mode 100644
index 8c5ff14..0000000
--- a/include/hardware/keymaster.h
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * Copyright (C) 2011 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 ANDROID_HARDWARE_KEYMASTER_H
-#define ANDROID_HARDWARE_KEYMASTER_H
-
-#include <stdint.h>
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include <hardware/hardware.h>
-
-__BEGIN_DECLS
-
-/**
- * The id of this module
- */
-#define KEYSTORE_HARDWARE_MODULE_ID "keystore"
-
-#define KEYSTORE_KEYMASTER "keymaster"
-
-/**
- * Settings for "module_api_version" and "hal_api_version"
- * fields in the keymaster_module initialization.
- */
-#define KEYMASTER_HEADER_VERSION 3
-
-#define KEYMASTER_MODULE_API_VERSION_0_2 HARDWARE_MODULE_API_VERSION(0, 2)
-#define KEYMASTER_DEVICE_API_VERSION_0_2 HARDWARE_DEVICE_API_VERSION_2(0, 2, KEYMASTER_HEADER_VERSION)
-
-#define KEYMASTER_MODULE_API_VERSION_0_3 HARDWARE_MODULE_API_VERSION(0, 3)
-#define KEYMASTER_DEVICE_API_VERSION_0_3 HARDWARE_DEVICE_API_VERSION_2(0, 3, KEYMASTER_HEADER_VERSION)
-
-/**
- * Flags for keymaster_device::flags
- */
-enum {
- /*
- * Indicates this keymaster implementation does not have hardware that
- * keeps private keys out of user space.
- *
- * This should not be implemented on anything other than the default
- * implementation.
- */
- KEYMASTER_SOFTWARE_ONLY = 1 << 0,
-
- /*
- * This indicates that the key blobs returned via all the primitives
- * are sufficient to operate on their own without the trusted OS
- * querying userspace to retrieve some other data. Key blobs of
- * this type are normally returned encrypted with a
- * Key Encryption Key (KEK).
- *
- * This is currently used by "vold" to know whether the whole disk
- * encryption secret can be unwrapped without having some external
- * service started up beforehand since the "/data" partition will
- * be unavailable at that point.
- */
- KEYMASTER_BLOBS_ARE_STANDALONE = 1 << 1,
-
- /*
- * Indicates that the keymaster module supports DSA keys.
- */
- KEYMASTER_SUPPORTS_DSA = 1 << 2,
-
- /*
- * Indicates that the keymaster module supports EC keys.
- */
- KEYMASTER_SUPPORTS_EC = 1 << 3,
-};
-
-struct keystore_module {
- /**
- * Common methods of the keystore module. This *must* be the first member of
- * keystore_module as users of this structure will cast a hw_module_t to
- * keystore_module pointer in contexts where it's known the hw_module_t references a
- * keystore_module.
- */
- hw_module_t common;
-};
-
-/**
- * Asymmetric key pair types.
- */
-typedef enum {
- TYPE_RSA = 1,
- TYPE_DSA = 2,
- TYPE_EC = 3,
-} keymaster_keypair_t;
-
-/**
- * Parameters needed to generate an RSA key.
- */
-typedef struct {
- uint32_t modulus_size;
- uint64_t public_exponent;
-} keymaster_rsa_keygen_params_t;
-
-/**
- * Parameters needed to generate a DSA key.
- */
-typedef struct {
- uint32_t key_size;
- uint32_t generator_len;
- uint32_t prime_p_len;
- uint32_t prime_q_len;
- const uint8_t* generator;
- const uint8_t* prime_p;
- const uint8_t* prime_q;
-} keymaster_dsa_keygen_params_t;
-
-/**
- * Parameters needed to generate an EC key.
- *
- * Field size is the only parameter in version 2. The sizes correspond to these required curves:
- *
- * 192 = NIST P-192
- * 224 = NIST P-224
- * 256 = NIST P-256
- * 384 = NIST P-384
- * 521 = NIST P-521
- *
- * The parameters for these curves are available at: http://www.nsa.gov/ia/_files/nist-routines.pdf
- * in Chapter 4.
- */
-typedef struct {
- uint32_t field_size;
-} keymaster_ec_keygen_params_t;
-
-/**
- * Digest type.
- */
-typedef enum {
- DIGEST_NONE,
-} keymaster_digest_t;
-
-/**
- * Type of padding used for RSA operations.
- */
-typedef enum {
- PADDING_NONE,
-} keymaster_rsa_padding_t;
-
-
-typedef struct {
- keymaster_digest_t digest_type;
-} keymaster_dsa_sign_params_t;
-
-typedef struct {
- keymaster_digest_t digest_type;
-} keymaster_ec_sign_params_t;
-
-typedef struct {
- keymaster_digest_t digest_type;
- keymaster_rsa_padding_t padding_type;
-} keymaster_rsa_sign_params_t;
-
-/**
- * The parameters that can be set for a given keymaster implementation.
- */
-struct keymaster_device {
- /**
- * Common methods of the keymaster device. This *must* be the first member of
- * keymaster_device as users of this structure will cast a hw_device_t to
- * keymaster_device pointer in contexts where it's known the hw_device_t references a
- * keymaster_device.
- */
- struct hw_device_t common;
-
- /**
- * THIS IS DEPRECATED. Use the new "module_api_version" and "hal_api_version"
- * fields in the keymaster_module initialization instead.
- */
- uint32_t client_version;
-
- /**
- * See flags defined for keymaster_device::flags above.
- */
- uint32_t flags;
-
- void* context;
-
- /**
- * Generates a public and private key. The key-blob returned is opaque
- * and must subsequently provided for signing and verification.
- *
- * Returns: 0 on success or an error code less than 0.
- */
- int (*generate_keypair)(const struct keymaster_device* dev,
- const keymaster_keypair_t key_type, const void* key_params,
- uint8_t** key_blob, size_t* key_blob_length);
-
- /**
- * Imports a public and private key pair. The imported keys will be in
- * PKCS#8 format with DER encoding (Java standard). The key-blob
- * returned is opaque and will be subsequently provided for signing
- * and verification.
- *
- * Returns: 0 on success or an error code less than 0.
- */
- int (*import_keypair)(const struct keymaster_device* dev,
- const uint8_t* key, const size_t key_length,
- uint8_t** key_blob, size_t* key_blob_length);
-
- /**
- * Gets the public key part of a key pair. The public key must be in
- * X.509 format (Java standard) encoded byte array.
- *
- * Returns: 0 on success or an error code less than 0.
- * On error, x509_data should not be allocated.
- */
- int (*get_keypair_public)(const struct keymaster_device* dev,
- const uint8_t* key_blob, const size_t key_blob_length,
- uint8_t** x509_data, size_t* x509_data_length);
-
- /**
- * Deletes the key pair associated with the key blob.
- *
- * This function is optional and should be set to NULL if it is not
- * implemented.
- *
- * Returns 0 on success or an error code less than 0.
- */
- int (*delete_keypair)(const struct keymaster_device* dev,
- const uint8_t* key_blob, const size_t key_blob_length);
-
- /**
- * Deletes all keys in the hardware keystore. Used when keystore is
- * reset completely.
- *
- * This function is optional and should be set to NULL if it is not
- * implemented.
- *
- * Returns 0 on success or an error code less than 0.
- */
- int (*delete_all)(const struct keymaster_device* dev);
-
- /**
- * Signs data using a key-blob generated before. This can use either
- * an asymmetric key or a secret key.
- *
- * Returns: 0 on success or an error code less than 0.
- */
- int (*sign_data)(const struct keymaster_device* dev,
- const void* signing_params,
- const uint8_t* key_blob, const size_t key_blob_length,
- const uint8_t* data, const size_t data_length,
- uint8_t** signed_data, size_t* signed_data_length);
-
- /**
- * Verifies data signed with a key-blob. This can use either
- * an asymmetric key or a secret key.
- *
- * Returns: 0 on successful verification or an error code less than 0.
- */
- int (*verify_data)(const struct keymaster_device* dev,
- const void* signing_params,
- const uint8_t* key_blob, const size_t key_blob_length,
- const uint8_t* signed_data, const size_t signed_data_length,
- const uint8_t* signature, const size_t signature_length);
-};
-typedef struct keymaster_device keymaster_device_t;
-
-
-/* Convenience API for opening and closing keymaster devices */
-
-static inline int keymaster_open(const struct hw_module_t* module,
- keymaster_device_t** device)
-{
- int rc = module->methods->open(module, KEYSTORE_KEYMASTER,
- (struct hw_device_t**) device);
-
- return rc;
-}
-
-static inline int keymaster_close(keymaster_device_t* device)
-{
- return device->common.close(&device->common);
-}
-
-__END_DECLS
-
-#endif // ANDROID_HARDWARE_KEYMASTER_H
diff --git a/include/hardware/keymaster0.h b/include/hardware/keymaster0.h
new file mode 100644
index 0000000..f020e5b
--- /dev/null
+++ b/include/hardware/keymaster0.h
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2011 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 ANDROID_HARDWARE_KEYMASTER_0_H
+#define ANDROID_HARDWARE_KEYMASTER_0_H
+
+#include <hardware/keymaster_common.h>
+
+__BEGIN_DECLS
+
+/**
+ * Keymaster0 device definition.
+ */
+struct keymaster0_device {
+ /**
+ * Common methods of the keymaster device. This *must* be the first member of
+ * keymaster0_device as users of this structure will cast a hw_device_t to
+ * keymaster0_device pointer in contexts where it's known the hw_device_t references a
+ * keymaster0_device.
+ */
+ struct hw_device_t common;
+
+ /**
+ * THIS IS DEPRECATED. Use the new "module_api_version" and "hal_api_version"
+ * fields in the keymaster_module initialization instead.
+ */
+ uint32_t client_version;
+
+ /**
+ * See flags defined for keymaster0_device::flags in keymaster_common.h
+ */
+ uint32_t flags;
+
+ void* context;
+
+ /**
+ * Generates a public and private key. The key-blob returned is opaque
+ * and must subsequently provided for signing and verification.
+ *
+ * Returns: 0 on success or an error code less than 0.
+ */
+ int (*generate_keypair)(const struct keymaster0_device* dev,
+ const keymaster_keypair_t key_type, const void* key_params,
+ uint8_t** key_blob, size_t* key_blob_length);
+
+ /**
+ * Imports a public and private key pair. The imported keys will be in
+ * PKCS#8 format with DER encoding (Java standard). The key-blob
+ * returned is opaque and will be subsequently provided for signing
+ * and verification.
+ *
+ * Returns: 0 on success or an error code less than 0.
+ */
+ int (*import_keypair)(const struct keymaster0_device* dev,
+ const uint8_t* key, const size_t key_length,
+ uint8_t** key_blob, size_t* key_blob_length);
+
+ /**
+ * Gets the public key part of a key pair. The public key must be in
+ * X.509 format (Java standard) encoded byte array.
+ *
+ * Returns: 0 on success or an error code less than 0.
+ * On error, x509_data should not be allocated.
+ */
+ int (*get_keypair_public)(const struct keymaster0_device* dev,
+ const uint8_t* key_blob, const size_t key_blob_length,
+ uint8_t** x509_data, size_t* x509_data_length);
+
+ /**
+ * Deletes the key pair associated with the key blob.
+ *
+ * This function is optional and should be set to NULL if it is not
+ * implemented.
+ *
+ * Returns 0 on success or an error code less than 0.
+ */
+ int (*delete_keypair)(const struct keymaster0_device* dev,
+ const uint8_t* key_blob, const size_t key_blob_length);
+
+ /**
+ * Deletes all keys in the hardware keystore. Used when keystore is
+ * reset completely.
+ *
+ * This function is optional and should be set to NULL if it is not
+ * implemented.
+ *
+ * Returns 0 on success or an error code less than 0.
+ */
+ int (*delete_all)(const struct keymaster0_device* dev);
+
+ /**
+ * Signs data using a key-blob generated before. This can use either
+ * an asymmetric key or a secret key.
+ *
+ * Returns: 0 on success or an error code less than 0.
+ */
+ int (*sign_data)(const struct keymaster0_device* dev,
+ const void* signing_params,
+ const uint8_t* key_blob, const size_t key_blob_length,
+ const uint8_t* data, const size_t data_length,
+ uint8_t** signed_data, size_t* signed_data_length);
+
+ /**
+ * Verifies data signed with a key-blob. This can use either
+ * an asymmetric key or a secret key.
+ *
+ * Returns: 0 on successful verification or an error code less than 0.
+ */
+ int (*verify_data)(const struct keymaster0_device* dev,
+ const void* signing_params,
+ const uint8_t* key_blob, const size_t key_blob_length,
+ const uint8_t* signed_data, const size_t signed_data_length,
+ const uint8_t* signature, const size_t signature_length);
+};
+typedef struct keymaster0_device keymaster0_device_t;
+
+
+/* Convenience API for opening and closing keymaster devices */
+
+static inline int keymaster0_open(const struct hw_module_t* module,
+ keymaster0_device_t** device)
+{
+ int rc = module->methods->open(module, KEYSTORE_KEYMASTER,
+ (struct hw_device_t**) device);
+
+ return rc;
+}
+
+static inline int keymaster0_close(keymaster0_device_t* device)
+{
+ return device->common.close(&device->common);
+}
+
+__END_DECLS
+
+#endif // ANDROID_HARDWARE_KEYMASTER_0_H
diff --git a/include/hardware/keymaster1.h b/include/hardware/keymaster1.h
new file mode 100644
index 0000000..dae3b8e
--- /dev/null
+++ b/include/hardware/keymaster1.h
@@ -0,0 +1,617 @@
+/*
+ * Copyright (C) 2015 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 ANDROID_HARDWARE_KEYMASTER1_H
+#define ANDROID_HARDWARE_KEYMASTER1_H
+
+#include <hardware/keymaster_common.h>
+#include <hardware/keymaster_defs.h>
+
+__BEGIN_DECLS
+
+/**
+ * Keymaster1 device definition
+ */
+struct keymaster1_device {
+ /**
+ * Common methods of the keymaster device. This *must* be the first member of
+ * keymaster_device as users of this structure will cast a hw_device_t to
+ * keymaster_device pointer in contexts where it's known the hw_device_t references a
+ * keymaster_device.
+ */
+ struct hw_device_t common;
+
+ /**
+ * THIS IS DEPRECATED. Use the new "module_api_version" and "hal_api_version"
+ * fields in the keymaster_module initialization instead.
+ */
+ uint32_t client_version;
+
+ /**
+ * See flags defined for keymaster0_devices::flags in keymaster_common.h
+ */
+ uint32_t flags;
+
+ void* context;
+
+ /**
+ * \deprecated Generates a public and private key. The key-blob returned is opaque and must
+ * subsequently provided for signing and verification.
+ *
+ * Returns: 0 on success or an error code less than 0.
+ */
+ int (*generate_keypair)(const struct keymaster1_device* dev, const keymaster_keypair_t key_type,
+ const void* key_params, uint8_t** key_blob, size_t* key_blob_length);
+
+ /**
+ * \deprecated Imports a public and private key pair. The imported keys will be in PKCS#8 format
+ * with DER encoding (Java standard). The key-blob returned is opaque and will be subsequently
+ * provided for signing and verification.
+ *
+ * Returns: 0 on success or an error code less than 0.
+ */
+ int (*import_keypair)(const struct keymaster1_device* dev, const uint8_t* key,
+ const size_t key_length, uint8_t** key_blob, size_t* key_blob_length);
+
+ /**
+ * \deprecated Gets the public key part of a key pair. The public key must be in X.509 format
+ * (Java standard) encoded byte array.
+ *
+ * Returns: 0 on success or an error code less than 0. On error, x509_data
+ * should not be allocated.
+ */
+ int (*get_keypair_public)(const struct keymaster1_device* dev, const uint8_t* key_blob,
+ const size_t key_blob_length, uint8_t** x509_data,
+ size_t* x509_data_length);
+
+ /**
+ * \deprecated Deletes the key pair associated with the key blob.
+ *
+ * This function is optional and should be set to NULL if it is not
+ * implemented.
+ *
+ * Returns 0 on success or an error code less than 0.
+ */
+ int (*delete_keypair)(const struct keymaster1_device* dev, const uint8_t* key_blob,
+ const size_t key_blob_length);
+
+ /**
+ * \deprecated Deletes all keys in the hardware keystore. Used when keystore is reset
+ * completely.
+ *
+ * This function is optional and should be set to NULL if it is not
+ * implemented.
+ *
+ * Returns 0 on success or an error code less than 0.
+ */
+ int (*delete_all)(const struct keymaster1_device* dev);
+
+ /**
+ * \deprecated Signs data using a key-blob generated before. This can use either an asymmetric
+ * key or a secret key.
+ *
+ * Returns: 0 on success or an error code less than 0.
+ */
+ int (*sign_data)(const struct keymaster1_device* dev, const void* signing_params,
+ const uint8_t* key_blob, const size_t key_blob_length, const uint8_t* data,
+ const size_t data_length, uint8_t** signed_data, size_t* signed_data_length);
+
+ /**
+ * \deprecated Verifies data signed with a key-blob. This can use either an asymmetric key or a
+ * secret key.
+ *
+ * Returns: 0 on successful verification or an error code less than 0.
+ */
+ int (*verify_data)(const struct keymaster1_device* dev, const void* signing_params,
+ const uint8_t* key_blob, const size_t key_blob_length,
+ const uint8_t* signed_data, const size_t signed_data_length,
+ const uint8_t* signature, const size_t signature_length);
+
+ /**
+ * Gets algorithms supported.
+ *
+ * \param[in] dev The keymaster device structure.
+ *
+ * \param[out] algorithms Array of algorithms supported. The caller takes ownership of the
+ * array and must free() it.
+ *
+ * \param[out] algorithms_length Length of \p algorithms.
+ */
+ keymaster_error_t (*get_supported_algorithms)(const struct keymaster1_device* dev,
+ keymaster_algorithm_t** algorithms,
+ size_t* algorithms_length);
+
+ /**
+ * Gets the block modes supported for the specified algorithm.
+ *
+ * \param[in] dev The keymaster device structure.
+ *
+ * \param[in] algorithm The algorithm for which supported modes will be returned.
+ *
+ * \param[out] modes Array of modes supported. The caller takes ownership of the array and must
+ * free() it.
+ *
+ * \param[out] modes_length Length of \p modes.
+ */
+ keymaster_error_t (*get_supported_block_modes)(const struct keymaster1_device* dev,
+ keymaster_algorithm_t algorithm,
+ keymaster_purpose_t purpose,
+ keymaster_block_mode_t** modes,
+ size_t* modes_length);
+
+ /**
+ * Gets the padding modes supported for the specified algorithm. Caller assumes ownership of
+ * the allocated array.
+ *
+ * \param[in] dev The keymaster device structure.
+ *
+ * \param[in] algorithm The algorithm for which supported padding modes will be returned.
+ *
+ * \param[out] modes Array of padding modes supported. The caller takes ownership of the array
+ * and must free() it.
+ *
+ * \param[out] modes_length Length of \p modes.
+ */
+ keymaster_error_t (*get_supported_padding_modes)(const struct keymaster1_device* dev,
+ keymaster_algorithm_t algorithm,
+ keymaster_purpose_t purpose,
+ keymaster_padding_t** modes,
+ size_t* modes_length);
+
+ /**
+ * Gets the digests supported for the specified algorithm. Caller assumes ownership of the
+ * allocated array.
+ *
+ * \param[in] dev The keymaster device structure.
+ *
+ * \param[in] algorithm The algorithm for which supported digests will be returned.
+ *
+ * \param[out] digests Array of digests supported. The caller takes ownership of the array and
+ * must free() it.
+ *
+ * \param[out] digests_length Length of \p digests.
+ */
+ keymaster_error_t (*get_supported_digests)(const struct keymaster1_device* dev,
+ keymaster_algorithm_t algorithm,
+ keymaster_purpose_t purpose,
+ keymaster_digest_t** digests,
+ size_t* digests_length);
+
+ /**
+ * Gets the key import formats supported for keys of the specified algorithm. Caller assumes
+ * ownership of the allocated array.
+ *
+ * \param[in] dev The keymaster device structure.
+ *
+ * \param[in] algorithm The algorithm for which supported formats will be returned.
+ *
+ * \param[out] formats Array of formats supported. The caller takes ownership of the array and
+ * must free() it.
+ *
+ * \param[out] formats_length Length of \p formats.
+ */
+ keymaster_error_t (*get_supported_import_formats)(const struct keymaster1_device* dev,
+ keymaster_algorithm_t algorithm,
+ keymaster_key_format_t** formats,
+ size_t* formats_length);
+
+ /**
+ * Gets the key export formats supported for keys of the specified algorithm. Caller assumes
+ * ownership of the allocated array.
+ *
+ * \param[in] dev The keymaster device structure.
+ *
+ * \param[in] algorithm The algorithm for which supported formats will be returned.
+ *
+ * \param[out] formats Array of formats supported. The caller takes ownership of the array and
+ * must free() it.
+ *
+ * \param[out] formats_length Length of \p formats.
+ */
+ keymaster_error_t (*get_supported_export_formats)(const struct keymaster1_device* dev,
+ keymaster_algorithm_t algorithm,
+ keymaster_key_format_t** formats,
+ size_t* formats_length);
+
+ /**
+ * Adds entropy to the RNG used by keymaster. Entropy added through this method is guaranteed
+ * not to be the only source of entropy used, and the mixing function is required to be secure,
+ * in the sense that if the RNG is seeded (from any source) with any data the attacker cannot
+ * predict (or control), then the RNG output is indistinguishable from random. Thus, if the
+ * entropy from any source is good, the output will be good.
+ *
+ * \param[in] dev The keymaster device structure.
+ *
+ * \param[in] data Random data to be mixed in.
+ *
+ * \param[in] data_length Length of \p data.
+ */
+ keymaster_error_t (*add_rng_entropy)(const struct keymaster1_device* dev, const uint8_t* data,
+ size_t data_length);
+
+ /**
+ * Generates a key, or key pair, returning a key blob and/or a description of the key.
+ *
+ * Key generation parameters are defined as keymaster tag/value pairs, provided in \p params.
+ * See keymaster_tag_t for the full list. Some values that are always required for generation
+ * of useful keys are:
+ *
+ * - KM_TAG_ALGORITHM;
+ * - KM_TAG_PURPOSE;
+ * - KM_TAG_USER_ID or KM_TAG_ALL_USERS;
+ * - KM_TAG_USER_AUTH_ID or KM_TAG_NO_AUTH_REQUIRED;
+ * - KM_TAG_APPLICATION_ID or KM_TAG_ALL_APPLICATIONS; and
+ * - KM_TAG_ORIGINATION_EXPIRE_DATETIME
+ *
+ * KM_TAG_AUTH_TIMEOUT should generally be specified unless KM_TAG_NO_AUTH_REQUIRED is present,
+ * or the user will have to authenticate for every use.
+ *
+ * KM_TAG_BLOCK_MODE, KM_TAG_PADDING, KM_TAG_MAC_LENGTH and KM_TAG_DIGEST must be specified for
+ * algorithms that require them.
+ *
+ * The following tags will take default values if unspecified:
+ *
+ * - KM_TAG_KEY_SIZE defaults to a recommended key size for the specified algorithm.
+ *
+ * - KM_TAG_USAGE_EXPIRE_DATETIME defaults to the value of KM_TAG_ORIGINATION_EXPIRE_DATETIME.
+ *
+ * - KM_TAG_ACTIVE_DATETIME will default to the value of KM_TAG_CREATION_DATETIME
+ *
+ * - KM_TAG_ROOT_OF_TRUST will default to the current root of trust.
+ *
+ * - KM_TAG_{RSA|DSA|DH}_* will default to values appropriate for the specified key size.
+ *
+ * The following tags may not be specified; their values will be provided by the implementation.
+ *
+ * - KM_TAG_ORIGIN,
+ *
+ * - KM_TAG_ROLLBACK_RESISTANT,
+ *
+ * - KM_TAG_CREATION_DATETIME,
+ *
+ * \param[in] dev The keymaster device structure.
+ *
+ * \param[in] params Array of key generation parameters.
+ *
+ * \param[in] params_count Length of \p params.
+ *
+ * \param[out] key_blob returns the generated key. If \p key_blob is NULL, no key is generated,
+ * but the characteristics of the key that would be generated are returned. The caller assumes
+ * ownership key_blob->key_material and must free() it.
+ *
+ * \param[out] characteristics returns the characteristics of the key that was, or would be,
+ * generated, if non-NULL. The caller assumes ownership, and the object must be freed with
+ * keymaster_free_characteristics(). Note that KM_TAG_ROOT_OF_TRUST, KM_TAG_APPLICATION_ID and
+ * KM_TAG_APPLICATION_DATA are never returned.
+ */
+ keymaster_error_t (*generate_key)(const struct keymaster1_device* dev,
+ const keymaster_key_param_t* params, size_t params_count,
+ keymaster_key_blob_t* key_blob,
+ keymaster_key_characteristics_t** characteristics);
+
+ /**
+ * Returns the characteristics of the specified key, or NULL if the key_blob is invalid
+ * (implementations must fully validate the integrity of the key). client_id and app_data must
+ * be the ID and data provided when the key was generated or imported. Those values are not
+ * included in the returned characteristics. Caller assumes ownership of the allocated
+ * characteristics object, which must be deallocated with keymaster_free_characteristics().
+ *
+ * Note that KM_TAG_ROOT_OF_TRUST, KM_TAG_APPLICATION_ID and KM_TAG_APPLICATION_DATA are never
+ * returned.
+ *
+ * \param[in] dev The keymaster device structure.
+ *
+ * \param[in] key_blob The key to retreive characteristics from.
+ *
+ * \param[in] client_id The client ID data, or NULL if none associated.
+ *
+ * \param[in] app_id The app data, or NULL if none associated.
+ *
+ * \param[out] characteristics The key characteristics.
+ */
+ keymaster_error_t (*get_key_characteristics)(const struct keymaster1_device* dev,
+ const keymaster_key_blob_t* key_blob,
+ const keymaster_blob_t* client_id,
+ const keymaster_blob_t* app_data,
+ keymaster_key_characteristics_t** characteristics);
+
+ /**
+ * Change a key's authorizations.
+ *
+ * Update the authorizations associated with key_blob to the list specified in new_params, which
+ * must contain the complete set of authorizations desired (hw_enforced and sw_enforced). Tags
+ * will be added, removed and/or updated only if the appropriate KM_TAG_RESCOPING_ADD and
+ * KM_TAG_RESCOPING_DEL tags exist in the key's authorizations, otherwise
+ * KM_ERROR_INVALID_RESCOPING will be returned and no changes will be made.
+ *
+ * \param[in] dev The keymaster device structure.
+ *
+ * \param[in] new_params The new authorization list to be associated with the key.
+ *
+ * \param[in] new_params_count The number of entries in \p new_params.
+ *
+ * \param[in] key_blob The key to update.
+ *
+ * \param[in] client_id The client ID associated with the key, or NULL if none is associated.
+ *
+ * \param[in] app_data The application data associated with the key, or NULL if none is
+ * associated.
+ *
+ * \param[out] rescoped_key_blob The key blob with the updated authorizations, if successful.
+ * The caller assumes ownership of rescoped_key_blob->key_material and must free() it.
+ *
+ * \param[out] characteristics If not null will contain the new key authorizations, divided into
+ * hw_enforced and sw_enforced lists. The caller takes ownership and must call
+ * keymaster_free_characteristics() to free.
+ */
+ keymaster_error_t (*rescope)(const struct keymaster1_device* dev,
+ const keymaster_key_param_t* new_params, size_t new_params_count,
+ const keymaster_key_blob_t* key_blob,
+ const keymaster_blob_t* client_id,
+ const keymaster_blob_t* app_data,
+ keymaster_key_blob_t* rescoped_key_blob,
+ keymaster_key_characteristics_t** characteristics);
+
+ /**
+ * Imports a key, or key pair, returning a key blob and/or a description of the key.
+ *
+ * Most key import parameters are defined as keymaster tag/value pairs, provided in "params".
+ * See keymaster_tag_t for the full list. Some values that are always required for import of
+ * useful keys are:
+ *
+ * - KM_TAG_PURPOSE;
+ *
+ * - KM_TAG_USER_ID
+ *
+ * - KM_TAG_USER_AUTH_ID;
+ *
+ * - KM_TAG_APPLICATION_ID or KM_TAG_ALL_APPLICATIONS;
+ *
+ * - KM_TAG_PRIVKEY_EXPIRE_DATETIME.
+ *
+ * KM_TAG_AUTH_TIMEOUT should generally be specified. If unspecified, the user will have to
+ * authenticate for every use, unless KM_TAG_USER_AUTH_ID is set to
+ * KM_NO_AUTHENTICATION_REQUIRED.
+ *
+ * The following tags will take default values if unspecified:
+ *
+ * - KM_TAG_PUBKEY_EXPIRE_DATETIME will default to the value for KM_TAG_PRIVKEY_EXPIRE_DATETIME.
+ *
+ * - KM_TAG_ACTIVE_DATETIME will default to the value of KM_TAG_CREATION_DATETIME
+ *
+ * - KM_TAG_ROOT_OF_TRUST will default to the current root of trust.
+ *
+ * The following tags may not be specified; their values will be provided by the implementation.
+ *
+ * - KM_TAG_ORIGIN,
+ *
+ * - KM_TAG_ROLLBACK_RESISTANT,
+ *
+ * - KM_TAG_CREATION_DATETIME,
+ *
+ * \param[in] dev The keymaster device structure.
+ *
+ * \param[in] params Parameters defining the imported key.
+ *
+ * \param[in] params_count The number of entries in \p params.
+ *
+ * \param[in] key_format specifies the format of the key data in key_data.
+ *
+ * \param[out] key_blob Used to return the opaque key blob. Must be non-NULL. The caller
+ * assumes ownership of the contained key_material.
+ *
+ * \param[out] characteristics Used to return the characteristics of the imported key. May be
+ * NULL, in which case no characteristics will be returned. If non-NULL, the caller assumes
+ * ownership and must deallocate with keymaster_free_characteristics().
+ */
+ keymaster_error_t (*import_key)(const struct keymaster1_device* dev,
+ const keymaster_key_param_t* params, size_t params_count,
+ keymaster_key_format_t key_format, const uint8_t* key_data,
+ size_t key_data_length, keymaster_key_blob_t* key_blob,
+ keymaster_key_characteristics_t** characteristics);
+
+ /**
+ * Exports a public key, returning a byte array in the specified format.
+ *
+ * \param[in] dev The keymaster device structure.
+ *
+ * \param[in] export_format The format to be used for exporting the key.
+ *
+ * \param[in] key_to_export The key to export.
+ *
+ * \param[out] export_data The exported key material. The caller assumes ownership.
+ *
+ * \param[out] export_data_length The length of \p export_data.
+ */
+ keymaster_error_t (*export_key)(const struct keymaster1_device* dev,
+ keymaster_key_format_t export_format,
+ const keymaster_key_blob_t* key_to_export,
+ const keymaster_blob_t* client_id,
+ const keymaster_blob_t* app_data, uint8_t** export_data,
+ size_t* export_data_length);
+
+ /**
+ * Deletes the key, or key pair, associated with the key blob. After calling this function it
+ * will be impossible to use the key for any other operations (though rescoped versions may
+ * exist, and if so will be usable). May be applied to keys from foreign roots of trust (keys
+ * not usable under the current root of trust).
+ *
+ * This function is optional and should be set to NULL if it is not implemented.
+ *
+ * \param[in] dev The keymaster device structure.
+ *
+ * \param[in] key The key to be deleted.
+ */
+ keymaster_error_t (*delete_key)(const struct keymaster1_device* dev,
+ const keymaster_key_blob_t* key);
+
+ /**
+ * Deletes all keys in the hardware keystore. Used when keystore is reset completely. After
+ * calling this function it will be impossible to use any previously generated or imported key
+ * blobs for any operations.
+ *
+ * This function is optional and should be set to NULL if it is not implemented.
+ *
+ * \param[in] dev The keymaster device structure.
+ *
+ * Returns 0 on success or an error code less than 0.
+ */
+ int (*delete_all_keys)(const struct keymaster1_device* dev);
+
+ /**
+ * Begins a cryptographic operation using the specified key. If all is well, begin() will
+ * return KM_ERROR_OK and create an operation handle which must be passed to subsequent calls to
+ * update(), finish() or abort().
+ *
+ * It is critical that each call to begin() be paired with a subsequent call to finish() or
+ * abort(), to allow the keymaster implementation to clean up any internal operation state.
+ * Failure to do this will leak internal state space or other internal resources and will
+ * eventually cause begin() to return KM_ERROR_TOO_MANY_OPERATIONS when it runs out of space for
+ * operations.
+ *
+ * \param[in] dev The keymaster device structure.
+ *
+ * \param[in] purpose The purpose of the operation, one of KM_PURPOSE_ENCRYPT,
+ * KM_PURPOSE_DECRYPT, KM_PURPOSE_SIGN or KM_PURPOSE_VERIFY. Note that for AEAD modes,
+ * encryption and decryption imply signing and verification, respectively.
+ *
+ * \param[in] key The key to be used for the operation. \p key must have a purpose compatible
+ * with \p purpose and all of its usage requirements must be satisfied, or begin() will return
+ * an appropriate error code.
+ *
+ * \param[in] params Additional parameters for the operation. This is typically used to provide
+ * client ID information, with tags KM_TAG_APPLICATION_ID and KM_TAG_APPLICATION_DATA. If the
+ * client information associated with the key is not provided, begin() will fail and return
+ * KM_ERROR_INVALID_KEY_BLOB. For operations that require a nonce or IV, this must contain a
+ * tag KM_TAG_NONCE. For AEAD operations KM_TAG_CHUNK_SIZE is specified here.
+ *
+ * \param[in] params_count The number of entries in \p params.
+ *
+ * \param[out] out_params Array of output parameters. The caller takes ownership of the output
+ * parametes array and must free it. out_params may be set to NULL if no output parameters are
+ * expected. If NULL, and output paramaters are generated, begin() will return
+ * KM_ERROR_OUTPUT_PARAMETER_NULL.
+ *
+ * \param[out] out_params_count The length of out_params.
+ *
+ * \param[out] operation_handle The newly-created operation handle which must be passed to
+ * update(), finish() or abort().
+ */
+ keymaster_error_t (*begin)(const struct keymaster1_device* dev, keymaster_purpose_t purpose,
+ const keymaster_key_blob_t* key, const keymaster_key_param_t* params,
+ size_t params_count, keymaster_key_param_t** out_params,
+ size_t* out_params_count,
+ keymaster_operation_handle_t* operation_handle);
+
+ /**
+ * Provides data to, and possibly receives output from, an ongoing cryptographic operation begun
+ * with begin().
+ *
+ * If operation_handle is invalid, update() will return KM_ERROR_INVALID_OPERATION_HANDLE.
+ *
+ * Not all of the data provided in the data buffer may be consumed. update() will return the
+ * amount consumed in *data_consumed. The caller should provide the unconsumed data in a
+ * subsequent call.
+ *
+ * \param[in] dev The keymaster device structure.
+ *
+ * \param[in] operation_handle The operation handle returned by begin().
+ *
+ * \param[in] params Additional parameters for the operation. For AEAD modes, this is used to
+ * specify KM_TAG_ADDITIONAL_DATA.
+ *
+ * \param[in] params_count Length of \p params.
+ *
+ * \param[in] input Data to be processed, per the parameters established in the call to begin().
+ * Note that update() may or may not consume all of the data provided. See \p data_consumed.
+ *
+ * \param[in] input_length Length of \p input.
+ *
+ * \param[out] input_consumed Amount of data that was consumed by update(). If this is less
+ * than the amount provided, the caller should provide the remainder in a subsequent call to
+ * update().
+ *
+ * \param[out] output The output data, if any. The caller assumes ownership of the allocated
+ * buffer. If output is NULL then NO input data is consumed and no output is produced, but
+ * *output_length is set to an estimate of the size that would have been produced by this
+ * update() and a subsequent finish().
+ *
+ * \param[out] output_length The length of the output buffer.
+ *
+ * Note that update() may not provide any output, in which case *output_length will be zero, and
+ * *output may be either NULL or zero-length (so the caller should always free() it).
+ */
+ keymaster_error_t (*update)(const struct keymaster1_device* dev,
+ keymaster_operation_handle_t operation_handle,
+ const keymaster_key_param_t* params, size_t params_count,
+ const uint8_t* input, size_t input_length, size_t* input_consumed,
+ uint8_t** output, size_t* output_length);
+
+ /**
+ * Finalizes a cryptographic operation begun with begin() and invalidates operation_handle
+ * (except in the insufficient buffer case, detailed below).
+ *
+ * \param[in] dev The keymaster device structure.
+ *
+ * \param[in] operation_handle The operation handle returned by begin(). This handle will be
+ * invalidated.
+ *
+ * \param[in] params Additional parameters for the operation. For AEAD modes, this is used to
+ * specify KM_TAG_ADDITIONAL_DATA.
+ *
+ * \param[in] params_count Length of \p params.
+ *
+ * \param[in] signature The signature to be verified if the purpose specified in the begin()
+ * call was KM_PURPOSE_VERIFY.
+ *
+ * \param[in] signature_length The length of \p signature.
+ *
+ * \param[out] output The output data, if any. The caller assumes ownership of the allocated
+ * buffer.
+ *
+ * \param[out] output_length The length of the output buffer.
+ *
+ * If the operation being finished is a signature verification or an AEAD-mode decryption and
+ * verification fails then finish() will return KM_ERROR_VERIFICATION_FAILED.
+ */
+ keymaster_error_t (*finish)(const struct keymaster1_device* dev,
+ keymaster_operation_handle_t operation_handle,
+ const keymaster_key_param_t* params, size_t params_count,
+ const uint8_t* signature, size_t signature_length, uint8_t** output,
+ size_t* output_length);
+
+ /**
+ * Aborts a cryptographic operation begun with begin(), freeing all internal resources and
+ * invalidating operation_handle.
+ */
+ keymaster_error_t (*abort)(const struct keymaster1_device* dev,
+ keymaster_operation_handle_t operation_handle);
+};
+typedef struct keymaster1_device keymaster1_device_t;
+
+/* Convenience API for opening and closing keymaster devices */
+
+static inline int keymaster1_open(const struct hw_module_t* module, keymaster1_device_t** device) {
+ return module->methods->open(module, KEYSTORE_KEYMASTER, (struct hw_device_t**)device);
+}
+
+static inline int keymaster1_close(keymaster1_device_t* device) {
+ return device->common.close(&device->common);
+}
+
+__END_DECLS
+
+#endif // ANDROID_HARDWARE_KEYMASTER1_H
diff --git a/include/hardware/keymaster_common.h b/include/hardware/keymaster_common.h
new file mode 100644
index 0000000..772d7e4
--- /dev/null
+++ b/include/hardware/keymaster_common.h
@@ -0,0 +1,185 @@
+/*
+ * Copyright (C) 2015 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 ANDROID_HARDWARE_KEYMASTER_COMMON_H
+#define ANDROID_HARDWARE_KEYMASTER_COMMON_H
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <hardware/hardware.h>
+
+__BEGIN_DECLS
+
+/**
+ * The id of this module
+ */
+#define KEYSTORE_HARDWARE_MODULE_ID "keystore"
+
+#define KEYSTORE_KEYMASTER "keymaster"
+
+
+/**
+ * Settings for "module_api_version" and "hal_api_version"
+ * fields in the keymaster_module initialization.
+ */
+
+/**
+ * Keymaster 0.X module version provide the same APIs, but later versions add more options
+ * for algorithms and flags.
+ */
+#define KEYMASTER_MODULE_API_VERSION_0_2 HARDWARE_MODULE_API_VERSION(0, 2)
+#define KEYMASTER_DEVICE_API_VERSION_0_2 HARDWARE_DEVICE_API_VERSION(0, 2)
+
+#define KEYMASTER_MODULE_API_VERSION_0_3 HARDWARE_MODULE_API_VERSION(0, 3)
+#define KEYMASTER_DEVICE_API_VERSION_0_3 HARDWARE_DEVICE_API_VERSION(0, 3)
+
+/**
+ * Keymaster 1.0 module version provides a completely different API, incompatible with 0.X.
+ */
+#define KEYMASTER_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
+#define KEYMASTER_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
+
+struct keystore_module {
+ /**
+ * Common methods of the keystore module. This *must* be the first member of keystore_module as
+ * users of this structure will cast a hw_module_t to keystore_module pointer in contexts where
+ * it's known the hw_module_t references a keystore_module.
+ */
+ hw_module_t common;
+
+ /* There are no keystore module methods other than the common ones. */
+};
+
+/**
+ * Flags for keymaster0_device::flags
+ */
+enum {
+ /*
+ * Indicates this keymaster implementation does not have hardware that
+ * keeps private keys out of user space.
+ *
+ * This should not be implemented on anything other than the default
+ * implementation.
+ */
+ KEYMASTER_SOFTWARE_ONLY = 1 << 0,
+
+ /*
+ * This indicates that the key blobs returned via all the primitives
+ * are sufficient to operate on their own without the trusted OS
+ * querying userspace to retrieve some other data. Key blobs of
+ * this type are normally returned encrypted with a
+ * Key Encryption Key (KEK).
+ *
+ * This is currently used by "vold" to know whether the whole disk
+ * encryption secret can be unwrapped without having some external
+ * service started up beforehand since the "/data" partition will
+ * be unavailable at that point.
+ */
+ KEYMASTER_BLOBS_ARE_STANDALONE = 1 << 1,
+
+ /*
+ * Indicates that the keymaster module supports DSA keys.
+ */
+ KEYMASTER_SUPPORTS_DSA = 1 << 2,
+
+ /*
+ * Indicates that the keymaster module supports EC keys.
+ */
+ KEYMASTER_SUPPORTS_EC = 1 << 3,
+};
+
+/**
+ * Asymmetric key pair types.
+ */
+typedef enum {
+ TYPE_RSA = 1,
+ TYPE_DSA = 2,
+ TYPE_EC = 3,
+} keymaster_keypair_t;
+
+/**
+ * Parameters needed to generate an RSA key.
+ */
+typedef struct {
+ uint32_t modulus_size;
+ uint64_t public_exponent;
+} keymaster_rsa_keygen_params_t;
+
+/**
+ * Parameters needed to generate a DSA key.
+ */
+typedef struct {
+ uint32_t key_size;
+ uint32_t generator_len;
+ uint32_t prime_p_len;
+ uint32_t prime_q_len;
+ const uint8_t* generator;
+ const uint8_t* prime_p;
+ const uint8_t* prime_q;
+} keymaster_dsa_keygen_params_t;
+
+/**
+ * Parameters needed to generate an EC key.
+ *
+ * Field size is the only parameter in version 2. The sizes correspond to these required curves:
+ *
+ * 192 = NIST P-192
+ * 224 = NIST P-224
+ * 256 = NIST P-256
+ * 384 = NIST P-384
+ * 521 = NIST P-521
+ *
+ * The parameters for these curves are available at: http://www.nsa.gov/ia/_files/nist-routines.pdf
+ * in Chapter 4.
+ */
+typedef struct {
+ uint32_t field_size;
+} keymaster_ec_keygen_params_t;
+
+
+/**
+ * Digest type.
+ */
+typedef enum {
+ DIGEST_NONE,
+} keymaster_digest_algorithm_t;
+
+/**
+ * Type of padding used for RSA operations.
+ */
+typedef enum {
+ PADDING_NONE,
+} keymaster_rsa_padding_t;
+
+
+typedef struct {
+ keymaster_digest_algorithm_t digest_type;
+} keymaster_dsa_sign_params_t;
+
+typedef struct {
+ keymaster_digest_algorithm_t digest_type;
+} keymaster_ec_sign_params_t;
+
+typedef struct {
+ keymaster_digest_algorithm_t digest_type;
+ keymaster_rsa_padding_t padding_type;
+} keymaster_rsa_sign_params_t;
+
+__END_DECLS
+
+#endif // ANDROID_HARDWARE_KEYMASTER_COMMON_H
diff --git a/include/hardware/keymaster_defs.h b/include/hardware/keymaster_defs.h
new file mode 100644
index 0000000..dd2c764
--- /dev/null
+++ b/include/hardware/keymaster_defs.h
@@ -0,0 +1,560 @@
+/*
+ * Copyright (C) 2014 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 ANDROID_HARDWARE_KEYMASTER_DEFS_H
+#define ANDROID_HARDWARE_KEYMASTER_DEFS_H
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifndef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+/**
+ * Authorization tags each have an associated type. This enumeration facilitates tagging each with
+ * a type, by using the high four bits (of an implied 32-bit unsigned enum value) to specify up to
+ * 16 data types. These values are ORed with tag IDs to generate the final tag ID values.
+ */
+typedef enum {
+ KM_INVALID = 0 << 28, /* Invalid type, used to designate a tag as uninitialized */
+ KM_ENUM = 1 << 28,
+ KM_ENUM_REP = 2 << 28, /* Repeatable enumeration value. */
+ KM_INT = 3 << 28,
+ KM_INT_REP = 4 << 28, /* Repeatable integer value */
+ KM_LONG = 5 << 28,
+ KM_DATE = 6 << 28,
+ KM_BOOL = 7 << 28,
+ KM_BIGNUM = 8 << 28,
+ KM_BYTES = 9 << 28,
+ KM_LONG_REP = 10 << 28, /* Repeatable long value */
+} keymaster_tag_type_t;
+
+typedef enum {
+ KM_TAG_INVALID = KM_INVALID | 0,
+
+ /*
+ * Tags that must be semantically enforced by hardware and software implementations.
+ */
+
+ /* Crypto parameters */
+ KM_TAG_PURPOSE = KM_ENUM_REP | 1, /* keymaster_purpose_t. */
+ KM_TAG_ALGORITHM = KM_ENUM | 2, /* keymaster_algorithm_t. */
+ KM_TAG_KEY_SIZE = KM_INT | 3, /* Key size in bits. */
+ KM_TAG_BLOCK_MODE = KM_ENUM | 4, /* keymaster_block_mode_t. */
+ KM_TAG_DIGEST = KM_ENUM | 5, /* keymaster_digest_t. */
+ KM_TAG_MAC_LENGTH = KM_INT | 6, /* MAC or AEAD authentication tag length in bits. */
+ KM_TAG_PADDING = KM_ENUM | 7, /* keymaster_padding_t. */
+ KM_TAG_RETURN_UNAUTHED = KM_BOOL | 8, /* Allow AEAD decryption to return plaintext before it has
+ been authenticated. WARNING: Not recommended. */
+ KM_TAG_CALLER_NONCE = KM_BOOL | 9, /* Allow caller to specify nonce or IV. */
+
+ /* Other hardware-enforced. */
+ KM_TAG_RESCOPING_ADD = KM_ENUM_REP | 101, /* Tags authorized for addition via rescoping. */
+ KM_TAG_RESCOPING_DEL = KM_ENUM_REP | 102, /* Tags authorized for removal via rescoping. */
+ KM_TAG_BLOB_USAGE_REQUIREMENTS = KM_ENUM | 705, /* keymaster_key_blob_usage_requirements_t */
+
+ /* Algorithm-specific. */
+ KM_TAG_RSA_PUBLIC_EXPONENT = KM_LONG | 200, /* Defaults to 2^16+1 */
+ KM_TAG_DSA_GENERATOR = KM_BIGNUM | 201,
+ KM_TAG_DSA_P = KM_BIGNUM | 202,
+ KM_TAG_DSA_Q = KM_BIGNUM | 203,
+ /* Note there are no EC-specific params. Field size is defined by KM_TAG_KEY_SIZE, and the
+ curve is chosen from NIST recommendations for field size */
+
+ /*
+ * Tags that should be semantically enforced by hardware if possible and will otherwise be
+ * enforced by software (keystore).
+ */
+
+ /* Key validity period */
+ KM_TAG_ACTIVE_DATETIME = KM_DATE | 400, /* Start of validity */
+ KM_TAG_ORIGINATION_EXPIRE_DATETIME = KM_DATE | 401, /* Date when new "messages" should no
+ longer be created. */
+ KM_TAG_USAGE_EXPIRE_DATETIME = KM_DATE | 402, /* Date when existing "messages" should no
+ longer be trusted. */
+ KM_TAG_MIN_SECONDS_BETWEEN_OPS = KM_INT | 403, /* Minimum elapsed time between
+ cryptographic operations with the key. */
+ KM_TAG_MAX_USES_PER_BOOT = KM_INT | 404, /* Number of times the key can be used per
+ boot. */
+
+ /* User authentication */
+ KM_TAG_ALL_USERS = KM_BOOL | 500, /* If key is usable by all users. */
+ KM_TAG_USER_ID = KM_INT | 501, /* ID of authorized user. Disallowed if
+ KM_TAG_ALL_USERS is present. */
+ KM_TAG_USER_SECURE_ID = KM_LONG_REP | 502, /* Secure ID of authorized user or authenticator(s).
+ Disallowed if KM_TAG_ALL_USERS or
+ KM_TAG_NO_AUTH_REQUIRED is present. */
+ KM_TAG_NO_AUTH_REQUIRED = KM_BOOL | 503, /* If key is usable without authentication. */
+ KM_TAG_USER_AUTH_TYPE = KM_ENUM | 504, /* Bitmask of authenticator types allowed when
+ * KM_TAG_USER_SECURE_ID contains a secure user ID,
+ * rather than a secure authenticator ID. Defined in
+ * hw_authenticator_type_t in hw_auth_token.h. */
+ KM_TAG_AUTH_TIMEOUT = KM_INT | 505, /* Required freshness of user authentication for
+ private/secret key operations, in seconds.
+ Public key operations require no authentication.
+ If absent, authentication is required for every
+ use. Authentication state is lost when the
+ device is powered off. */
+
+ /* Application access control */
+ KM_TAG_ALL_APPLICATIONS = KM_BOOL | 600, /* If key is usable by all applications. */
+ KM_TAG_APPLICATION_ID = KM_BYTES | 601, /* ID of authorized application. Disallowed if
+ KM_TAG_ALL_APPLICATIONS is present. */
+
+ /*
+ * Semantically unenforceable tags, either because they have no specific meaning or because
+ * they're informational only.
+ */
+ KM_TAG_APPLICATION_DATA = KM_BYTES | 700, /* Data provided by authorized application. */
+ KM_TAG_CREATION_DATETIME = KM_DATE | 701, /* Key creation time */
+ KM_TAG_ORIGIN = KM_ENUM | 702, /* keymaster_key_origin_t. */
+ KM_TAG_ROLLBACK_RESISTANT = KM_BOOL | 703, /* Whether key is rollback-resistant. */
+ KM_TAG_ROOT_OF_TRUST = KM_BYTES | 704, /* Root of trust ID. Empty array means usable by all
+ roots. */
+
+ /* Tags used only to provide data to or receive data from operations */
+ KM_TAG_ASSOCIATED_DATA = KM_BYTES | 1000, /* Used to provide associated data for AEAD modes. */
+ KM_TAG_NONCE = KM_BYTES | 1001, /* Nonce or Initialization Vector */
+ KM_TAG_CHUNK_LENGTH = KM_INT | 1002, /* AEAD mode chunk size, in bytes. 0 means no limit,
+ which requires KM_TAG_RETURN_UNAUTHED. */
+ KM_TAG_AUTH_TOKEN = KM_BYTES | 1003, /* Authentication token that proves secure user
+ authentication has been performed. Structure
+ defined in hw_auth_token_t in hw_auth_token.h. */
+} keymaster_tag_t;
+
+/**
+ * Algorithms that may be provided by keymaster implementations. Those that must be provided by all
+ * implementations are tagged as "required".
+ */
+typedef enum {
+ /* Asymmetric algorithms. */
+ KM_ALGORITHM_RSA = 1, /* required */
+ KM_ALGORITHM_DSA = 2,
+ KM_ALGORITHM_ECDSA = 3, /* required */
+ KM_ALGORITHM_ECIES = 4,
+ /* FIPS Approved Ciphers */
+ KM_ALGORITHM_AES = 32, /* required */
+ KM_ALGORITHM_3DES = 33,
+ KM_ALGORITHM_SKIPJACK = 34,
+ /* AES Finalists */
+ KM_ALGORITHM_MARS = 48,
+ KM_ALGORITHM_RC6 = 49,
+ KM_ALGORITHM_SERPENT = 50,
+ KM_ALGORITHM_TWOFISH = 51,
+ /* Other common block ciphers */
+ KM_ALGORITHM_IDEA = 52,
+ KM_ALGORITHM_RC5 = 53,
+ KM_ALGORITHM_CAST5 = 54,
+ KM_ALGORITHM_BLOWFISH = 55,
+ /* Common stream ciphers */
+ KM_ALGORITHM_RC4 = 64,
+ KM_ALGORITHM_CHACHA20 = 65,
+ /* MAC algorithms */
+ KM_ALGORITHM_HMAC = 128, /* required */
+} keymaster_algorithm_t;
+
+/**
+ * Symmetric block cipher modes that may be provided by keymaster implementations. Those that must
+ * be provided by all implementations are tagged as "required". This type is new in 0_4.
+ *
+ * KM_MODE_FIRST_UNAUTHENTICATED, KM_MODE_FIRST_AUTHENTICATED and KM_MODE_FIRST_MAC are not modes,
+ * but markers used to separate the available modes into classes.
+ */
+typedef enum {
+ /* Unauthenticated modes, usable only for encryption/decryption and not generally recommended
+ * except for compatibility with existing other protocols. */
+ KM_MODE_FIRST_UNAUTHENTICATED = 1,
+ KM_MODE_ECB = KM_MODE_FIRST_UNAUTHENTICATED, /* required */
+ KM_MODE_CBC = 2, /* required */
+ KM_MODE_CBC_CTS = 3, /* recommended */
+ KM_MODE_CTR = 4, /* recommended */
+ KM_MODE_OFB = 5,
+ KM_MODE_CFB = 6,
+ KM_MODE_XTS = 7, /* Note: requires double-length keys */
+ /* Authenticated modes, usable for encryption/decryption and signing/verification. Recommended
+ * over unauthenticated modes for all purposes. One of KM_MODE_GCM and KM_MODE_OCB is
+ * required. */
+ KM_MODE_FIRST_AUTHENTICATED = 32,
+ KM_MODE_GCM = KM_MODE_FIRST_AUTHENTICATED,
+ KM_MODE_OCB = 33,
+ KM_MODE_CCM = 34,
+ /* MAC modes -- only for signing/verification */
+ KM_MODE_FIRST_MAC = 128,
+ KM_MODE_CMAC = KM_MODE_FIRST_MAC,
+ KM_MODE_POLY1305 = 129,
+} keymaster_block_mode_t;
+
+/**
+ * Padding modes that may be applied to plaintext for encryption operations. This list includes
+ * padding modes for both symmetric and asymmetric algorithms. Note that implementations should not
+ * provide all possible combinations of algorithm and padding, only the
+ * cryptographically-appropriate pairs.
+ */
+typedef enum {
+ KM_PAD_NONE = 1, /* required, deprecated */
+ KM_PAD_RSA_OAEP = 2, /* required */
+ KM_PAD_RSA_PSS = 3, /* required */
+ KM_PAD_RSA_PKCS1_1_5_ENCRYPT = 4,
+ KM_PAD_RSA_PKCS1_1_5_SIGN = 5,
+ KM_PAD_ANSI_X923 = 32,
+ KM_PAD_ISO_10126 = 33,
+ KM_PAD_ZERO = 64, /* required */
+ KM_PAD_PKCS7 = 65, /* required */
+ KM_PAD_ISO_7816_4 = 66,
+} keymaster_padding_t;
+
+/**
+ * Digests that may be provided by keymaster implementations. Those that must be provided by all
+ * implementations are tagged as "required". Those that have been added since version 0_2 of the
+ * API are tagged as "new".
+ */
+typedef enum {
+ KM_DIGEST_NONE = 0, /* new, required */
+ KM_DIGEST_MD5 = 1, /* new, for compatibility with old protocols only */
+ KM_DIGEST_SHA1 = 2, /* new */
+ KM_DIGEST_SHA_2_224 = 3, /* new */
+ KM_DIGEST_SHA_2_256 = 4, /* new, required */
+ KM_DIGEST_SHA_2_384 = 5, /* new, recommended */
+ KM_DIGEST_SHA_2_512 = 6, /* new, recommended */
+ KM_DIGEST_SHA_3_256 = 7, /* new */
+ KM_DIGEST_SHA_3_384 = 8, /* new */
+ KM_DIGEST_SHA_3_512 = 9, /* new */
+} keymaster_digest_t;
+
+/**
+ * The origin of a key (or pair), i.e. where it was generated. Origin and can be used together to
+ * determine whether a key may have existed outside of secure hardware. This type is new in 0_4.
+ */
+typedef enum {
+ KM_ORIGIN_HARDWARE = 0, /* Generated in secure hardware */
+ KM_ORIGIN_SOFTWARE = 1, /* Generated in non-secure software */
+ KM_ORIGIN_IMPORTED = 2, /* Imported, origin unknown */
+} keymaster_key_origin_t;
+
+/**
+ * Usability requirements of key blobs. This defines what system functionality must be available
+ * for the key to function. For example, key "blobs" which are actually handles referencing
+ * encrypted key material stored in the file system cannot be used until the file system is
+ * available, and should have BLOB_REQUIRES_FILE_SYSTEM. Other requirements entries will be added
+ * as needed for implementations. This type is new in 0_4.
+ */
+typedef enum {
+ KM_BLOB_STANDALONE = 0,
+ KM_BLOB_REQUIRES_FILE_SYSTEM = 1,
+} keymaster_key_blob_usage_requirements_t;
+
+/**
+ * Possible purposes of a key (or pair). This type is new in 0_4.
+ */
+typedef enum {
+ KM_PURPOSE_ENCRYPT = 0,
+ KM_PURPOSE_DECRYPT = 1,
+ KM_PURPOSE_SIGN = 2,
+ KM_PURPOSE_VERIFY = 3,
+} keymaster_purpose_t;
+
+typedef struct {
+ const uint8_t* data;
+ size_t data_length;
+} keymaster_blob_t;
+
+typedef struct {
+ keymaster_tag_t tag;
+ union {
+ uint32_t enumerated; /* KM_ENUM and KM_ENUM_REP */
+ bool boolean; /* KM_BOOL */
+ uint32_t integer; /* KM_INT and KM_INT_REP */
+ uint64_t long_integer; /* KM_LONG */
+ uint64_t date_time; /* KM_DATE */
+ keymaster_blob_t blob; /* KM_BIGNUM and KM_BYTES*/
+ };
+} keymaster_key_param_t;
+
+typedef struct {
+ keymaster_key_param_t* params; /* may be NULL if length == 0 */
+ size_t length;
+} keymaster_key_param_set_t;
+
+/**
+ * Parameters that define a key's characteristics, including authorized modes of usage and access
+ * control restrictions. The parameters are divided into two categories, those that are enforced by
+ * secure hardware, and those that are not. For a software-only keymaster implementation the
+ * enforced array must NULL. Hardware implementations must enforce everything in the enforced
+ * array.
+ */
+typedef struct {
+ keymaster_key_param_set_t hw_enforced;
+ keymaster_key_param_set_t sw_enforced;
+} keymaster_key_characteristics_t;
+
+typedef struct {
+ const uint8_t* key_material;
+ size_t key_material_size;
+} keymaster_key_blob_t;
+
+/**
+ * Formats for key import and export. At present, only asymmetric key import/export is supported.
+ * In the future this list will expand greatly to accommodate asymmetric key import/export.
+ */
+typedef enum {
+ KM_KEY_FORMAT_X509 = 0, /* for public key export, required */
+ KM_KEY_FORMAT_PKCS8 = 1, /* for asymmetric key pair import, required */
+ KM_KEY_FORMAT_PKCS12 = 2, /* for asymmetric key pair import, not required */
+ KM_KEY_FORMAT_RAW = 3, /* for symmetric key import, required */
+} keymaster_key_format_t;
+
+/**
+ * The keymaster operation API consists of begin, update, finish and abort. This is the type of the
+ * handle used to tie the sequence of calls together. A 64-bit value is used because it's important
+ * that handles not be predictable. Implementations must use strong random numbers for handle
+ * values.
+ */
+typedef uint64_t keymaster_operation_handle_t;
+
+typedef enum {
+ KM_ERROR_OK = 0,
+ KM_ERROR_ROOT_OF_TRUST_ALREADY_SET = -1,
+ KM_ERROR_UNSUPPORTED_PURPOSE = -2,
+ KM_ERROR_INCOMPATIBLE_PURPOSE = -3,
+ KM_ERROR_UNSUPPORTED_ALGORITHM = -4,
+ KM_ERROR_INCOMPATIBLE_ALGORITHM = -5,
+ KM_ERROR_UNSUPPORTED_KEY_SIZE = -6,
+ KM_ERROR_UNSUPPORTED_BLOCK_MODE = -7,
+ KM_ERROR_INCOMPATIBLE_BLOCK_MODE = -8,
+ KM_ERROR_UNSUPPORTED_MAC_LENGTH = -9,
+ KM_ERROR_UNSUPPORTED_PADDING_MODE = -10,
+ KM_ERROR_INCOMPATIBLE_PADDING_MODE = -11,
+ KM_ERROR_UNSUPPORTED_DIGEST = -12,
+ KM_ERROR_INCOMPATIBLE_DIGEST = -13,
+ KM_ERROR_INVALID_EXPIRATION_TIME = -14,
+ KM_ERROR_INVALID_USER_ID = -15,
+ KM_ERROR_INVALID_AUTHORIZATION_TIMEOUT = -16,
+ KM_ERROR_UNSUPPORTED_KEY_FORMAT = -17,
+ KM_ERROR_INCOMPATIBLE_KEY_FORMAT = -18,
+ KM_ERROR_UNSUPPORTED_KEY_ENCRYPTION_ALGORITHM = -19, /* For PKCS8 & PKCS12 */
+ KM_ERROR_UNSUPPORTED_KEY_VERIFICATION_ALGORITHM = -20, /* For PKCS8 & PKCS12 */
+ KM_ERROR_INVALID_INPUT_LENGTH = -21,
+ KM_ERROR_KEY_EXPORT_OPTIONS_INVALID = -22,
+ KM_ERROR_DELEGATION_NOT_ALLOWED = -23,
+ KM_ERROR_KEY_NOT_YET_VALID = -24,
+ KM_ERROR_KEY_EXPIRED = -25,
+ KM_ERROR_KEY_USER_NOT_AUTHENTICATED = -26,
+ KM_ERROR_OUTPUT_PARAMETER_NULL = -27,
+ KM_ERROR_INVALID_OPERATION_HANDLE = -28,
+ KM_ERROR_INSUFFICIENT_BUFFER_SPACE = -29,
+ KM_ERROR_VERIFICATION_FAILED = -30,
+ KM_ERROR_TOO_MANY_OPERATIONS = -31,
+ KM_ERROR_UNEXPECTED_NULL_POINTER = -32,
+ KM_ERROR_INVALID_KEY_BLOB = -33,
+ KM_ERROR_IMPORTED_KEY_NOT_ENCRYPTED = -34,
+ KM_ERROR_IMPORTED_KEY_DECRYPTION_FAILED = -35,
+ KM_ERROR_IMPORTED_KEY_NOT_SIGNED = -36,
+ KM_ERROR_IMPORTED_KEY_VERIFICATION_FAILED = -37,
+ KM_ERROR_INVALID_ARGUMENT = -38,
+ KM_ERROR_UNSUPPORTED_TAG = -39,
+ KM_ERROR_INVALID_TAG = -40,
+ KM_ERROR_MEMORY_ALLOCATION_FAILED = -41,
+ KM_ERROR_INVALID_RESCOPING = -42,
+ KM_ERROR_INVALID_DSA_PARAMS = -43,
+ KM_ERROR_IMPORT_PARAMETER_MISMATCH = -44,
+ KM_ERROR_SECURE_HW_ACCESS_DENIED = -45,
+ KM_ERROR_OPERATION_CANCELLED = -46,
+ KM_ERROR_CONCURRENT_ACCESS_CONFLICT = -47,
+ KM_ERROR_SECURE_HW_BUSY = -48,
+ KM_ERROR_SECURE_HW_COMMUNICATION_FAILED = -49,
+ KM_ERROR_UNSUPPORTED_EC_FIELD = -50,
+ KM_ERROR_MISSING_NONCE = -51,
+ KM_ERROR_INVALID_NONCE = -52,
+ KM_ERROR_UNSUPPORTED_CHUNK_LENGTH = -53,
+ KM_ERROR_RESCOPABLE_KEY_NOT_USABLE = -54,
+
+ KM_ERROR_UNIMPLEMENTED = -100,
+ KM_ERROR_VERSION_MISMATCH = -101,
+
+ /* Additional error codes may be added by implementations, but implementers should coordinate
+ * with Google to avoid code collision. */
+ KM_ERROR_UNKNOWN_ERROR = -1000,
+} keymaster_error_t;
+
+/* Convenience functions for manipulating keymaster tag types */
+
+static inline keymaster_tag_type_t keymaster_tag_get_type(keymaster_tag_t tag) {
+ return (keymaster_tag_type_t)(tag & (0xF << 28));
+}
+
+static inline uint32_t keymaster_tag_mask_type(keymaster_tag_t tag) {
+ return tag & 0x0FFFFFFF;
+}
+
+static inline bool keymaster_tag_type_repeatable(keymaster_tag_type_t type) {
+ switch (type) {
+ case KM_INT_REP:
+ case KM_ENUM_REP:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static inline bool keymaster_tag_repeatable(keymaster_tag_t tag) {
+ return keymaster_tag_type_repeatable(keymaster_tag_get_type(tag));
+}
+
+/* Convenience functions for manipulating keymaster_key_param_t structs */
+
+inline keymaster_key_param_t keymaster_param_enum(keymaster_tag_t tag, uint32_t value) {
+ // assert(keymaster_tag_get_type(tag) == KM_ENUM || keymaster_tag_get_type(tag) == KM_ENUM_REP);
+ keymaster_key_param_t param;
+ memset(¶m, 0, sizeof(param));
+ param.tag = tag;
+ param.enumerated = value;
+ return param;
+}
+
+inline keymaster_key_param_t keymaster_param_int(keymaster_tag_t tag, uint32_t value) {
+ // assert(keymaster_tag_get_type(tag) == KM_INT || keymaster_tag_get_type(tag) == KM_INT_REP);
+ keymaster_key_param_t param;
+ memset(¶m, 0, sizeof(param));
+ param.tag = tag;
+ param.integer = value;
+ return param;
+}
+
+inline keymaster_key_param_t keymaster_param_long(keymaster_tag_t tag, uint64_t value) {
+ // assert(keymaster_tag_get_type(tag) == KM_LONG);
+ keymaster_key_param_t param;
+ memset(¶m, 0, sizeof(param));
+ param.tag = tag;
+ param.long_integer = value;
+ return param;
+}
+
+inline keymaster_key_param_t keymaster_param_blob(keymaster_tag_t tag, const uint8_t* bytes,
+ size_t bytes_len) {
+ // assert(keymaster_tag_get_type(tag) == KM_BYTES || keymaster_tag_get_type(tag) == KM_BIGNUM);
+ keymaster_key_param_t param;
+ memset(¶m, 0, sizeof(param));
+ param.tag = tag;
+ param.blob.data = (uint8_t*)bytes;
+ param.blob.data_length = bytes_len;
+ return param;
+}
+
+inline keymaster_key_param_t keymaster_param_bool(keymaster_tag_t tag) {
+ // assert(keymaster_tag_get_type(tag) == KM_BOOL);
+ keymaster_key_param_t param;
+ memset(¶m, 0, sizeof(param));
+ param.tag = tag;
+ param.boolean = true;
+ return param;
+}
+
+inline keymaster_key_param_t keymaster_param_date(keymaster_tag_t tag, uint64_t value) {
+ // assert(keymaster_tag_get_type(tag) == KM_DATE);
+ keymaster_key_param_t param;
+ memset(¶m, 0, sizeof(param));
+ param.tag = tag;
+ param.date_time = value;
+ return param;
+}
+
+#define KEYMASTER_SIMPLE_COMPARE(a, b) (a < b) ? -1 : ((a > b) ? 1 : 0)
+inline int keymaster_param_compare(const keymaster_key_param_t* a, const keymaster_key_param_t* b) {
+ int retval = KEYMASTER_SIMPLE_COMPARE(a->tag, b->tag);
+ if (retval != 0)
+ return retval;
+
+ switch (keymaster_tag_get_type(a->tag)) {
+ case KM_INVALID:
+ case KM_BOOL:
+ return 0;
+ case KM_ENUM:
+ case KM_ENUM_REP:
+ return KEYMASTER_SIMPLE_COMPARE(a->enumerated, b->enumerated);
+ case KM_INT:
+ case KM_INT_REP:
+ return KEYMASTER_SIMPLE_COMPARE(a->integer, b->integer);
+ case KM_LONG:
+ case KM_LONG_REP:
+ return KEYMASTER_SIMPLE_COMPARE(a->long_integer, b->long_integer);
+ case KM_DATE:
+ return KEYMASTER_SIMPLE_COMPARE(a->date_time, b->date_time);
+ case KM_BIGNUM:
+ case KM_BYTES:
+ // Handle the empty cases.
+ if (a->blob.data_length != 0 && b->blob.data_length == 0)
+ return -1;
+ if (a->blob.data_length == 0 && b->blob.data_length == 0)
+ return 0;
+ if (a->blob.data_length == 0 && b->blob.data_length > 0)
+ return 1;
+
+ retval = memcmp(a->blob.data, b->blob.data, a->blob.data_length < b->blob.data_length
+ ? a->blob.data_length
+ : b->blob.data_length);
+ if (retval != 0)
+ return retval;
+ else if (a->blob.data_length != b->blob.data_length) {
+ // Equal up to the common length; longer one is larger.
+ if (a->blob.data_length < b->blob.data_length)
+ return -1;
+ if (a->blob.data_length > b->blob.data_length)
+ return 1;
+ };
+ }
+
+ return 0;
+}
+#undef KEYMASTER_SIMPLE_COMPARE
+
+inline void keymaster_free_param_values(keymaster_key_param_t* param, size_t param_count) {
+ while (param_count-- > 0) {
+ switch (keymaster_tag_get_type(param->tag)) {
+ case KM_BIGNUM:
+ case KM_BYTES:
+ free((void*)param->blob.data);
+ param->blob.data = NULL;
+ break;
+ default:
+ // NOP
+ break;
+ }
+ ++param;
+ }
+}
+
+inline void keymaster_free_param_set(keymaster_key_param_set_t* set) {
+ if (set) {
+ keymaster_free_param_values(set->params, set->length);
+ free(set->params);
+ set->params = NULL;
+ }
+}
+
+inline void keymaster_free_characteristics(keymaster_key_characteristics_t* characteristics) {
+ if (characteristics) {
+ keymaster_free_param_set(&characteristics->hw_enforced);
+ keymaster_free_param_set(&characteristics->sw_enforced);
+ }
+}
+
+#ifndef __cplusplus
+} // extern "C"
+#endif // __cplusplus
+
+#endif // ANDROID_HARDWARE_KEYMASTER_DEFS_H
diff --git a/include/hardware/qemu_pipe.h b/include/hardware/qemu_pipe.h
index 814b20b..53aec97 100644
--- a/include/hardware/qemu_pipe.h
+++ b/include/hardware/qemu_pipe.h
@@ -23,6 +23,7 @@
#include <pthread.h> /* for pthread_once() */
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include <errno.h>
#ifndef D
diff --git a/include/hardware/radio.h b/include/hardware/radio.h
new file mode 100644
index 0000000..145deb5
--- /dev/null
+++ b/include/hardware/radio.h
@@ -0,0 +1,298 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+#include <system/radio.h>
+#include <hardware/hardware.h>
+
+#ifndef ANDROID_RADIO_HAL_H
+#define ANDROID_RADIO_HAL_H
+
+
+__BEGIN_DECLS
+
+/**
+ * The id of this module
+ */
+#define RADIO_HARDWARE_MODULE_ID "radio"
+
+/**
+ * Name of the audio devices to open
+ */
+#define RADIO_HARDWARE_DEVICE "radio_hw_device"
+
+#define RADIO_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
+#define RADIO_MODULE_API_VERSION_CURRENT RADIO_MODULE_API_VERSION_1_0
+
+
+#define RADIO_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
+#define RADIO_DEVICE_API_VERSION_CURRENT RADIO_DEVICE_API_VERSION_1_0
+
+/**
+ * List of known radio HAL modules. This is the base name of the radio HAL
+ * library composed of the "radio." prefix, one of the base names below and
+ * a suffix specific to the device.
+ * E.g: radio.fm.default.so
+ */
+
+#define RADIO_HARDWARE_MODULE_ID_FM "fm" /* corresponds to RADIO_CLASS_AM_FM */
+#define RADIO_HARDWARE_MODULE_ID_SAT "sat" /* corresponds to RADIO_CLASS_SAT */
+#define RADIO_HARDWARE_MODULE_ID_DT "dt" /* corresponds to RADIO_CLASS_DT */
+
+
+/**
+ * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
+ * and the fields of this data structure must begin with hw_module_t
+ * followed by module specific information.
+ */
+struct radio_module {
+ struct hw_module_t common;
+};
+
+/*
+ * Callback function called by the HAL when one of the following occurs:
+ * - event RADIO_EVENT_HW_FAILURE: radio chip of driver failure requiring
+ * closing and reopening of the tuner interface.
+ * - event RADIO_EVENT_CONFIG: new configuration applied in response to open_tuner(),
+ * or set_configuration(). The event status is 0 (no error) if the configuration has been applied,
+ * -EINVAL is not or -ETIMEDOUT in case of time out.
+ * - event RADIO_EVENT_TUNED: tune locked on new station/frequency following scan(),
+ * step(), tune() or auto AF switching. The event status is 0 (no error) if in tune,
+ * -EINVAL is not tuned and data in radio_program_info is not valid or -ETIMEDOUT if scan()
+ * timed out.
+ * - event RADIO_EVENT_TA: at the beginning and end of traffic announcement if current
+ * configuration enables TA.
+ * - event RADIO_EVENT_AF: after automatic switching to alternate frequency if current
+ * configuration enables AF switching.
+ * - event RADIO_EVENT_ANTENNA: when the antenna is connected or disconnected.
+ * - event RADIO_EVENT_METADATA: when new meta data are received from the tuned station.
+ * The callback MUST NOT be called synchronously while executing a HAL function but from
+ * a separate thread.
+ */
+typedef void (*radio_callback_t)(radio_hal_event_t *event, void *cookie);
+
+/* control interface for a radio tuner */
+struct radio_tuner {
+ /*
+ * Apply current radio band configuration (band, range, channel spacing ...).
+ *
+ * arguments:
+ * - config: the band configuration to apply
+ *
+ * returns:
+ * 0 if configuration could be applied
+ * -EINVAL if configuration requested is invalid
+ *
+ * Automatically cancels pending scan, step or tune.
+ *
+ * Callback function with event RADIO_EVENT_CONFIG MUST be called once the
+ * configuration is applied or a failure occurs or after a time out.
+ */
+ int (*set_configuration)(const struct radio_tuner *tuner,
+ const radio_hal_band_config_t *config);
+
+ /*
+ * Retrieve current radio band configuration.
+ *
+ * arguments:
+ * - config: where to return the band configuration
+ *
+ * returns:
+ * 0 if valid configuration is returned
+ * -EINVAL if invalid arguments are passed
+ */
+ int (*get_configuration)(const struct radio_tuner *tuner,
+ radio_hal_band_config_t *config);
+
+ /*
+ * Start scanning up to next valid station.
+ * Must be called when a valid configuration has been applied.
+ *
+ * arguments:
+ * - direction: RADIO_DIRECTION_UP or RADIO_DIRECTION_DOWN
+ * - skip_sub_channel: valid for HD radio or digital radios only: ignore sub channels
+ * (e.g SPS for HD radio).
+ *
+ * returns:
+ * 0 if scan successfully started
+ * -ENOSYS if called out of sequence
+ * -ENODEV if another error occurs
+ *
+ * Automatically cancels pending scan, step or tune.
+ *
+ * Callback function with event RADIO_EVENT_TUNED MUST be called once
+ * locked on a station or after a time out or full frequency scan if
+ * no station found. The event status should indicate if a valid station
+ * is tuned or not.
+ */
+ int (*scan)(const struct radio_tuner *tuner,
+ radio_direction_t direction, bool skip_sub_channel);
+
+ /*
+ * Move one channel spacing up or down.
+ * Must be called when a valid configuration has been applied.
+ *
+ * arguments:
+ * - direction: RADIO_DIRECTION_UP or RADIO_DIRECTION_DOWN
+ * - skip_sub_channel: valid for HD radio or digital radios only: ignore sub channels
+ * (e.g SPS for HD radio).
+ *
+ * returns:
+ * 0 if step successfully started
+ * -ENOSYS if called out of sequence
+ * -ENODEV if another error occurs
+ *
+ * Automatically cancels pending scan, step or tune.
+ *
+ * Callback function with event RADIO_EVENT_TUNED MUST be called once
+ * step completed or after a time out. The event status should indicate
+ * if a valid station is tuned or not.
+ */
+ int (*step)(const struct radio_tuner *tuner,
+ radio_direction_t direction, bool skip_sub_channel);
+
+ /*
+ * Tune to specified frequency.
+ * Must be called when a valid configuration has been applied.
+ *
+ * arguments:
+ * - channel: channel to tune to. A frequency in kHz for AM/FM/HD Radio bands.
+ * - sub_channel: valid for HD radio or digital radios only: (e.g SPS number for HD radio).
+ *
+ * returns:
+ * 0 if tune successfully started
+ * -ENOSYS if called out of sequence
+ * -EINVAL if invalid arguments are passed
+ * -ENODEV if another error occurs
+ *
+ * Automatically cancels pending scan, step or tune.
+ *
+ * Callback function with event RADIO_EVENT_TUNED MUST be called once
+ * tuned or after a time out. The event status should indicate
+ * if a valid station is tuned or not.
+ */
+ int (*tune)(const struct radio_tuner *tuner,
+ unsigned int channel, unsigned int sub_channel);
+
+ /*
+ * Cancel a scan, step or tune operation.
+ * Must be called while a scan, step or tune operation is pending
+ * (callback not yet sent).
+ *
+ * returns:
+ * 0 if successful
+ * -ENOSYS if called out of sequence
+ * -ENODEV if another error occurs
+ *
+ * The callback is not sent.
+ */
+ int (*cancel)(const struct radio_tuner *tuner);
+
+ /*
+ * Retrieve current station information.
+ *
+ * arguments:
+ * - info: where to return the program info.
+ * If info->metadata is NULL. no meta data should be returned.
+ * If meta data must be returned, they should be added to or cloned to
+ * info->metadata, not passed from a newly created meta data buffer.
+ *
+ * returns:
+ * 0 if tuned and information available
+ * -EINVAL if invalid arguments are passed
+ * -ENODEV if another error occurs
+ */
+ int (*get_program_information)(const struct radio_tuner *tuner,
+ radio_program_info_t *info);
+};
+
+struct radio_hw_device {
+ struct hw_device_t common;
+
+ /*
+ * Retrieve implementation properties.
+ *
+ * arguments:
+ * - properties: where to return the module properties
+ *
+ * returns:
+ * 0 if no error
+ * -EINVAL if invalid arguments are passed
+ */
+ int (*get_properties)(const struct radio_hw_device *dev,
+ radio_hal_properties_t *properties);
+
+ /*
+ * Open a tuner interface for the requested configuration.
+ * If no other tuner is opened, this will activate the radio module.
+ *
+ * arguments:
+ * - config: the band configuration to apply
+ * - audio: this tuner will be used for live radio listening and should be connected to
+ * the radio audio source.
+ * - callback: the event callback
+ * - cookie: the cookie to pass when calling the callback
+ * - tuner: where to return the tuner interface
+ *
+ * returns:
+ * 0 if HW was powered up and configuration could be applied
+ * -EINVAL if configuration requested is invalid
+ * -ENOSYS if called out of sequence
+ *
+ * Callback function with event RADIO_EVENT_CONFIG MUST be called once the
+ * configuration is applied or a failure occurs or after a time out.
+ */
+ int (*open_tuner)(const struct radio_hw_device *dev,
+ const radio_hal_band_config_t *config,
+ bool audio,
+ radio_callback_t callback,
+ void *cookie,
+ const struct radio_tuner **tuner);
+
+ /*
+ * Close a tuner interface.
+ * If the last tuner is closed, the radio module is deactivated.
+ *
+ * arguments:
+ * - tuner: the tuner interface to close
+ *
+ * returns:
+ * 0 if powered down successfully.
+ * -EINVAL if an invalid argument is passed
+ * -ENOSYS if called out of sequence
+ */
+ int (*close_tuner)(const struct radio_hw_device *dev, const struct radio_tuner *tuner);
+
+};
+
+typedef struct radio_hw_device radio_hw_device_t;
+
+/** convenience API for opening and closing a supported device */
+
+static inline int radio_hw_device_open(const struct hw_module_t* module,
+ struct radio_hw_device** device)
+{
+ return module->methods->open(module, RADIO_HARDWARE_DEVICE,
+ (struct hw_device_t**)device);
+}
+
+static inline int radio_hw_device_close(const struct radio_hw_device* device)
+{
+ return device->common.close((struct hw_device_t *)&device->common);
+}
+
+__END_DECLS
+
+#endif // ANDROID_RADIO_HAL_H
diff --git a/include/hardware/sensors.h b/include/hardware/sensors.h
index f0773d5..e917c0a 100644
--- a/include/hardware/sensors.h
+++ b/include/hardware/sensors.h
@@ -602,6 +602,22 @@
#define SENSOR_TYPE_PICK_UP_GESTURE (25)
#define SENSOR_STRING_TYPE_PICK_UP_GESTURE "android.sensor.pick_up_gesture"
+/*
+ * SENSOR_TYPE_WRIST_TILT_GESTURE
+ * trigger-mode: special
+ * wake-up sensor: yes
+ *
+ * A sensor of this type triggers an event each time a tilt of the wrist-worn
+ * device is detected.
+ *
+ * This sensor must be low power, as it is likely to be activated 24/7.
+ * The only allowed value to return is 1.0.
+ *
+ * Implement only the wake-up version of this sensor.
+ */
+#define SENSOR_TYPE_WRIST_TILT_GESTURE (26)
+#define SENSOR_STRING_TYPE_WRIST_TILT_GESTURE "android.sensor.wrist_tilt_gesture"
+
/**
* Values returned by the accelerometer in various locations in the universe.
* all values are in SI units (m/s^2)
diff --git a/modules/Android.mk b/modules/Android.mk
index 13a0b5b..9f7e5f0 100644
--- a/modules/Android.mk
+++ b/modules/Android.mk
@@ -1,4 +1,4 @@
hardware_modules := gralloc hwcomposer audio nfc nfc-nci local_time \
power usbaudio audio_remote_submix camera usbcamera consumerir sensors vibrator \
- tv_input fingerprint
+ tv_input fingerprint input
include $(call all-named-subdir-makefiles,$(hardware_modules))
diff --git a/modules/audio/Android.mk b/modules/audio/Android.mk
index a31c85f..ef4b8f5 100644
--- a/modules/audio/Android.mk
+++ b/modules/audio/Android.mk
@@ -31,6 +31,23 @@
include $(BUILD_SHARED_LIBRARY)
+# The stub audio HAL module, identical to the default audio hal, but with
+# different name to be loaded concurrently with other audio HALs if necessary.
+# This can also be used as skeleton for new implementations
+#
+# The format of the name is audio.<type>.<hardware/etc>.so where the only
+# required type is 'primary'. Other possibilites are 'a2dp', 'usb', etc.
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := audio.stub.default
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_SRC_FILES := audio_hw.c
+LOCAL_SHARED_LIBRARIES := liblog libcutils
+LOCAL_MODULE_TAGS := optional
+LOCAL_CFLAGS := -Wno-unused-parameter
+
+include $(BUILD_SHARED_LIBRARY)
+
# The stub audio policy HAL module that can be used as a skeleton for
# new implementations.
include $(CLEAR_VARS)
diff --git a/modules/audio/audio_hw.c b/modules/audio/audio_hw.c
index 18c0e59..a1a322f 100644
--- a/modules/audio/audio_hw.c
+++ b/modules/audio/audio_hw.c
@@ -18,6 +18,7 @@
//#define LOG_NDEBUG 0
#include <errno.h>
+#include <malloc.h>
#include <pthread.h>
#include <stdint.h>
#include <sys/time.h>
@@ -47,65 +48,78 @@
static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
{
- return 0;
+ ALOGV("out_set_sample_rate: %d", 0);
+ return -ENOSYS;
}
static size_t out_get_buffer_size(const struct audio_stream *stream)
{
+ ALOGV("out_get_buffer_size: %d", 4096);
return 4096;
}
static audio_channel_mask_t out_get_channels(const struct audio_stream *stream)
{
+ ALOGV("out_get_channels");
return AUDIO_CHANNEL_OUT_STEREO;
}
static audio_format_t out_get_format(const struct audio_stream *stream)
{
+ ALOGV("out_get_format");
return AUDIO_FORMAT_PCM_16_BIT;
}
static int out_set_format(struct audio_stream *stream, audio_format_t format)
{
- return 0;
+ ALOGV("out_set_format: %d",format);
+ return -ENOSYS;
}
static int out_standby(struct audio_stream *stream)
{
+ ALOGV("out_standby");
+
return 0;
}
static int out_dump(const struct audio_stream *stream, int fd)
{
+ ALOGV("out_dump");
return 0;
}
static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
{
+ ALOGV("out_set_parameters");
return 0;
}
static char * out_get_parameters(const struct audio_stream *stream, const char *keys)
{
+ ALOGV("out_get_parameters");
return strdup("");
}
static uint32_t out_get_latency(const struct audio_stream_out *stream)
{
+ ALOGV("out_get_latency");
return 0;
}
static int out_set_volume(struct audio_stream_out *stream, float left,
float right)
{
+ ALOGV("out_set_volume: Left:%f Right:%f", left, right);
return 0;
}
static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
size_t bytes)
{
+ ALOGV("out_write: bytes: %d", bytes);
/* XXX: fake timing for audio output */
- usleep(bytes * 1000000 / audio_stream_out_frame_size(stream) /
+ usleep((int64_t)bytes * 1000000 / audio_stream_out_frame_size(stream) /
out_get_sample_rate(&stream->common));
return bytes;
}
@@ -113,43 +127,53 @@
static int out_get_render_position(const struct audio_stream_out *stream,
uint32_t *dsp_frames)
{
+ *dsp_frames = 0;
+ ALOGV("out_get_render_position: dsp_frames: %p", dsp_frames);
return -EINVAL;
}
static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
{
+ ALOGV("out_add_audio_effect: %p", effect);
return 0;
}
static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
{
+ ALOGV("out_remove_audio_effect: %p", effect);
return 0;
}
static int out_get_next_write_timestamp(const struct audio_stream_out *stream,
int64_t *timestamp)
{
+ *timestamp = 0;
+ ALOGV("out_get_next_write_timestamp: %ld", (long int)(*timestamp));
return -EINVAL;
}
/** audio_stream_in implementation **/
static uint32_t in_get_sample_rate(const struct audio_stream *stream)
{
+ ALOGV("in_get_sample_rate");
return 8000;
}
static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
{
- return 0;
+ ALOGV("in_set_sample_rate: %d", rate);
+ return -ENOSYS;
}
static size_t in_get_buffer_size(const struct audio_stream *stream)
{
+ ALOGV("in_get_buffer_size: %d", 320);
return 320;
}
static audio_channel_mask_t in_get_channels(const struct audio_stream *stream)
{
+ ALOGV("in_get_channels: %d", AUDIO_CHANNEL_IN_MONO);
return AUDIO_CHANNEL_IN_MONO;
}
@@ -160,7 +184,7 @@
static int in_set_format(struct audio_stream *stream, audio_format_t format)
{
- return 0;
+ return -ENOSYS;
}
static int in_standby(struct audio_stream *stream)
@@ -192,9 +216,11 @@
static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
size_t bytes)
{
+ ALOGV("in_read: bytes %d", bytes);
/* XXX: fake timing for audio input */
- usleep(bytes * 1000000 / audio_stream_in_frame_size(stream) /
+ usleep((int64_t)bytes * 1000000 / audio_stream_in_frame_size(stream) /
in_get_sample_rate(&stream->common));
+ memset(buffer, 0, bytes);
return bytes;
}
@@ -221,6 +247,8 @@
struct audio_stream_out **stream_out,
const char *address __unused)
{
+ ALOGV("adev_open_output_stream...");
+
struct stub_audio_device *ladev = (struct stub_audio_device *)dev;
struct stub_stream_out *out;
int ret;
@@ -259,68 +287,81 @@
static void adev_close_output_stream(struct audio_hw_device *dev,
struct audio_stream_out *stream)
{
+ ALOGV("adev_close_output_stream...");
free(stream);
}
static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
{
+ ALOGV("adev_set_parameters");
return -ENOSYS;
}
static char * adev_get_parameters(const struct audio_hw_device *dev,
const char *keys)
{
- return NULL;
+ ALOGV("adev_get_parameters");
+ return strdup("");
}
static int adev_init_check(const struct audio_hw_device *dev)
{
+ ALOGV("adev_init_check");
return 0;
}
static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
{
+ ALOGV("adev_set_voice_volume: %f", volume);
return -ENOSYS;
}
static int adev_set_master_volume(struct audio_hw_device *dev, float volume)
{
+ ALOGV("adev_set_master_volume: %f", volume);
return -ENOSYS;
}
static int adev_get_master_volume(struct audio_hw_device *dev, float *volume)
{
+ ALOGV("adev_get_master_volume: %f", *volume);
return -ENOSYS;
}
static int adev_set_master_mute(struct audio_hw_device *dev, bool muted)
{
+ ALOGV("adev_set_master_mute: %d", muted);
return -ENOSYS;
}
static int adev_get_master_mute(struct audio_hw_device *dev, bool *muted)
{
+ ALOGV("adev_get_master_mute: %d", *muted);
return -ENOSYS;
}
static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode)
{
+ ALOGV("adev_set_mode: %d", mode);
return 0;
}
static int adev_set_mic_mute(struct audio_hw_device *dev, bool state)
{
+ ALOGV("adev_set_mic_mute: %d",state);
return -ENOSYS;
}
static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state)
{
+ ALOGV("adev_get_mic_mute");
return -ENOSYS;
}
static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
const struct audio_config *config)
{
+ ALOGV("adev_get_input_buffer_size: %d", 320);
return 320;
}
@@ -333,6 +374,8 @@
const char *address __unused,
audio_source_t source __unused)
{
+ ALOGV("adev_open_input_stream...");
+
struct stub_audio_device *ladev = (struct stub_audio_device *)dev;
struct stub_stream_in *in;
int ret;
@@ -369,16 +412,19 @@
static void adev_close_input_stream(struct audio_hw_device *dev,
struct audio_stream_in *in)
{
+ ALOGV("adev_close_input_stream...");
return;
}
static int adev_dump(const audio_hw_device_t *device, int fd)
{
+ ALOGV("adev_dump");
return 0;
}
static int adev_close(hw_device_t *device)
{
+ ALOGV("adev_close");
free(device);
return 0;
}
@@ -386,6 +432,8 @@
static int adev_open(const hw_module_t* module, const char* name,
hw_device_t** device)
{
+ ALOGV("adev_open: %s", name);
+
struct stub_audio_device *adev;
int ret;
diff --git a/modules/camera/Stream.cpp b/modules/camera/Stream.cpp
index 9cf971e..e0099b6 100644
--- a/modules/camera/Stream.cpp
+++ b/modules/camera/Stream.cpp
@@ -225,15 +225,15 @@
dprintf(fd, "Stream ID: %d (%p)\n", mId, mStream);
dprintf(fd, "Stream Type: %s (%d)\n", typeToString(mType), mType);
- dprintf(fd, "Width: %"PRIu32" Height: %"PRIu32"\n", mWidth, mHeight);
+ dprintf(fd, "Width: %" PRIu32 " Height: %" PRIu32 "\n", mWidth, mHeight);
dprintf(fd, "Stream Format: %s (%d)", formatToString(mFormat), mFormat);
// ToDo: prettyprint usage mask flags
- dprintf(fd, "Gralloc Usage Mask: %#"PRIx32"\n", mUsage);
- dprintf(fd, "Max Buffer Count: %"PRIu32"\n", mMaxBuffers);
+ dprintf(fd, "Gralloc Usage Mask: %#" PRIx32 "\n", mUsage);
+ dprintf(fd, "Max Buffer Count: %" PRIu32 "\n", mMaxBuffers);
dprintf(fd, "Buffers Registered: %s\n", mRegistered ? "true" : "false");
- dprintf(fd, "Number of Buffers: %"PRIu32"\n", mNumBuffers);
+ dprintf(fd, "Number of Buffers: %" PRIu32 "\n", mNumBuffers);
for (uint32_t i = 0; i < mNumBuffers; i++) {
- dprintf(fd, "Buffer %"PRIu32"/%"PRIu32": %p\n", i, mNumBuffers,
+ dprintf(fd, "Buffer %" PRIu32 "/%" PRIu32 ": %p\n", i, mNumBuffers,
mBuffers[i]);
}
}
diff --git a/modules/consumerir/consumerir.c b/modules/consumerir/consumerir.c
index 87039cc..f3eac0b 100644
--- a/modules/consumerir/consumerir.c
+++ b/modules/consumerir/consumerir.c
@@ -16,6 +16,7 @@
#define LOG_TAG "ConsumerIrHal"
#include <errno.h>
+#include <malloc.h>
#include <string.h>
#include <cutils/log.h>
#include <hardware/hardware.h>
diff --git a/modules/fingerprint/fingerprint.c b/modules/fingerprint/fingerprint.c
index 14dac12..0f11954 100644
--- a/modules/fingerprint/fingerprint.c
+++ b/modules/fingerprint/fingerprint.c
@@ -16,6 +16,7 @@
#define LOG_TAG "FingerprintHal"
#include <errno.h>
+#include <malloc.h>
#include <string.h>
#include <cutils/log.h>
#include <hardware/hardware.h>
@@ -32,12 +33,27 @@
}
static int fingerprint_enroll(struct fingerprint_device __unused *dev,
+ uint32_t __unused gid,
uint32_t __unused timeout_sec) {
return FINGERPRINT_ERROR;
}
+static int fingerprint_enroll_cancel(struct fingerprint_device __unused *dev) {
+ return FINGERPRINT_ERROR;
+}
+
static int fingerprint_remove(struct fingerprint_device __unused *dev,
- uint32_t __unused fingerprint_id) {
+ fingerprint_finger_id_t __unused fingerprint_id) {
+ return FINGERPRINT_ERROR;
+}
+
+static int fingerprint_set_active_group(struct fingerprint_device __unused *dev,
+ uint32_t __unused gid) {
+ return FINGERPRINT_ERROR;
+}
+
+static int fingerprint_authenticate(struct fingerprint_device __unused *dev,
+ uint64_t __unused operation_id, __unused uint32_t gid) {
return FINGERPRINT_ERROR;
}
@@ -60,12 +76,15 @@
memset(dev, 0, sizeof(fingerprint_device_t));
dev->common.tag = HARDWARE_DEVICE_TAG;
- dev->common.version = HARDWARE_MODULE_API_VERSION(1, 0);
+ dev->common.version = FINGERPRINT_MODULE_API_VERSION_2_0;
dev->common.module = (struct hw_module_t*) module;
dev->common.close = fingerprint_close;
dev->enroll = fingerprint_enroll;
+ dev->enroll_cancel = fingerprint_enroll_cancel;
dev->remove = fingerprint_remove;
+ dev->set_active_group = fingerprint_set_active_group;
+ dev->authenticate = fingerprint_authenticate;
dev->set_notify = set_notify_callback;
dev->notify = NULL;
@@ -80,7 +99,7 @@
fingerprint_module_t HAL_MODULE_INFO_SYM = {
.common = {
.tag = HARDWARE_MODULE_TAG,
- .module_api_version = FINGERPRINT_MODULE_API_VERSION_1_0,
+ .module_api_version = FINGERPRINT_MODULE_API_VERSION_2_0,
.hal_api_version = HARDWARE_HAL_API_VERSION,
.id = FINGERPRINT_HARDWARE_MODULE_ID,
.name = "Demo Fingerprint HAL",
diff --git a/modules/gralloc/mapper.cpp b/modules/gralloc/mapper.cpp
index 5a882e2..20d9841 100644
--- a/modules/gralloc/mapper.cpp
+++ b/modules/gralloc/mapper.cpp
@@ -33,14 +33,6 @@
#include "gralloc_priv.h"
-/* desktop Linux needs a little help with gettid() */
-#if defined(ARCH_X86) && !defined(HAVE_ANDROID_OS)
-#define __KERNEL__
-# include <linux/unistd.h>
-pid_t gettid() { return syscall(__NR_gettid);}
-#undef __KERNEL__
-#endif
-
/*****************************************************************************/
static int gralloc_map(gralloc_module_t const* /*module*/,
diff --git a/modules/hwcomposer/hwcomposer.cpp b/modules/hwcomposer/hwcomposer.cpp
index f0a5512..9d1aa34 100644
--- a/modules/hwcomposer/hwcomposer.cpp
+++ b/modules/hwcomposer/hwcomposer.cpp
@@ -16,8 +16,9 @@
#include <hardware/hardware.h>
-#include <fcntl.h>
#include <errno.h>
+#include <fcntl.h>
+#include <malloc.h>
#include <cutils/log.h>
#include <cutils/atomic.h>
diff --git a/modules/input/Android.mk b/modules/input/Android.mk
new file mode 100644
index 0000000..3011b2e
--- /dev/null
+++ b/modules/input/Android.mk
@@ -0,0 +1,19 @@
+# Copyright (C) 2015 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/modules/input/evdev/Android.mk b/modules/input/evdev/Android.mk
new file mode 100644
index 0000000..ad05af3
--- /dev/null
+++ b/modules/input/evdev/Android.mk
@@ -0,0 +1,29 @@
+# Copyright (C) 2015 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := input.evdev.default
+LOCAL_MODULE_RELATIVE_PATH := hw
+
+LOCAL_SRC_FILES := \
+ EvdevModule.cpp
+
+LOCAL_SHARED_LIBRARIES := liblog
+
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/input/evdev/EvdevModule.cpp b/modules/input/evdev/EvdevModule.cpp
new file mode 100644
index 0000000..f56842a
--- /dev/null
+++ b/modules/input/evdev/EvdevModule.cpp
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+#define LOG_NDEBUG 0
+#define LOG_TAG "EvdevModule"
+
+#include <assert.h>
+#include <hardware/hardware.h>
+#include <hardware/input.h>
+
+namespace input {
+
+extern "C" {
+
+static int dummy_open(const hw_module_t __unused *module, const char __unused *id,
+ hw_device_t __unused **device) {
+ assert(false);
+ return 0;
+}
+
+static void input_init(const input_module_t* module,
+ input_host_t* host, input_host_callbacks_t cb) {
+ return;
+}
+
+static void input_notify_report(input_report_t* r) {
+ return;
+}
+
+static struct hw_module_methods_t input_module_methods = {
+ .open = dummy_open,
+};
+
+input_module_t HAL_MODULE_INFO_SYM = {
+ .common = {
+ .tag = HARDWARE_MODULE_TAG,
+ .module_api_version = INPUT_MODULE_API_VERSION_1_0,
+ .hal_api_version = HARDWARE_HAL_API_VERSION,
+ .id = INPUT_HARDWARE_MODULE_ID,
+ .name = "Input evdev HAL",
+ .author = "The Android Open Source Project",
+ .methods = &input_module_methods,
+ .dso = NULL,
+ .reserved = {0},
+ },
+
+ .init = input_init,
+ .notify_report = input_notify_report,
+};
+
+} // extern "C"
+
+} // namespace input
diff --git a/modules/local_time/local_time_hw.c b/modules/local_time/local_time_hw.c
index 308f7d9..ac597f4 100644
--- a/modules/local_time/local_time_hw.c
+++ b/modules/local_time/local_time_hw.c
@@ -18,9 +18,10 @@
//#define LOG_NDEBUG 0
#include <errno.h>
+#include <malloc.h>
#include <stdint.h>
+#include <string.h>
#include <sys/time.h>
-#include <linux/time.h>
#include <cutils/log.h>
diff --git a/modules/nfc-nci/nfc_nci_example.c b/modules/nfc-nci/nfc_nci_example.c
index 2514225..758c2b7 100644
--- a/modules/nfc-nci/nfc_nci_example.c
+++ b/modules/nfc-nci/nfc_nci_example.c
@@ -14,6 +14,7 @@
* limitations under the License.
*/
#include <errno.h>
+#include <malloc.h>
#include <string.h>
#include <cutils/log.h>
diff --git a/modules/nfc/nfc_pn544_example.c b/modules/nfc/nfc_pn544_example.c
index 54c9c56..71bfd6b 100644
--- a/modules/nfc/nfc_pn544_example.c
+++ b/modules/nfc/nfc_pn544_example.c
@@ -14,6 +14,7 @@
* limitations under the License.
*/
#include <errno.h>
+#include <malloc.h>
#include <string.h>
#include <hardware/hardware.h>
diff --git a/modules/radio/Android.mk b/modules/radio/Android.mk
new file mode 100644
index 0000000..f433c85
--- /dev/null
+++ b/modules/radio/Android.mk
@@ -0,0 +1,27 @@
+# Copyright (C) 2015 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.
+
+LOCAL_PATH := $(call my-dir)
+
+# Stub radio HAL module, used for tests
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := radio.fm.default
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_SRC_FILES := radio_hw.c
+LOCAL_SHARED_LIBRARIES := liblog libcutils libradio_metadata
+LOCAL_MODULE_TAGS := optional
+LOCAL_32_BIT_ONLY := true
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/radio/radio_hw.c b/modules/radio/radio_hw.c
new file mode 100644
index 0000000..b1a4d26
--- /dev/null
+++ b/modules/radio/radio_hw.c
@@ -0,0 +1,726 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+#define LOG_TAG "radio_hw_stub"
+#define LOG_NDEBUG 0
+
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <pthread.h>
+#include <sys/prctl.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <cutils/log.h>
+#include <cutils/list.h>
+#include <system/radio.h>
+#include <system/radio_metadata.h>
+#include <hardware/hardware.h>
+#include <hardware/radio.h>
+
+static const radio_hal_properties_t hw_properties = {
+ .class_id = RADIO_CLASS_AM_FM,
+ .implementor = "The Android Open Source Project",
+ .product = "Radio stub HAL",
+ .version = "0.1",
+ .serial = "0123456789",
+ .num_tuners = 1,
+ .num_audio_sources = 1,
+ .supports_capture = false,
+ .num_bands = 2,
+ .bands = {
+ {
+ .type = RADIO_BAND_FM,
+ .antenna_connected = false,
+ .lower_limit = 87900,
+ .upper_limit = 107900,
+ .num_spacings = 1,
+ .spacings = { 200 },
+ .fm = {
+ .deemphasis = RADIO_DEEMPHASIS_75,
+ .stereo = true,
+ .rds = RADIO_RDS_US,
+ .ta = false,
+ .af = false,
+ }
+ },
+ {
+ .type = RADIO_BAND_AM,
+ .antenna_connected = true,
+ .lower_limit = 540,
+ .upper_limit = 1610,
+ .num_spacings = 1,
+ .spacings = { 10 },
+ .am = {
+ .stereo = true,
+ }
+ }
+ }
+};
+
+struct stub_radio_tuner {
+ struct radio_tuner interface;
+ struct stub_radio_device *dev;
+ radio_callback_t callback;
+ void *cookie;
+ radio_hal_band_config_t config;
+ radio_program_info_t program;
+ bool audio;
+ pthread_t callback_thread;
+ pthread_mutex_t lock;
+ pthread_cond_t cond;
+ struct listnode command_list;
+};
+
+struct stub_radio_device {
+ struct radio_hw_device device;
+ struct stub_radio_tuner *tuner;
+ pthread_mutex_t lock;
+};
+
+
+typedef enum {
+ CMD_EXIT,
+ CMD_CONFIG,
+ CMD_STEP,
+ CMD_SCAN,
+ CMD_TUNE,
+ CMD_CANCEL,
+ CMD_METADATA,
+} thread_cmd_type_t;
+
+struct thread_command {
+ struct listnode node;
+ thread_cmd_type_t type;
+ struct timespec ts;
+ union {
+ unsigned int param;
+ radio_hal_band_config_t config;
+ };
+};
+
+/* must be called with out->lock locked */
+static int send_command_l(struct stub_radio_tuner *tuner,
+ thread_cmd_type_t type,
+ unsigned int delay_ms,
+ void *param)
+{
+ struct thread_command *cmd = (struct thread_command *)calloc(1, sizeof(struct thread_command));
+ struct timespec ts;
+
+ if (cmd == NULL)
+ return -ENOMEM;
+
+ ALOGV("%s %d delay_ms %d", __func__, type, delay_ms);
+
+ cmd->type = type;
+ if (param != NULL) {
+ if (cmd->type == CMD_CONFIG) {
+ cmd->config = *(radio_hal_band_config_t *)param;
+ ALOGV("%s CMD_CONFIG type %d", __func__, cmd->config.type);
+ } else
+ cmd->param = *(unsigned int *)param;
+ }
+
+ clock_gettime(CLOCK_REALTIME, &ts);
+
+ ts.tv_sec += delay_ms/1000;
+ ts.tv_nsec += (delay_ms%1000) * 1000000;
+ if (ts.tv_nsec >= 1000000000) {
+ ts.tv_nsec -= 1000000000;
+ ts.tv_sec += 1;
+ }
+ cmd->ts = ts;
+ list_add_tail(&tuner->command_list, &cmd->node);
+ pthread_cond_signal(&tuner->cond);
+ return 0;
+}
+
+#define BITMAP_FILE_PATH "/data/misc/media/android.png"
+
+static int add_bitmap_metadata(radio_metadata_t **metadata, radio_metadata_key_t key,
+ const char *source)
+{
+ int fd;
+ ssize_t ret = 0;
+ struct stat info;
+ void *data = NULL;
+ size_t size;
+
+ fd = open(source, O_RDONLY);
+ if (fd < 0)
+ return -EPIPE;
+
+ fstat(fd, &info);
+ size = info.st_size;
+ data = malloc(size);
+ if (data == NULL) {
+ ret = -ENOMEM;
+ goto exit;
+ }
+ ret = read(fd, data, size);
+ if (ret < 0)
+ goto exit;
+ ret = radio_metadata_add_raw(metadata, key, (const unsigned char *)data, size);
+
+exit:
+ close(fd);
+ free(data);
+ ALOGE_IF(ret != 0, "%s error %d", __func__, ret);
+ return (int)ret;
+}
+
+static int prepare_metadata(struct stub_radio_tuner *tuner,
+ radio_metadata_t **metadata, bool program)
+{
+ int ret = 0;
+ char text[RADIO_STRING_LEN_MAX];
+ struct timespec ts;
+
+ if (metadata == NULL)
+ return -EINVAL;
+
+ if (*metadata != NULL)
+ radio_metadata_deallocate(*metadata);
+
+ *metadata = NULL;
+
+ ret = radio_metadata_allocate(metadata, tuner->program.channel, 0);
+ if (ret != 0)
+ return ret;
+
+ if (program) {
+ ret = radio_metadata_add_int(metadata, RADIO_METADATA_KEY_RBDS_PTY, 5);
+ if (ret != 0)
+ goto exit;
+ ret = radio_metadata_add_text(metadata, RADIO_METADATA_KEY_RDS_PS, "RockBand");
+ if (ret != 0)
+ goto exit;
+ ret = add_bitmap_metadata(metadata, RADIO_METADATA_KEY_ICON, BITMAP_FILE_PATH);
+ if (ret != 0)
+ goto exit;
+ } else {
+ ret = add_bitmap_metadata(metadata, RADIO_METADATA_KEY_ART, BITMAP_FILE_PATH);
+ if (ret != 0)
+ goto exit;
+ }
+
+ clock_gettime(CLOCK_REALTIME, &ts);
+ snprintf(text, RADIO_STRING_LEN_MAX, "Artist %ld", ts.tv_sec % 10);
+ ret = radio_metadata_add_text(metadata, RADIO_METADATA_KEY_ARTIST, text);
+ if (ret != 0)
+ goto exit;
+
+ snprintf(text, RADIO_STRING_LEN_MAX, "Song %ld", ts.tv_nsec % 10);
+ ret = radio_metadata_add_text(metadata, RADIO_METADATA_KEY_TITLE, text);
+ if (ret != 0)
+ goto exit;
+
+ return 0;
+
+exit:
+ radio_metadata_deallocate(*metadata);
+ *metadata = NULL;
+ return ret;
+}
+
+static void *callback_thread_loop(void *context)
+{
+ struct stub_radio_tuner *tuner = (struct stub_radio_tuner *)context;
+ struct timespec ts = {0, 0};
+
+ ALOGI("%s", __func__);
+
+ prctl(PR_SET_NAME, (unsigned long)"sound trigger callback", 0, 0, 0);
+
+ pthread_mutex_lock(&tuner->lock);
+
+ while (true) {
+ struct thread_command *cmd = NULL;
+ struct listnode *item;
+ struct listnode *tmp;
+ struct timespec cur_ts;
+
+ if (list_empty(&tuner->command_list) || ts.tv_sec != 0) {
+ ALOGV("%s SLEEPING", __func__);
+ if (ts.tv_sec != 0) {
+ ALOGV("%s SLEEPING with timeout", __func__);
+ pthread_cond_timedwait(&tuner->cond, &tuner->lock, &ts);
+ } else {
+ ALOGV("%s SLEEPING forever", __func__);
+ pthread_cond_wait(&tuner->cond, &tuner->lock);
+ }
+ ts.tv_sec = 0;
+ ALOGV("%s RUNNING", __func__);
+ }
+
+ clock_gettime(CLOCK_REALTIME, &cur_ts);
+
+ list_for_each_safe(item, tmp, &tuner->command_list) {
+ cmd = node_to_item(item, struct thread_command, node);
+
+ if ((cmd->ts.tv_sec < cur_ts.tv_sec) ||
+ ((cmd->ts.tv_sec == cur_ts.tv_sec) && (cmd->ts.tv_nsec < cur_ts.tv_nsec))) {
+ radio_hal_event_t event;
+
+ event.type = RADIO_EVENT_HW_FAILURE;
+ list_remove(item);
+
+ ALOGV("%s processing command %d time %ld.%ld", __func__, cmd->type, cmd->ts.tv_sec,
+ cmd->ts.tv_nsec);
+
+ switch (cmd->type) {
+ default:
+ case CMD_EXIT:
+ free(cmd);
+ goto exit;
+
+ case CMD_CONFIG: {
+ tuner->config = cmd->config;
+ event.type = RADIO_EVENT_CONFIG;
+ event.config = tuner->config;
+ ALOGV("%s CMD_CONFIG type %d low %d up %d",
+ __func__, tuner->config.type,
+ tuner->config.lower_limit, tuner->config.upper_limit);
+ if (tuner->config.type == RADIO_BAND_FM) {
+ ALOGV(" - stereo %d\n - rds %d\n - ta %d\n - af %d",
+ tuner->config.fm.stereo, tuner->config.fm.rds,
+ tuner->config.fm.ta, tuner->config.fm.af);
+ } else {
+ ALOGV(" - stereo %d", tuner->config.am.stereo);
+ }
+ } break;
+
+ case CMD_STEP: {
+ int frequency;
+ frequency = tuner->program.channel;
+ if (cmd->param == RADIO_DIRECTION_UP) {
+ frequency += tuner->config.spacings[0];
+ } else {
+ frequency -= tuner->config.spacings[0];
+ }
+ if (frequency > (int)tuner->config.upper_limit) {
+ frequency = tuner->config.lower_limit;
+ }
+ if (frequency < (int)tuner->config.lower_limit) {
+ frequency = tuner->config.upper_limit;
+ }
+ tuner->program.channel = frequency;
+ tuner->program.tuned = (frequency / (tuner->config.spacings[0] * 5)) % 2;
+ tuner->program.signal_strength = 20;
+ if (tuner->config.type == RADIO_BAND_FM)
+ tuner->program.stereo = false;
+ else
+ tuner->program.stereo = false;
+
+ event.type = RADIO_EVENT_TUNED;
+ event.info = tuner->program;
+ } break;
+
+ case CMD_SCAN: {
+ int frequency;
+ frequency = tuner->program.channel;
+ if (cmd->param == RADIO_DIRECTION_UP) {
+ frequency += tuner->config.spacings[0] * 25;
+ } else {
+ frequency -= tuner->config.spacings[0] * 25;
+ }
+ if (frequency > (int)tuner->config.upper_limit) {
+ frequency = tuner->config.lower_limit;
+ }
+ if (frequency < (int)tuner->config.lower_limit) {
+ frequency = tuner->config.upper_limit;
+ }
+ tuner->program.channel = (unsigned int)frequency;
+ tuner->program.tuned = true;
+ if (tuner->config.type == RADIO_BAND_FM)
+ tuner->program.stereo = tuner->config.fm.stereo;
+ else
+ tuner->program.stereo = tuner->config.am.stereo;
+ tuner->program.signal_strength = 50;
+
+ event.type = RADIO_EVENT_TUNED;
+ event.info = tuner->program;
+ if (tuner->program.metadata != NULL)
+ radio_metadata_deallocate(tuner->program.metadata);
+ tuner->program.metadata = NULL;
+ send_command_l(tuner, CMD_METADATA, 2000, NULL);
+ } break;
+
+ case CMD_TUNE: {
+ tuner->program.channel = cmd->param;
+ tuner->program.tuned = (tuner->program.channel /
+ (tuner->config.spacings[0] * 5)) % 2;
+
+ if (tuner->program.tuned) {
+ prepare_metadata(tuner, &tuner->program.metadata, true);
+ send_command_l(tuner, CMD_METADATA, 5000, NULL);
+ } else {
+ if (tuner->program.metadata != NULL)
+ radio_metadata_deallocate(tuner->program.metadata);
+ tuner->program.metadata = NULL;
+ }
+ tuner->program.signal_strength = 100;
+ if (tuner->config.type == RADIO_BAND_FM)
+ tuner->program.stereo =
+ tuner->program.tuned ? tuner->config.fm.stereo : false;
+ else
+ tuner->program.stereo =
+ tuner->program.tuned ? tuner->config.am.stereo : false;
+ event.type = RADIO_EVENT_TUNED;
+ event.info = tuner->program;
+ } break;
+
+ case CMD_METADATA: {
+ prepare_metadata(tuner, &tuner->program.metadata, false);
+ event.type = RADIO_EVENT_METADATA;
+ event.metadata = tuner->program.metadata;
+ } break;
+
+ case CMD_CANCEL: {
+ struct listnode *tmp2;
+ list_for_each_safe(item, tmp2, &tuner->command_list) {
+ cmd = node_to_item(item, struct thread_command, node);
+ if (cmd->type == CMD_STEP || cmd->type == CMD_SCAN ||
+ cmd->type == CMD_TUNE || cmd->type == CMD_METADATA) {
+ list_remove(item);
+ free(cmd);
+ }
+ }
+ } break;
+
+ }
+ if (event.type != RADIO_EVENT_HW_FAILURE && tuner->callback != NULL) {
+ pthread_mutex_unlock(&tuner->lock);
+ tuner->callback(&event, tuner->cookie);
+ pthread_mutex_lock(&tuner->lock);
+ }
+ ALOGV("%s processed command %d", __func__, cmd->type);
+ free(cmd);
+ } else {
+ if ((ts.tv_sec == 0) ||
+ (cmd->ts.tv_sec < ts.tv_sec) ||
+ ((cmd->ts.tv_sec == ts.tv_sec) && (cmd->ts.tv_nsec < ts.tv_nsec))) {
+ ts.tv_sec = cmd->ts.tv_sec;
+ ts.tv_nsec = cmd->ts.tv_nsec;
+ }
+ }
+ }
+ }
+
+exit:
+ pthread_mutex_unlock(&tuner->lock);
+
+ ALOGV("%s Exiting", __func__);
+
+ return NULL;
+}
+
+
+static int tuner_set_configuration(const struct radio_tuner *tuner,
+ const radio_hal_band_config_t *config)
+{
+ struct stub_radio_tuner *stub_tuner = (struct stub_radio_tuner *)tuner;
+ int status = 0;
+
+ ALOGI("%s stub_tuner %p", __func__, stub_tuner);
+ pthread_mutex_lock(&stub_tuner->lock);
+ if (config == NULL) {
+ status = -EINVAL;
+ goto exit;
+ }
+ send_command_l(stub_tuner, CMD_CANCEL, 0, NULL);
+ send_command_l(stub_tuner, CMD_CONFIG, 500, (void *)config);
+
+exit:
+ pthread_mutex_unlock(&stub_tuner->lock);
+ return status;
+}
+
+static int tuner_get_configuration(const struct radio_tuner *tuner,
+ radio_hal_band_config_t *config)
+{
+ struct stub_radio_tuner *stub_tuner = (struct stub_radio_tuner *)tuner;
+ int status = 0;
+ struct listnode *item;
+ radio_hal_band_config_t *src_config;
+
+ ALOGI("%s stub_tuner %p", __func__, stub_tuner);
+ pthread_mutex_lock(&stub_tuner->lock);
+ src_config = &stub_tuner->config;
+
+ if (config == NULL) {
+ status = -EINVAL;
+ goto exit;
+ }
+ list_for_each(item, &stub_tuner->command_list) {
+ struct thread_command *cmd = node_to_item(item, struct thread_command, node);
+ if (cmd->type == CMD_CONFIG) {
+ src_config = &cmd->config;
+ }
+ }
+ *config = *src_config;
+
+exit:
+ pthread_mutex_unlock(&stub_tuner->lock);
+ return status;
+}
+
+static int tuner_step(const struct radio_tuner *tuner,
+ radio_direction_t direction, bool skip_sub_channel)
+{
+ struct stub_radio_tuner *stub_tuner = (struct stub_radio_tuner *)tuner;
+
+ ALOGI("%s stub_tuner %p direction %d, skip_sub_channel %d",
+ __func__, stub_tuner, direction, skip_sub_channel);
+
+ pthread_mutex_lock(&stub_tuner->lock);
+ send_command_l(stub_tuner, CMD_STEP, 20, &direction);
+ pthread_mutex_unlock(&stub_tuner->lock);
+ return 0;
+}
+
+static int tuner_scan(const struct radio_tuner *tuner,
+ radio_direction_t direction, bool skip_sub_channel)
+{
+ struct stub_radio_tuner *stub_tuner = (struct stub_radio_tuner *)tuner;
+
+ ALOGI("%s stub_tuner %p direction %d, skip_sub_channel %d",
+ __func__, stub_tuner, direction, skip_sub_channel);
+
+ pthread_mutex_lock(&stub_tuner->lock);
+ send_command_l(stub_tuner, CMD_SCAN, 200, &direction);
+ pthread_mutex_unlock(&stub_tuner->lock);
+ return 0;
+}
+
+static int tuner_tune(const struct radio_tuner *tuner,
+ unsigned int channel, unsigned int sub_channel)
+{
+ struct stub_radio_tuner *stub_tuner = (struct stub_radio_tuner *)tuner;
+
+ ALOGI("%s stub_tuner %p channel %d, sub_channel %d",
+ __func__, stub_tuner, channel, sub_channel);
+
+ pthread_mutex_lock(&stub_tuner->lock);
+ if (channel < stub_tuner->config.lower_limit || channel > stub_tuner->config.upper_limit) {
+ pthread_mutex_unlock(&stub_tuner->lock);
+ ALOGI("%s channel out of range", __func__);
+ return -EINVAL;
+ }
+ send_command_l(stub_tuner, CMD_TUNE, 100, &channel);
+ pthread_mutex_unlock(&stub_tuner->lock);
+ return 0;
+}
+
+static int tuner_cancel(const struct radio_tuner *tuner)
+{
+ struct stub_radio_tuner *stub_tuner = (struct stub_radio_tuner *)tuner;
+
+ ALOGI("%s stub_tuner %p", __func__, stub_tuner);
+
+ pthread_mutex_lock(&stub_tuner->lock);
+ send_command_l(stub_tuner, CMD_CANCEL, 0, NULL);
+ pthread_mutex_unlock(&stub_tuner->lock);
+ return 0;
+}
+
+static int tuner_get_program_information(const struct radio_tuner *tuner,
+ radio_program_info_t *info)
+{
+ struct stub_radio_tuner *stub_tuner = (struct stub_radio_tuner *)tuner;
+ int status = 0;
+ radio_metadata_t *metadata;
+
+ ALOGI("%s stub_tuner %p", __func__, stub_tuner);
+ pthread_mutex_lock(&stub_tuner->lock);
+ if (info == NULL) {
+ status = -EINVAL;
+ goto exit;
+ }
+ metadata = info->metadata;
+ *info = stub_tuner->program;
+ info->metadata = metadata;
+ if (metadata != NULL)
+ radio_metadata_add_metadata(&info->metadata, stub_tuner->program.metadata);
+
+exit:
+ pthread_mutex_unlock(&stub_tuner->lock);
+ return status;
+}
+
+static int rdev_get_properties(const struct radio_hw_device *dev,
+ radio_hal_properties_t *properties)
+{
+ struct stub_radio_device *rdev = (struct stub_radio_device *)dev;
+
+ ALOGI("%s", __func__);
+ if (properties == NULL)
+ return -EINVAL;
+ memcpy(properties, &hw_properties, sizeof(radio_hal_properties_t));
+ return 0;
+}
+
+static int rdev_open_tuner(const struct radio_hw_device *dev,
+ const radio_hal_band_config_t *config,
+ bool audio,
+ radio_callback_t callback,
+ void *cookie,
+ const struct radio_tuner **tuner)
+{
+ struct stub_radio_device *rdev = (struct stub_radio_device *)dev;
+ int status = 0;
+
+ ALOGI("%s rdev %p", __func__, rdev);
+ pthread_mutex_lock(&rdev->lock);
+
+ if (rdev->tuner != NULL) {
+ status = -ENOSYS;
+ goto exit;
+ }
+
+ if (config == NULL || callback == NULL || tuner == NULL) {
+ status = -EINVAL;
+ goto exit;
+ }
+
+ rdev->tuner = (struct stub_radio_tuner *)calloc(1, sizeof(struct stub_radio_tuner));
+ if (rdev->tuner == NULL) {
+ status = -ENOMEM;
+ goto exit;
+ }
+
+ rdev->tuner->interface.set_configuration = tuner_set_configuration;
+ rdev->tuner->interface.get_configuration = tuner_get_configuration;
+ rdev->tuner->interface.scan = tuner_scan;
+ rdev->tuner->interface.step = tuner_step;
+ rdev->tuner->interface.tune = tuner_tune;
+ rdev->tuner->interface.cancel = tuner_cancel;
+ rdev->tuner->interface.get_program_information = tuner_get_program_information;
+
+ rdev->tuner->audio = audio;
+ rdev->tuner->callback = callback;
+ rdev->tuner->cookie = cookie;
+
+ rdev->tuner->dev = rdev;
+
+ pthread_mutex_init(&rdev->tuner->lock, (const pthread_mutexattr_t *) NULL);
+ pthread_cond_init(&rdev->tuner->cond, (const pthread_condattr_t *) NULL);
+ pthread_create(&rdev->tuner->callback_thread, (const pthread_attr_t *) NULL,
+ callback_thread_loop, rdev->tuner);
+ list_init(&rdev->tuner->command_list);
+
+ pthread_mutex_lock(&rdev->tuner->lock);
+ send_command_l(rdev->tuner, CMD_CONFIG, 500, (void *)config);
+ pthread_mutex_unlock(&rdev->tuner->lock);
+
+ *tuner = &rdev->tuner->interface;
+
+exit:
+ pthread_mutex_unlock(&rdev->lock);
+ ALOGI("%s DONE", __func__);
+ return status;
+}
+
+static int rdev_close_tuner(const struct radio_hw_device *dev,
+ const struct radio_tuner *tuner)
+{
+ struct stub_radio_device *rdev = (struct stub_radio_device *)dev;
+ struct stub_radio_tuner *stub_tuner = (struct stub_radio_tuner *)tuner;
+ int status = 0;
+
+ ALOGI("%s tuner %p", __func__, tuner);
+ pthread_mutex_lock(&rdev->lock);
+
+ if (tuner == NULL) {
+ status = -EINVAL;
+ goto exit;
+ }
+
+ pthread_mutex_lock(&stub_tuner->lock);
+ stub_tuner->callback = NULL;
+ send_command_l(stub_tuner, CMD_EXIT, 0, NULL);
+ pthread_mutex_unlock(&stub_tuner->lock);
+ pthread_join(stub_tuner->callback_thread, (void **) NULL);
+
+ if (stub_tuner->program.metadata != NULL)
+ radio_metadata_deallocate(stub_tuner->program.metadata);
+
+ free(stub_tuner);
+ rdev->tuner = NULL;
+
+exit:
+ pthread_mutex_unlock(&rdev->lock);
+ return status;
+}
+
+static int rdev_close(hw_device_t *device)
+{
+ struct stub_radio_device *rdev = (struct stub_radio_device *)device;
+ if (rdev != NULL) {
+ free(rdev->tuner);
+ }
+ free(rdev);
+ return 0;
+}
+
+static int rdev_open(const hw_module_t* module, const char* name,
+ hw_device_t** device)
+{
+ struct stub_radio_device *rdev;
+ int ret;
+
+ if (strcmp(name, RADIO_HARDWARE_DEVICE) != 0)
+ return -EINVAL;
+
+ rdev = calloc(1, sizeof(struct stub_radio_device));
+ if (!rdev)
+ return -ENOMEM;
+
+ rdev->device.common.tag = HARDWARE_DEVICE_TAG;
+ rdev->device.common.version = RADIO_DEVICE_API_VERSION_1_0;
+ rdev->device.common.module = (struct hw_module_t *) module;
+ rdev->device.common.close = rdev_close;
+ rdev->device.get_properties = rdev_get_properties;
+ rdev->device.open_tuner = rdev_open_tuner;
+ rdev->device.close_tuner = rdev_close_tuner;
+
+ pthread_mutex_init(&rdev->lock, (const pthread_mutexattr_t *) NULL);
+
+ *device = &rdev->device.common;
+
+ return 0;
+}
+
+
+static struct hw_module_methods_t hal_module_methods = {
+ .open = rdev_open,
+};
+
+struct radio_module HAL_MODULE_INFO_SYM = {
+ .common = {
+ .tag = HARDWARE_MODULE_TAG,
+ .module_api_version = RADIO_MODULE_API_VERSION_1_0,
+ .hal_api_version = HARDWARE_HAL_API_VERSION,
+ .id = RADIO_HARDWARE_MODULE_ID,
+ .name = "Stub radio HAL",
+ .author = "The Android Open Source Project",
+ .methods = &hal_module_methods,
+ },
+};
diff --git a/modules/sensors/Android.mk b/modules/sensors/Android.mk
index 65f699b..445f69e 100644
--- a/modules/sensors/Android.mk
+++ b/modules/sensors/Android.mk
@@ -35,16 +35,10 @@
libcutils \
libdl \
liblog \
- libstlport \
libutils \
-LOCAL_PRELINK_MODULE := false
LOCAL_STRIP_MODULE := false
-LOCAL_C_INCLUDES := \
- external/stlport/stlport \
- bionic \
-
include $(BUILD_SHARED_LIBRARY)
endif # USE_SENSOR_MULTI_HAL
diff --git a/modules/tv_input/tv_input.cpp b/modules/tv_input/tv_input.cpp
index bc02786..114e80e 100644
--- a/modules/tv_input/tv_input.cpp
+++ b/modules/tv_input/tv_input.cpp
@@ -14,8 +14,9 @@
* limitations under the License.
*/
-#include <fcntl.h>
#include <errno.h>
+#include <fcntl.h>
+#include <malloc.h>
#include <cutils/log.h>
#include <cutils/native_handle.h>
diff --git a/modules/usbaudio/Android.mk b/modules/usbaudio/Android.mk
index ec8a8c0..9df1e79 100644
--- a/modules/usbaudio/Android.mk
+++ b/modules/usbaudio/Android.mk
@@ -19,15 +19,12 @@
LOCAL_MODULE := audio.usb.default
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := \
- audio_hw.c \
- alsa_device_profile.c \
- alsa_device_proxy.c \
- logging.c \
- format.c
+ audio_hal.c
LOCAL_C_INCLUDES += \
external/tinyalsa/include \
- $(call include-path-for, audio-utils)
-LOCAL_SHARED_LIBRARIES := liblog libcutils libtinyalsa libaudioutils
+ $(call include-path-for, audio-utils) \
+ $(call include-path-for, alsa-utils)
+LOCAL_SHARED_LIBRARIES := liblog libcutils libtinyalsa libaudioutils libalsautils
LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS := -Wno-unused-parameter
diff --git a/modules/usbaudio/alsa_device_profile.c b/modules/usbaudio/alsa_device_profile.c
deleted file mode 100644
index 8e84471..0000000
--- a/modules/usbaudio/alsa_device_profile.c
+++ /dev/null
@@ -1,497 +0,0 @@
-/*
- * Copyright (C) 2014 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.
- */
-
-#define LOG_TAG "alsa_device_profile"
-/*#define LOG_NDEBUG 0*/
-/*#define LOG_PCM_PARAMS 0*/
-
-#include <errno.h>
-#include <inttypes.h>
-#include <stdint.h>
-#include <stdlib.h>
-
-#include <log/log.h>
-
-#include "alsa_device_profile.h"
-#include "format.h"
-#include "logging.h"
-
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
-
-/*TODO - Evaluate if this value should/can be retrieved from a device-specific property */
-#define BUFF_DURATION_MS 5
-
-#define DEFAULT_PERIOD_SIZE 1024
-
-static const char * const format_string_map[] = {
- "AUDIO_FORMAT_PCM_16_BIT", /* "PCM_FORMAT_S16_LE", */
- "AUDIO_FORMAT_PCM_32_BIT", /* "PCM_FORMAT_S32_LE", */
- "AUDIO_FORMAT_PCM_8_BIT", /* "PCM_FORMAT_S8", */
- "AUDIO_FORMAT_PCM_8_24_BIT", /* "PCM_FORMAT_S24_LE", */
- "AUDIO_FORMAT_PCM_24_BIT_PACKED"/* "PCM_FORMAT_S24_3LE" */
-};
-
-static const unsigned const format_byte_size_map[] = {
- 2, /* PCM_FORMAT_S16_LE */
- 4, /* PCM_FORMAT_S32_LE */
- 1, /* PCM_FORMAT_S8 */
- 4, /* PCM_FORMAT_S24_LE */
- 3, /* PCM_FORMAT_S24_3LE */
-};
-
-extern int8_t const pcm_format_value_map[50];
-
-/* sort these highest -> lowest (to default to best quality) */
-static const unsigned std_sample_rates[] =
- {48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000};
-
-static void profile_reset(alsa_device_profile* profile)
-{
- profile->card = profile->device = -1;
-
- /* Fill the attribute arrays with invalid values */
- size_t index;
- for (index = 0; index < ARRAY_SIZE(profile->formats); index++) {
- profile->formats[index] = PCM_FORMAT_INVALID;
- }
-
- for (index = 0; index < ARRAY_SIZE(profile->sample_rates); index++) {
- profile->sample_rates[index] = 0;
- }
-
- for (index = 0; index < ARRAY_SIZE(profile->channel_counts); index++) {
- profile->channel_counts[index] = 0;
- }
-
- profile->min_period_size = profile->max_period_size = 0;
- profile->min_channel_count = profile->max_channel_count = DEFAULT_CHANNEL_COUNT;
-
- profile->is_valid = false;
-}
-
-void profile_init(alsa_device_profile* profile, int direction)
-{
- profile->direction = direction;
- profile_reset(profile);
-}
-
-bool profile_is_initialized(alsa_device_profile* profile)
-{
- return profile->card >= 0 && profile->device >= 0;
-}
-
-bool profile_is_valid(alsa_device_profile* profile) {
- return profile->is_valid;
-}
-
-bool profile_is_cached_for(alsa_device_profile* profile, int card, int device) {
- return card == profile->card && device == profile->device;
-}
-
-void profile_decache(alsa_device_profile* profile) {
- profile_reset(profile);
-}
-
-/*
- * Returns the supplied value rounded up to the next even multiple of 16
- */
-static unsigned int round_to_16_mult(unsigned int size)
-{
- return (size + 15) & ~15; // 0xFFFFFFF0;
-}
-
-/*
- * Returns the system defined minimum period size based on the supplied sample rate.
- */
-unsigned profile_calc_min_period_size(alsa_device_profile* profile, unsigned sample_rate)
-{
- ALOGV("profile_calc_min_period_size(%p, rate:%d)", profile, sample_rate);
- if (profile == NULL) {
- return DEFAULT_PERIOD_SIZE;
- } else {
- unsigned num_sample_frames = (sample_rate * BUFF_DURATION_MS) / 1000;
- if (num_sample_frames < profile->min_period_size) {
- num_sample_frames = profile->min_period_size;
- }
- return round_to_16_mult(num_sample_frames) * 2;
- }
-}
-
-unsigned int profile_get_period_size(alsa_device_profile* profile, unsigned sample_rate)
-{
- // return profile->default_config.period_size;
- unsigned int period_size = profile_calc_min_period_size(profile, sample_rate);
- ALOGV("profile_get_period_size(rate:%d) = %d", sample_rate, period_size);
- return period_size;
-}
-
-/*
- * Sample Rate
- */
-unsigned profile_get_default_sample_rate(alsa_device_profile* profile)
-{
- /*
- * TODO this won't be right in general. we should store a preferred rate as we are scanning.
- * But right now it will return the highest rate, which may be correct.
- */
- return profile_is_valid(profile) ? profile->sample_rates[0] : DEFAULT_SAMPLE_RATE;
-}
-
-bool profile_is_sample_rate_valid(alsa_device_profile* profile, unsigned rate)
-{
- if (profile_is_valid(profile)) {
- size_t index;
- for (index = 0; profile->sample_rates[index] != 0; index++) {
- if (profile->sample_rates[index] == rate) {
- return true;
- }
- }
-
- return false;
- } else {
- return rate == DEFAULT_SAMPLE_RATE;
- }
-}
-
-/*
- * Format
- */
-enum pcm_format profile_get_default_format(alsa_device_profile* profile)
-{
- /*
- * TODO this won't be right in general. we should store a preferred format as we are scanning.
- */
- return profile_is_valid(profile) ? profile->formats[0] : DEFAULT_SAMPLE_FORMAT;
-}
-
-bool profile_is_format_valid(alsa_device_profile* profile, enum pcm_format fmt) {
- if (profile_is_valid(profile)) {
- size_t index;
- for (index = 0; profile->formats[index] != PCM_FORMAT_INVALID; index++) {
- if (profile->formats[index] == fmt) {
- return true;
- }
- }
-
- return false;
- } else {
- return fmt == DEFAULT_SAMPLE_FORMAT;
- }
-}
-
-/*
- * Channels
- */
-unsigned profile_get_default_channel_count(alsa_device_profile* profile)
-{
- return profile_is_valid(profile) ? profile->channel_counts[0] : DEFAULT_CHANNEL_COUNT;
-}
-
-bool profile_is_channel_count_valid(alsa_device_profile* profile, unsigned count)
-{
- if (profile_is_initialized(profile)) {
- return count >= profile->min_channel_count && count <= profile->max_channel_count;
- } else {
- return count == DEFAULT_CHANNEL_COUNT;
- }
-}
-
-static bool profile_test_sample_rate(alsa_device_profile* profile, unsigned rate)
-{
- struct pcm_config config = profile->default_config;
- config.rate = rate;
-
- bool works = false; /* let's be pessimistic */
- struct pcm * pcm = pcm_open(profile->card, profile->device,
- profile->direction, &config);
-
- if (pcm != NULL) {
- works = pcm_is_ready(pcm);
- pcm_close(pcm);
- }
-
- return works;
-}
-
-static unsigned profile_enum_sample_rates(alsa_device_profile* profile, unsigned min, unsigned max)
-{
- unsigned num_entries = 0;
- unsigned index;
-
- for (index = 0; index < ARRAY_SIZE(std_sample_rates) &&
- num_entries < ARRAY_SIZE(profile->sample_rates) - 1;
- index++) {
- if (std_sample_rates[index] >= min && std_sample_rates[index] <= max
- && profile_test_sample_rate(profile, std_sample_rates[index])) {
- profile->sample_rates[num_entries++] = std_sample_rates[index];
- }
- }
-
- return num_entries; /* return # of supported rates */
-}
-
-static unsigned profile_enum_sample_formats(alsa_device_profile* profile, struct pcm_mask * mask)
-{
- const int num_slots = ARRAY_SIZE(mask->bits);
- const int bits_per_slot = sizeof(mask->bits[0]) * 8;
-
- const int table_size = ARRAY_SIZE(pcm_format_value_map);
-
- int slot_index, bit_index, table_index;
- table_index = 0;
- int num_written = 0;
- for (slot_index = 0; slot_index < num_slots && table_index < table_size;
- slot_index++) {
- unsigned bit_mask = 1;
- for (bit_index = 0;
- bit_index < bits_per_slot && table_index < table_size;
- bit_index++) {
- if ((mask->bits[slot_index] & bit_mask) != 0) {
- enum pcm_format format = pcm_format_value_map[table_index];
- /* Never return invalid (unrecognized) or 8-bit */
- if (format != PCM_FORMAT_INVALID && format != PCM_FORMAT_S8) {
- profile->formats[num_written++] = format;
- if (num_written == ARRAY_SIZE(profile->formats) - 1) {
- /* leave at least one PCM_FORMAT_INVALID at the end */
- return num_written;
- }
- }
- }
- bit_mask <<= 1;
- table_index++;
- }
- }
-
- return num_written;
-}
-
-static unsigned profile_enum_channel_counts(alsa_device_profile* profile, unsigned min, unsigned max)
-{
- static const unsigned std_channel_counts[] = {8, 4, 2, 1};
-
- unsigned num_counts = 0;
- unsigned index;
- /* TODO write a profile_test_channel_count() */
- /* Ensure there is at least one invalid channel count to terminate the channel counts array */
- for (index = 0; index < ARRAY_SIZE(std_channel_counts) &&
- num_counts < ARRAY_SIZE(profile->channel_counts) - 1;
- index++) {
- /* TODO Do we want a channel counts test? */
- if (std_channel_counts[index] >= min && std_channel_counts[index] <= max /* &&
- profile_test_channel_count(profile, channel_counts[index])*/) {
- profile->channel_counts[num_counts++] = std_channel_counts[index];
- }
- }
-
- return num_counts; /* return # of supported counts */
-}
-
-/*
- * Reads and decodes configuration info from the specified ALSA card/device.
- */
-static int read_alsa_device_config(alsa_device_profile * profile, struct pcm_config * config)
-{
- ALOGV("usb:audio_hw - read_alsa_device_config(c:%d d:%d t:0x%X)",
- profile->card, profile->device, profile->direction);
-
- if (profile->card < 0 || profile->device < 0) {
- return -EINVAL;
- }
-
- struct pcm_params * alsa_hw_params =
- pcm_params_get(profile->card, profile->device, profile->direction);
- if (alsa_hw_params == NULL) {
- return -EINVAL;
- }
-
- profile->min_period_size = pcm_params_get_min(alsa_hw_params, PCM_PARAM_PERIOD_SIZE);
- profile->max_period_size = pcm_params_get_max(alsa_hw_params, PCM_PARAM_PERIOD_SIZE);
-
- profile->min_channel_count = pcm_params_get_min(alsa_hw_params, PCM_PARAM_CHANNELS);
- profile->max_channel_count = pcm_params_get_max(alsa_hw_params, PCM_PARAM_CHANNELS);
-
- int ret = 0;
-
- /*
- * This Logging will be useful when testing new USB devices.
- */
-#ifdef LOG_PCM_PARAMS
- log_pcm_params(alsa_hw_params);
-#endif
-
- config->channels = pcm_params_get_min(alsa_hw_params, PCM_PARAM_CHANNELS);
- config->rate = pcm_params_get_min(alsa_hw_params, PCM_PARAM_RATE);
- config->period_size = profile_calc_min_period_size(profile, config->rate);
- config->period_count = pcm_params_get_min(alsa_hw_params, PCM_PARAM_PERIODS);
- config->format = get_pcm_format_for_mask(pcm_params_get_mask(alsa_hw_params, PCM_PARAM_FORMAT));
-#ifdef LOG_PCM_PARAMS
- log_pcm_config(config, "read_alsa_device_config");
-#endif
- if (config->format == PCM_FORMAT_INVALID) {
- ret = -EINVAL;
- }
-
- pcm_params_free(alsa_hw_params);
-
- return ret;
-}
-
-bool profile_read_device_info(alsa_device_profile* profile)
-{
- if (!profile_is_initialized(profile)) {
- return false;
- }
-
- /* let's get some defaults */
- read_alsa_device_config(profile, &profile->default_config);
- ALOGV("default_config chans:%d rate:%d format:%d count:%d size:%d",
- profile->default_config.channels, profile->default_config.rate,
- profile->default_config.format, profile->default_config.period_count,
- profile->default_config.period_size);
-
- struct pcm_params * alsa_hw_params = pcm_params_get(profile->card,
- profile->device,
- profile->direction);
- if (alsa_hw_params == NULL) {
- return false;
- }
-
- /* Formats */
- struct pcm_mask * format_mask = pcm_params_get_mask(alsa_hw_params, PCM_PARAM_FORMAT);
- profile_enum_sample_formats(profile, format_mask);
-
- /* Channels */
- profile_enum_channel_counts(
- profile, pcm_params_get_min(alsa_hw_params, PCM_PARAM_CHANNELS),
- pcm_params_get_max(alsa_hw_params, PCM_PARAM_CHANNELS));
-
- /* Sample Rates */
- profile_enum_sample_rates(
- profile, pcm_params_get_min(alsa_hw_params, PCM_PARAM_RATE),
- pcm_params_get_max(alsa_hw_params, PCM_PARAM_RATE));
-
- profile->is_valid = true;
-
- return true;
-}
-
-char * profile_get_sample_rate_strs(alsa_device_profile* profile)
-{
- char buffer[128];
- buffer[0] = '\0';
- int buffSize = ARRAY_SIZE(buffer);
-
- char numBuffer[32];
-
- int numEntries = 0;
- unsigned index;
- for (index = 0; profile->sample_rates[index] != 0; index++) {
- if (numEntries++ != 0) {
- strncat(buffer, "|", buffSize);
- }
- snprintf(numBuffer, sizeof(numBuffer), "%u", profile->sample_rates[index]);
- strncat(buffer, numBuffer, buffSize);
- }
-
- return strdup(buffer);
-}
-
-char * profile_get_format_strs(alsa_device_profile* profile)
-{
- /* TODO remove this hack when we have support for input in non PCM16 formats */
- if (profile->direction == PCM_IN) {
- return strdup("AUDIO_FORMAT_PCM_16_BIT");
- }
-
- char buffer[128];
- buffer[0] = '\0';
- int buffSize = ARRAY_SIZE(buffer);
-
- int numEntries = 0;
- unsigned index = 0;
- for (index = 0; profile->formats[index] != PCM_FORMAT_INVALID; index++) {
- if (numEntries++ != 0) {
- strncat(buffer, "|", buffSize);
- }
- strncat(buffer, format_string_map[profile->formats[index]], buffSize);
- }
-
- return strdup(buffer);
-}
-
-char * profile_get_channel_count_strs(alsa_device_profile* profile)
-{
- static const char * const out_chans_strs[] = {
- /* 0 */"AUDIO_CHANNEL_NONE", /* will never be taken as this is a terminator */
- /* 1 */"AUDIO_CHANNEL_OUT_MONO",
- /* 2 */"AUDIO_CHANNEL_OUT_STEREO",
- /* 3 */ /* "AUDIO_CHANNEL_OUT_STEREO|AUDIO_CHANNEL_OUT_FRONT_CENTER" */ NULL,
- /* 4 */"AUDIO_CHANNEL_OUT_QUAD",
- /* 5 */ /* "AUDIO_CHANNEL_OUT_QUAD|AUDIO_CHANNEL_OUT_FRONT_CENTER" */ NULL,
- /* 6 */"AUDIO_CHANNEL_OUT_5POINT1",
- /* 7 */ /* "AUDIO_CHANNEL_OUT_5POINT1|AUDIO_CHANNEL_OUT_BACK_CENTER" */ NULL,
- /* 8 */"AUDIO_CHANNEL_OUT_7POINT1",
- /* channel counts greater than this not considered */
- };
-
- static const char * const in_chans_strs[] = {
- /* 0 */"AUDIO_CHANNEL_NONE", /* will never be taken as this is a terminator */
- /* 1 */"AUDIO_CHANNEL_IN_MONO",
- /* 2 */"AUDIO_CHANNEL_IN_STEREO",
- /* channel counts greater than this not considered */
- };
-
- const bool isOutProfile = profile->direction == PCM_OUT;
-
- const char * const * const names_array = isOutProfile ? out_chans_strs : in_chans_strs;
- const size_t names_size = isOutProfile ? ARRAY_SIZE(out_chans_strs)
- : ARRAY_SIZE(in_chans_strs);
-
- char buffer[256]; /* caution, may need to be expanded */
- buffer[0] = '\0';
- const int buffer_size = ARRAY_SIZE(buffer);
- int num_entries = 0;
- /* We currently support MONO and STEREO, and always report STEREO but some (many)
- * USB Audio Devices may only announce support for MONO (a headset mic for example), or
- * The total number of output channels. SO, if the device itself doesn't explicitly
- * support STEREO, append to the channel config strings we are generating.
- */
- bool stereo_present = false;
- unsigned index;
- unsigned channel_count;
-
- for (index = 0; (channel_count = profile->channel_counts[index]) != 0; index++) {
- stereo_present = stereo_present || channel_count == 2;
- if (channel_count < names_size && names_array[channel_count] != NULL) {
- if (num_entries++ != 0) {
- strncat(buffer, "|", buffer_size);
- }
- strncat(buffer, names_array[channel_count], buffer_size);
- }
- }
-
- /* emulated modes:
- * always expose stereo as we can emulate it for PCM_OUT
- */
- if (!stereo_present) {
- if (num_entries++ != 0) {
- strncat(buffer, "|", buffer_size);
- }
- strncat(buffer, names_array[2], buffer_size); /* stereo */
- }
-
- return strdup(buffer);
-}
diff --git a/modules/usbaudio/alsa_device_profile.h b/modules/usbaudio/alsa_device_profile.h
deleted file mode 100644
index 2c0da39..0000000
--- a/modules/usbaudio/alsa_device_profile.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (C) 2014 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 ANDROID_HARDWARE_LIBHARDWARE_MODULES_USBAUDIO_ALSA_DEVICE_PROFILE_H
-#define ANDROID_HARDWARE_LIBHARDWARE_MODULES_USBAUDIO_ALSA_DEVICE_PROFILE_H
-
-#include <stdbool.h>
-
-#include <tinyalsa/asoundlib.h>
-
-#define MAX_PROFILE_FORMATS 6 /* We long support the 5 standard formats defined
- * in asound.h, so we just need this to be 1 more
- * than that */
-#define MAX_PROFILE_SAMPLE_RATES 10 /* this number needs to be 1 more than the number of
- * standard formats in std_sample_rates[]
- * (in alsa_device_profile.c) */
-#define MAX_PROFILE_CHANNEL_COUNTS 5 /* this number need to be 1 more than the number of
- * standard channel formats in std_channel_counts[]
- * (in alsa_device_profile.c) */
-
-#define DEFAULT_SAMPLE_RATE 44100
-#define DEFAULT_SAMPLE_FORMAT PCM_FORMAT_S16_LE
-#define DEFAULT_CHANNEL_COUNT 2
-
-typedef struct {
- int card;
- int device;
- int direction; /* PCM_OUT or PCM_IN */
-
- enum pcm_format formats[MAX_PROFILE_FORMATS];
-
- unsigned sample_rates[MAX_PROFILE_SAMPLE_RATES];
-
- unsigned channel_counts[MAX_PROFILE_CHANNEL_COUNTS];
-
- bool is_valid;
-
- /* read from the hardware device */
- struct pcm_config default_config;
-
- unsigned min_period_size;
- unsigned max_period_size;
-
- unsigned min_channel_count;
- unsigned max_channel_count;
-} alsa_device_profile;
-
-void profile_init(alsa_device_profile* profile, int direction);
-bool profile_is_initialized(alsa_device_profile* profile);
-bool profile_is_valid(alsa_device_profile* profile);
-bool profile_is_cached_for(alsa_device_profile* profile, int card, int device);
-void profile_decache(alsa_device_profile* profile);
-
-bool profile_read_device_info(alsa_device_profile* profile);
-
-/* Audio Config Strings Methods */
-char * profile_get_sample_rate_strs(alsa_device_profile* profile);
-char * profile_get_format_strs(alsa_device_profile* profile);
-char * profile_get_channel_count_strs(alsa_device_profile* profile);
-
-/* Sample Rate Methods */
-unsigned profile_get_default_sample_rate(alsa_device_profile* profile);
-bool profile_is_sample_rate_valid(alsa_device_profile* profile, unsigned rate);
-
-/* Format Methods */
-enum pcm_format profile_get_default_format(alsa_device_profile* profile);
-bool profile_is_format_valid(alsa_device_profile* profile, enum pcm_format fmt);
-
-/* Channel Methods */
-unsigned profile_get_default_channel_count(alsa_device_profile* profile);
-bool profile_is_channel_count_valid(alsa_device_profile* profile, unsigned count);
-
-/* Utility */
-unsigned profile_calc_min_period_size(alsa_device_profile* profile, unsigned sample_rate);
-unsigned int profile_get_period_size(alsa_device_profile* profile, unsigned sample_rate);
-
-#endif /* ANDROID_HARDWARE_LIBHARDWARE_MODULES_USBAUDIO_ALSA_DEVICE_PROFILE_H */
diff --git a/modules/usbaudio/alsa_device_proxy.c b/modules/usbaudio/alsa_device_proxy.c
deleted file mode 100644
index 081c05b..0000000
--- a/modules/usbaudio/alsa_device_proxy.c
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright (C) 2014 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.
- */
-
-#define LOG_TAG "alsa_device_proxy"
-/*#define LOG_NDEBUG 0*/
-/*#define LOG_PCM_PARAMS 0*/
-
-#include <log/log.h>
-
-#include "alsa_device_proxy.h"
-
-#include "logging.h"
-
-#define DEFAULT_PERIOD_SIZE 1024
-#define DEFAULT_PERIOD_COUNT 2
-
-void proxy_prepare(alsa_device_proxy * proxy, alsa_device_profile* profile,
- struct pcm_config * config)
-{
- ALOGV("proxy_prepare()");
-
- proxy->profile = profile;
-
-#ifdef LOG_PCM_PARAMS
- log_pcm_config(config, "proxy_setup()");
-#endif
-
- proxy->alsa_config.format =
- config->format != PCM_FORMAT_INVALID && profile_is_format_valid(profile, config->format)
- ? config->format : profile->default_config.format;
- proxy->alsa_config.rate =
- config->rate != 0 && profile_is_sample_rate_valid(profile, config->rate)
- ? config->rate : profile->default_config.rate;
- proxy->alsa_config.channels =
- config->channels != 0 && profile_is_channel_count_valid(profile, config->channels)
- ? config->channels : profile->default_config.channels;
-
- proxy->alsa_config.period_count = profile->default_config.period_count;
- proxy->alsa_config.period_size =
- profile_get_period_size(proxy->profile, proxy->alsa_config.rate);
-
- // Hack for USB accessory audio.
- // Here we set the correct value for period_count if tinyalsa fails to get it from the
- // f_audio_source driver.
- if (proxy->alsa_config.period_count == 0) {
- proxy->alsa_config.period_count = 4;
- }
-
- proxy->pcm = NULL;
-}
-
-int proxy_open(alsa_device_proxy * proxy)
-{
- alsa_device_profile* profile = proxy->profile;
- ALOGV("proxy_open(card:%d device:%d %s)", profile->card, profile->device,
- profile->direction == PCM_OUT ? "PCM_OUT" : "PCM_IN");
-
- proxy->pcm = pcm_open(profile->card, profile->device, profile->direction, &proxy->alsa_config);
- if (proxy->pcm == NULL) {
- return -ENOMEM;
- }
-
- if (!pcm_is_ready(proxy->pcm)) {
- ALOGE("[%s] proxy_open() pcm_open() failed: %s", LOG_TAG, pcm_get_error(proxy->pcm));
-#ifdef LOG_PCM_PARAMS
- log_pcm_config(&proxy->alsa_config, "config");
-#endif
- pcm_close(proxy->pcm);
- proxy->pcm = NULL;
- return -ENOMEM;
- }
-
- return 0;
-}
-
-void proxy_close(alsa_device_proxy * proxy)
-{
- ALOGV("proxy_close() [pcm:%p]", proxy->pcm);
-
- if (proxy->pcm != NULL) {
- pcm_close(proxy->pcm);
- proxy->pcm = NULL;
- }
-}
-
-/*
- * Sample Rate
- */
-unsigned proxy_get_sample_rate(const alsa_device_proxy * proxy)
-{
- return proxy->alsa_config.rate;
-}
-
-/*
- * Format
- */
-enum pcm_format proxy_get_format(const alsa_device_proxy * proxy)
-{
- return proxy->alsa_config.format;
-}
-
-/*
- * Channel Count
- */
-unsigned proxy_get_channel_count(const alsa_device_proxy * proxy)
-{
- return proxy->alsa_config.channels;
-}
-
-/*
- * Other
- */
-unsigned int proxy_get_period_size(const alsa_device_proxy * proxy)
-{
- return proxy->alsa_config.period_size;
-}
-
-unsigned int proxy_get_period_count(const alsa_device_proxy * proxy)
-{
- return proxy->alsa_config.period_count;
-}
-
-unsigned proxy_get_latency(const alsa_device_proxy * proxy)
-{
- return (proxy_get_period_size(proxy) * proxy_get_period_count(proxy) * 1000)
- / proxy_get_sample_rate(proxy);
-}
-
-/*
- * I/O
- */
-int proxy_write(const alsa_device_proxy * proxy, const void *data, unsigned int count)
-{
- return pcm_write(proxy->pcm, data, count);
-}
-
-int proxy_read(const alsa_device_proxy * proxy, void *data, unsigned int count)
-{
- return pcm_read(proxy->pcm, data, count);
-}
diff --git a/modules/usbaudio/alsa_device_proxy.h b/modules/usbaudio/alsa_device_proxy.h
deleted file mode 100644
index f090c56..0000000
--- a/modules/usbaudio/alsa_device_proxy.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2014 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 ANDROID_HARDWARE_LIBHARDWARE_MODULES_USBAUDIO_ALSA_DEVICE_PROXY_H
-#define ANDROID_HARDWARE_LIBHARDWARE_MODULES_USBAUDIO_ALSA_DEVICE_PROXY_H
-
-#include <tinyalsa/asoundlib.h>
-
-#include "alsa_device_profile.h"
-
-typedef struct {
- alsa_device_profile* profile;
-
- struct pcm_config alsa_config;
-
- struct pcm * pcm;
-} alsa_device_proxy;
-
-void proxy_prepare(alsa_device_proxy * proxy, alsa_device_profile * profile,
- struct pcm_config * config);
-
-unsigned proxy_get_sample_rate(const alsa_device_proxy * proxy);
-enum pcm_format proxy_get_format(const alsa_device_proxy * proxy);
-unsigned proxy_get_channel_count(const alsa_device_proxy * proxy);
-
-unsigned int proxy_get_period_size(const alsa_device_proxy * proxy);
-
-unsigned proxy_get_latency(const alsa_device_proxy * proxy);
-
-int proxy_open(alsa_device_proxy * proxy);
-void proxy_close(alsa_device_proxy * proxy);
-
-int proxy_write(const alsa_device_proxy * proxy, const void *data, unsigned int count);
-int proxy_read(const alsa_device_proxy * proxy, void *data, unsigned int count);
-
-#endif /* ANDROID_HARDWARE_LIBHARDWARE_MODULES_USBAUDIO_ALSA_DEVICE_PROXY_H */
diff --git a/modules/usbaudio/audio_hw.c b/modules/usbaudio/audio_hal.c
similarity index 91%
rename from modules/usbaudio/audio_hw.c
rename to modules/usbaudio/audio_hal.c
index 49c99af..3163424 100644
--- a/modules/usbaudio/audio_hw.c
+++ b/modules/usbaudio/audio_hal.c
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#define LOG_TAG "usb_audio_hw"
+#define LOG_TAG "modules.usbaudio.audio_hal"
/*#define LOG_NDEBUG 0*/
#include <errno.h>
@@ -51,7 +51,7 @@
#include "alsa_device_profile.h"
#include "alsa_device_proxy.h"
-#include "logging.h"
+#include "alsa_logging.h"
#define DEFAULT_INPUT_BUFFER_SIZE_MS 20
@@ -79,7 +79,7 @@
struct audio_device *dev; /* hardware information - only using this for the lock */
- alsa_device_profile * profile;
+ alsa_device_profile * profile; /* Points to the alsa_device_profile in the audio_device */
alsa_device_proxy proxy; /* state of the stream */
unsigned hal_channel_count; /* channel count exposed to AudioFlinger.
@@ -101,7 +101,7 @@
struct audio_device *dev; /* hardware information - only using this for the lock */
- alsa_device_profile * profile;
+ alsa_device_profile * profile; /* Points to the alsa_device_profile in the audio_device */
alsa_device_proxy proxy; /* state of the stream */
unsigned hal_channel_count; /* channel count exposed to AudioFlinger.
@@ -184,10 +184,43 @@
return num_in_samples * 2;
}
+/*
+ * Extract the card and device numbers from the supplied key/value pairs.
+ * kvpairs A null-terminated string containing the key/value pairs or card and device.
+ * i.e. "card=1;device=42"
+ * card A pointer to a variable to receive the parsed-out card number.
+ * device A pointer to a variable to receive the parsed-out device number.
+ * NOTE: The variables pointed to by card and device return -1 (undefined) if the
+ * associated key/value pair is not found in the provided string.
+ * Return true if the kvpairs string contain a card/device spec, false otherwise.
+ */
+static bool parse_card_device_params(const char *kvpairs, int *card, int *device)
+{
+ struct str_parms * parms = str_parms_create_str(kvpairs);
+ char value[32];
+ int param_val;
+
+ // initialize to "undefined" state.
+ *card = -1;
+ *device = -1;
+
+ param_val = str_parms_get_str(parms, "card", value, sizeof(value));
+ if (param_val >= 0) {
+ *card = atoi(value);
+ }
+
+ param_val = str_parms_get_str(parms, "device", value, sizeof(value));
+ if (param_val >= 0) {
+ *device = atoi(value);
+ }
+
+ str_parms_destroy(parms);
+
+ return *card >= 0 && *device >= 0;
+}
+
static char * device_get_parameters(alsa_device_profile * profile, const char * keys)
{
- ALOGV("usb:audio_hw::device_get_parameters() keys:%s", keys);
-
if (profile->card < 0 || profile->device < 0) {
return strdup("");
}
@@ -224,7 +257,7 @@
char* result_str = str_parms_to_str(result);
str_parms_destroy(result);
- ALOGV("usb:audio_hw::device_get_parameters = %s", result_str);
+ ALOGV("device_get_parameters = %s", result_str);
return result_str;
}
@@ -307,30 +340,25 @@
static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
{
- ALOGV("usb:audio_hw::out out_set_parameters() keys:%s", kvpairs);
+ ALOGV("out_set_parameters() keys:%s", kvpairs);
struct stream_out *out = (struct stream_out *)stream;
- char value[32];
- int param_val;
int routing = 0;
int ret_value = 0;
int card = -1;
int device = -1;
- struct str_parms * parms = str_parms_create_str(kvpairs);
+ if (!parse_card_device_params(kvpairs, &card, &device)) {
+ // nothing to do
+ return ret_value;
+ }
+
+ /* Lock the device because that is where the profile lives */
pthread_mutex_lock(&out->dev->lock);
pthread_mutex_lock(&out->lock);
- param_val = str_parms_get_str(parms, "card", value, sizeof(value));
- if (param_val >= 0)
- card = atoi(value);
-
- param_val = str_parms_get_str(parms, "device", value, sizeof(value));
- if (param_val >= 0)
- device = atoi(value);
-
- if (card >= 0 && device >= 0 && !profile_is_cached_for(out->profile, card, device)) {
+ if (!profile_is_cached_for(out->profile, card, device)) {
/* cannot read pcm device info if playback is active */
if (!out->standby)
ret_value = -ENOSYS;
@@ -349,7 +377,6 @@
pthread_mutex_unlock(&out->lock);
pthread_mutex_unlock(&out->dev->lock);
- str_parms_destroy(parms);
return ret_value;
}
@@ -382,8 +409,7 @@
/* must be called with hw device and output stream mutexes locked */
static int start_output_stream(struct stream_out *out)
{
- ALOGV("usb:audio_hw::out start_output_stream(card:%d device:%d)",
- out->profile->card, out->profile->device);
+ ALOGV("start_output_stream(card:%d device:%d)", out->profile->card, out->profile->device);
return proxy_open(&out->proxy);
}
@@ -480,10 +506,10 @@
audio_output_flags_t flags,
struct audio_config *config,
struct audio_stream_out **stream_out,
- const char *address __unused)
+ const char *address /*__unused*/)
{
- ALOGV("usb:audio_hw::out adev_open_output_stream() handle:0x%X, device:0x%X, flags:0x%X",
- handle, devices, flags);
+ ALOGV("adev_open_output_stream() handle:0x%X, device:0x%X, flags:0x%X, addr:%s",
+ handle, devices, flags, address);
struct audio_device *adev = (struct audio_device *)dev;
@@ -514,13 +540,20 @@
out->stream.get_next_write_timestamp = out_get_next_write_timestamp;
out->dev = adev;
-
+ pthread_mutex_lock(&adev->lock);
out->profile = &adev->out_profile;
// build this to hand to the alsa_device_proxy
struct pcm_config proxy_config;
memset(&proxy_config, 0, sizeof(proxy_config));
+ /* Pull out the card/device pair */
+ parse_card_device_params(address, &(out->profile->card), &(out->profile->device));
+
+ profile_read_device_info(out->profile);
+
+ pthread_mutex_unlock(&adev->lock);
+
int ret = 0;
/* Rate */
@@ -585,8 +618,8 @@
static void adev_close_output_stream(struct audio_hw_device *dev,
struct audio_stream_out *stream)
{
- ALOGV("usb:audio_hw::out adev_close_output_stream()");
struct stream_out *out = (struct stream_out *)stream;
+ ALOGV("adev_close_output_stream(c:%d d:%d)", out->profile->card, out->profile->device);
/* Close the pcm device */
out_standby(&stream->common);
@@ -680,7 +713,7 @@
static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
{
- ALOGV("usb: audio_hw::in in_set_parameters() keys:%s", kvpairs);
+ ALOGV("in_set_parameters() keys:%s", kvpairs);
struct stream_in *in = (struct stream_in *)stream;
@@ -691,20 +724,14 @@
int card = -1;
int device = -1;
- struct str_parms * parms = str_parms_create_str(kvpairs);
+ if (!parse_card_device_params(kvpairs, &card, &device)) {
+ // nothing to do
+ return ret_value;
+ }
pthread_mutex_lock(&in->dev->lock);
pthread_mutex_lock(&in->lock);
- /* Device Connection Message ("card=1,device=0") */
- param_val = str_parms_get_str(parms, "card", value, sizeof(value));
- if (param_val >= 0)
- card = atoi(value);
-
- param_val = str_parms_get_str(parms, "device", value, sizeof(value));
- if (param_val >= 0)
- device = atoi(value);
-
if (card >= 0 && device >= 0 && !profile_is_cached_for(in->profile, card, device)) {
/* cannot read pcm device info if playback is active */
if (!in->standby)
@@ -725,8 +752,6 @@
pthread_mutex_unlock(&in->lock);
pthread_mutex_unlock(&in->dev->lock);
- str_parms_destroy(parms);
-
return ret_value;
}
@@ -763,8 +788,7 @@
/* must be called with hw device and output stream mutexes locked */
static int start_input_stream(struct stream_in *in)
{
- ALOGV("usb:audio_hw::start_input_stream(card:%d device:%d)",
- in->profile->card, in->profile->device);
+ ALOGV("ustart_input_stream(card:%d device:%d)", in->profile->card, in->profile->device);
return proxy_open(&in->proxy);
}
@@ -790,7 +814,6 @@
}
pthread_mutex_unlock(&in->dev->lock);
-
alsa_device_profile * profile = in->profile;
/*
@@ -844,6 +867,8 @@
num_read_buff_bytes =
convert_32_to_16(read_buff, num_read_buff_bytes / 4, out_buff);
} else {
+ LOG_ALWAYS_FATAL("Unsupported format");
+ num_read_buff_bytes = 0;
goto err;
}
}
@@ -867,8 +892,8 @@
/* no need to acquire in->dev->lock to read mic_muted here as we don't change its state */
if (num_read_buff_bytes > 0 && in->dev->mic_muted)
memset(buffer, 0, num_read_buff_bytes);
- } else if (ret == -ENODEV) {
- num_read_buff_bytes = 0; //reset the value after USB headset is unplugged
+ } else {
+ num_read_buff_bytes = 0; // reset the value after USB headset is unplugged
}
err:
@@ -888,10 +913,10 @@
struct audio_config *config,
struct audio_stream_in **stream_in,
audio_input_flags_t flags __unused,
- const char *address __unused,
+ const char *address /*__unused*/,
audio_source_t source __unused)
{
- ALOGV("usb: in adev_open_input_stream() rate:%" PRIu32 ", chanMask:0x%" PRIX32 ", fmt:%" PRIu8,
+ ALOGV("in adev_open_input_stream() rate:%" PRIu32 ", chanMask:0x%" PRIX32 ", fmt:%" PRIu8,
config->sample_rate, config->channel_mask, config->format);
struct stream_in *in = (struct stream_in *)calloc(1, sizeof(struct stream_in));
@@ -919,12 +944,19 @@
in->stream.get_input_frames_lost = in_get_input_frames_lost;
in->dev = (struct audio_device *)dev;
+ pthread_mutex_lock(&in->dev->lock);
in->profile = &in->dev->in_profile;
struct pcm_config proxy_config;
memset(&proxy_config, 0, sizeof(proxy_config));
+ /* Pull out the card/device pair */
+ parse_card_device_params(address, &(in->profile->card), &(in->profile->device));
+
+ profile_read_device_info(in->profile);
+ pthread_mutex_unlock(&in->dev->lock);
+
/* Rate */
if (config->sample_rate == 0) {
proxy_config.rate = config->sample_rate = profile_get_default_sample_rate(in->profile);
@@ -995,43 +1027,6 @@
*/
static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
{
- ALOGV("audio_hw:usb adev_set_parameters(%s)", kvpairs);
-
- struct audio_device * adev = (struct audio_device *)dev;
-
- char value[32];
- int param_val;
-
- struct str_parms * parms = str_parms_create_str(kvpairs);
-
- /* Check for the "disconnect" message */
- param_val = str_parms_get_str(parms, "disconnect", value, sizeof(value));
- if (param_val >= 0) {
- audio_devices_t device = (audio_devices_t)atoi(value);
-
- param_val = str_parms_get_str(parms, "card", value, sizeof(value));
- int alsa_card = param_val >= 0 ? atoi(value) : -1;
-
- param_val = str_parms_get_str(parms, "device", value, sizeof(value));
- int alsa_device = param_val >= 0 ? atoi(value) : -1;
-
- if (alsa_card >= 0 && alsa_device >= 0) {
- /* "decache" the profile */
- pthread_mutex_lock(&adev->lock);
- if (device == AUDIO_DEVICE_OUT_USB_DEVICE &&
- profile_is_cached_for(&adev->out_profile, alsa_card, alsa_device)) {
- profile_decache(&adev->out_profile);
- }
- if (device == AUDIO_DEVICE_IN_USB_DEVICE &&
- profile_is_cached_for(&adev->in_profile, alsa_card, alsa_device)) {
- profile_decache(&adev->in_profile);
- }
- pthread_mutex_unlock(&adev->lock);
- }
- }
-
- str_parms_destroy(parms);
-
return 0;
}
diff --git a/modules/usbaudio/format.c b/modules/usbaudio/format.c
deleted file mode 100644
index 6aac1d3..0000000
--- a/modules/usbaudio/format.c
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Copyright (C) 2014 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.
- */
-
-#define LOG_TAG "usb_profile"
-/*#define LOG_NDEBUG 0*/
-
-#include "format.h"
-
-#include <tinyalsa/asoundlib.h>
-
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
-
-/*
- * Maps from bit position in pcm_mask to AUDIO_ format constants.
- */
-static audio_format_t const format_value_map[] = {
- AUDIO_FORMAT_PCM_8_BIT, /* 00 - SNDRV_PCM_FORMAT_S8 */
- AUDIO_FORMAT_PCM_8_BIT, /* 01 - SNDRV_PCM_FORMAT_U8 */
- AUDIO_FORMAT_PCM_16_BIT, /* 02 - SNDRV_PCM_FORMAT_S16_LE */
- AUDIO_FORMAT_INVALID, /* 03 - SNDRV_PCM_FORMAT_S16_BE */
- AUDIO_FORMAT_INVALID, /* 04 - SNDRV_PCM_FORMAT_U16_LE */
- AUDIO_FORMAT_INVALID, /* 05 - SNDRV_PCM_FORMAT_U16_BE */
- AUDIO_FORMAT_INVALID, /* 06 - SNDRV_PCM_FORMAT_S24_LE */
- AUDIO_FORMAT_INVALID, /* 07 - SNDRV_PCM_FORMAT_S24_BE */
- AUDIO_FORMAT_INVALID, /* 08 - SNDRV_PCM_FORMAT_U24_LE */
- AUDIO_FORMAT_INVALID, /* 09 - SNDRV_PCM_FORMAT_U24_BE */
- AUDIO_FORMAT_PCM_32_BIT, /* 10 - SNDRV_PCM_FORMAT_S32_LE */
- AUDIO_FORMAT_INVALID, /* 11 - SNDRV_PCM_FORMAT_S32_BE */
- AUDIO_FORMAT_INVALID, /* 12 - SNDRV_PCM_FORMAT_U32_LE */
- AUDIO_FORMAT_INVALID, /* 13 - SNDRV_PCM_FORMAT_U32_BE */
- AUDIO_FORMAT_PCM_FLOAT, /* 14 - SNDRV_PCM_FORMAT_FLOAT_LE */
- AUDIO_FORMAT_INVALID, /* 15 - SNDRV_PCM_FORMAT_FLOAT_BE */
- AUDIO_FORMAT_INVALID, /* 16 - SNDRV_PCM_FORMAT_FLOAT64_LE */
- AUDIO_FORMAT_INVALID, /* 17 - SNDRV_PCM_FORMAT_FLOAT64_BE */
- AUDIO_FORMAT_INVALID, /* 18 - SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE */
- AUDIO_FORMAT_INVALID, /* 19 - SNDRV_PCM_FORMAT_IEC958_SUBFRAME_BE */
- AUDIO_FORMAT_INVALID, /* 20 - SNDRV_PCM_FORMAT_MU_LAW */
- AUDIO_FORMAT_INVALID, /* 21 - SNDRV_PCM_FORMAT_A_LAW */
- AUDIO_FORMAT_INVALID, /* 22 - SNDRV_PCM_FORMAT_IMA_ADPCM */
- AUDIO_FORMAT_INVALID, /* 23 - SNDRV_PCM_FORMAT_MPEG */
- AUDIO_FORMAT_INVALID, /* 24 - SNDRV_PCM_FORMAT_GSM */
- AUDIO_FORMAT_INVALID, /* 25 -> 30 (not assigned) */
- AUDIO_FORMAT_INVALID,
- AUDIO_FORMAT_INVALID,
- AUDIO_FORMAT_INVALID,
- AUDIO_FORMAT_INVALID,
- AUDIO_FORMAT_INVALID,
- AUDIO_FORMAT_INVALID, /* 31 - SNDRV_PCM_FORMAT_SPECIAL */
- AUDIO_FORMAT_PCM_24_BIT_PACKED, /* 32 - SNDRV_PCM_FORMAT_S24_3LE */
- AUDIO_FORMAT_INVALID, /* 33 - SNDRV_PCM_FORMAT_S24_3BE */
- AUDIO_FORMAT_INVALID, /* 34 - SNDRV_PCM_FORMAT_U24_3LE */
- AUDIO_FORMAT_INVALID, /* 35 - SNDRV_PCM_FORMAT_U24_3BE */
- AUDIO_FORMAT_INVALID, /* 36 - SNDRV_PCM_FORMAT_S20_3LE */
- AUDIO_FORMAT_INVALID, /* 37 - SNDRV_PCM_FORMAT_S20_3BE */
- AUDIO_FORMAT_INVALID, /* 38 - SNDRV_PCM_FORMAT_U20_3LE */
- AUDIO_FORMAT_INVALID, /* 39 - SNDRV_PCM_FORMAT_U20_3BE */
- AUDIO_FORMAT_INVALID, /* 40 - SNDRV_PCM_FORMAT_S18_3LE */
- AUDIO_FORMAT_INVALID, /* 41 - SNDRV_PCM_FORMAT_S18_3BE */
- AUDIO_FORMAT_INVALID, /* 42 - SNDRV_PCM_FORMAT_U18_3LE */
- AUDIO_FORMAT_INVALID, /* 43 - SNDRV_PCM_FORMAT_U18_3BE */
- AUDIO_FORMAT_INVALID, /* 44 - SNDRV_PCM_FORMAT_G723_24 */
- AUDIO_FORMAT_INVALID, /* 45 - SNDRV_PCM_FORMAT_G723_24_1B */
- AUDIO_FORMAT_INVALID, /* 46 - SNDRV_PCM_FORMAT_G723_40 */
- AUDIO_FORMAT_INVALID, /* 47 - SNDRV_PCM_FORMAT_G723_40_1B */
- AUDIO_FORMAT_INVALID, /* 48 - SNDRV_PCM_FORMAT_DSD_U8 */
- AUDIO_FORMAT_INVALID /* 49 - SNDRV_PCM_FORMAT_DSD_U16_LE */
-};
-
-audio_format_t get_format_for_mask(struct pcm_mask* mask)
-{
- int num_slots = sizeof(mask->bits) / sizeof(mask->bits[0]);
- int bits_per_slot = sizeof(mask->bits[0]) * 8;
-
- int table_size = sizeof(format_value_map) / sizeof(format_value_map[0]);
-
- int slot_index, bit_index, table_index;
- table_index = 0;
- int num_written = 0;
- for (slot_index = 0; slot_index < num_slots; slot_index++) {
- unsigned bit_mask = 1;
- for (bit_index = 0; bit_index < bits_per_slot; bit_index++) {
- /* don't return b-bit formats even if they are supported */
- if (table_index >= 2 && (mask->bits[slot_index] & bit_mask) != 0) {
- /* just return the first one */
- return table_index < table_size
- ? format_value_map[table_index]
- : AUDIO_FORMAT_INVALID;
- }
- bit_mask <<= 1;
- table_index++;
- }
- }
-
- return AUDIO_FORMAT_INVALID;
-}
-
-/*
- * Maps from bit position in pcm_mask to PCM_ format constants.
- */
-int8_t const pcm_format_value_map[50] = {
- PCM_FORMAT_S8, /* 00 - SNDRV_PCM_FORMAT_S8 */
- PCM_FORMAT_INVALID, /* 01 - SNDRV_PCM_FORMAT_U8 */
- PCM_FORMAT_S16_LE, /* 02 - SNDRV_PCM_FORMAT_S16_LE */
- PCM_FORMAT_INVALID, /* 03 - SNDRV_PCM_FORMAT_S16_BE */
- PCM_FORMAT_INVALID, /* 04 - SNDRV_PCM_FORMAT_U16_LE */
- PCM_FORMAT_INVALID, /* 05 - SNDRV_PCM_FORMAT_U16_BE */
- PCM_FORMAT_S24_3LE, /* 06 - SNDRV_PCM_FORMAT_S24_LE */
- PCM_FORMAT_INVALID, /* 07 - SNDRV_PCM_FORMAT_S24_BE */
- PCM_FORMAT_INVALID, /* 08 - SNDRV_PCM_FORMAT_U24_LE */
- PCM_FORMAT_INVALID, /* 09 - SNDRV_PCM_FORMAT_U24_BE */
- PCM_FORMAT_S32_LE, /* 10 - SNDRV_PCM_FORMAT_S32_LE */
- PCM_FORMAT_INVALID, /* 11 - SNDRV_PCM_FORMAT_S32_BE */
- PCM_FORMAT_INVALID, /* 12 - SNDRV_PCM_FORMAT_U32_LE */
- PCM_FORMAT_INVALID, /* 13 - SNDRV_PCM_FORMAT_U32_BE */
- PCM_FORMAT_INVALID, /* 14 - SNDRV_PCM_FORMAT_FLOAT_LE */
- PCM_FORMAT_INVALID, /* 15 - SNDRV_PCM_FORMAT_FLOAT_BE */
- PCM_FORMAT_INVALID, /* 16 - SNDRV_PCM_FORMAT_FLOAT64_LE */
- PCM_FORMAT_INVALID, /* 17 - SNDRV_PCM_FORMAT_FLOAT64_BE */
- PCM_FORMAT_INVALID, /* 18 - SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE */
- PCM_FORMAT_INVALID, /* 19 - SNDRV_PCM_FORMAT_IEC958_SUBFRAME_BE */
- PCM_FORMAT_INVALID, /* 20 - SNDRV_PCM_FORMAT_MU_LAW */
- PCM_FORMAT_INVALID, /* 21 - SNDRV_PCM_FORMAT_A_LAW */
- PCM_FORMAT_INVALID, /* 22 - SNDRV_PCM_FORMAT_IMA_ADPCM */
- PCM_FORMAT_INVALID, /* 23 - SNDRV_PCM_FORMAT_MPEG */
- PCM_FORMAT_INVALID, /* 24 - SNDRV_PCM_FORMAT_GSM */
- PCM_FORMAT_INVALID, /* 25 -> 30 (not assigned) */
- PCM_FORMAT_INVALID,
- PCM_FORMAT_INVALID,
- PCM_FORMAT_INVALID,
- PCM_FORMAT_INVALID,
- PCM_FORMAT_INVALID,
- PCM_FORMAT_INVALID, /* 31 - SNDRV_PCM_FORMAT_SPECIAL */
- PCM_FORMAT_S24_3LE, /* 32 - SNDRV_PCM_FORMAT_S24_3LE */ /* ??? */
- PCM_FORMAT_INVALID, /* 33 - SNDRV_PCM_FORMAT_S24_3BE */
- PCM_FORMAT_INVALID, /* 34 - SNDRV_PCM_FORMAT_U24_3LE */
- PCM_FORMAT_INVALID, /* 35 - SNDRV_PCM_FORMAT_U24_3BE */
- PCM_FORMAT_INVALID, /* 36 - SNDRV_PCM_FORMAT_S20_3LE */
- PCM_FORMAT_INVALID, /* 37 - SNDRV_PCM_FORMAT_S20_3BE */
- PCM_FORMAT_INVALID, /* 38 - SNDRV_PCM_FORMAT_U20_3LE */
- PCM_FORMAT_INVALID, /* 39 - SNDRV_PCM_FORMAT_U20_3BE */
- PCM_FORMAT_INVALID, /* 40 - SNDRV_PCM_FORMAT_S18_3LE */
- PCM_FORMAT_INVALID, /* 41 - SNDRV_PCM_FORMAT_S18_3BE */
- PCM_FORMAT_INVALID, /* 42 - SNDRV_PCM_FORMAT_U18_3LE */
- PCM_FORMAT_INVALID, /* 43 - SNDRV_PCM_FORMAT_U18_3BE */
- PCM_FORMAT_INVALID, /* 44 - SNDRV_PCM_FORMAT_G723_24 */
- PCM_FORMAT_INVALID, /* 45 - SNDRV_PCM_FORMAT_G723_24_1B */
- PCM_FORMAT_INVALID, /* 46 - SNDRV_PCM_FORMAT_G723_40 */
- PCM_FORMAT_INVALID, /* 47 - SNDRV_PCM_FORMAT_G723_40_1B */
- PCM_FORMAT_INVALID, /* 48 - SNDRV_PCM_FORMAT_DSD_U8 */
- PCM_FORMAT_INVALID /* 49 - SNDRV_PCM_FORMAT_DSD_U16_LE */
-};
-
-/*
- * Scans the provided format mask and returns the first non-8 bit sample
- * format supported by the devices.
- */
-enum pcm_format get_pcm_format_for_mask(struct pcm_mask* mask)
-{
- int num_slots = ARRAY_SIZE(mask->bits);
- int bits_per_slot = sizeof(mask->bits[0]) * 8;
-
- int table_size = ARRAY_SIZE(pcm_format_value_map);
-
- int slot_index, bit_index, table_index;
- table_index = 0;
- int num_written = 0;
- for (slot_index = 0; slot_index < num_slots && table_index < table_size; slot_index++) {
- unsigned bit_mask = 1;
- for (bit_index = 0; bit_index < bits_per_slot && table_index < table_size; bit_index++) {
- /* skip any 8-bit formats */
- if (table_index >= 2 && (mask->bits[slot_index] & bit_mask) != 0) {
- /* just return the first one which will be at least 16-bit */
- return (int)pcm_format_value_map[table_index];
- }
- bit_mask <<= 1;
- table_index++;
- }
- }
-
- return PCM_FORMAT_INVALID;
-}
diff --git a/modules/usbaudio/format.h b/modules/usbaudio/format.h
deleted file mode 100644
index e23935e..0000000
--- a/modules/usbaudio/format.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2014 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 ANDROID_HARDWARE_LIBHARDWARE_MODULES_USBAUDIO_FORMAT_H
-#define ANDROID_HARDWARE_LIBHARDWARE_MODULES_USBAUDIO_FORMAT_H
-
-#include <system/audio.h>
-
-#include <tinyalsa/asoundlib.h>
-
-audio_format_t get_format_for_mask(struct pcm_mask* mask);
-enum pcm_format get_pcm_format_for_mask(struct pcm_mask* mask);
-
-#endif /* ANDROID_HARDWARE_LIBHARDWARE_MODULES_USBAUDIO_FORMAT_H */
diff --git a/modules/usbaudio/logging.c b/modules/usbaudio/logging.c
deleted file mode 100644
index 0a05511..0000000
--- a/modules/usbaudio/logging.c
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright (C) 2014 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.
- */
-
-#define LOG_TAG "usb_logging"
-/*#define LOG_NDEBUG 0*/
-
-#include <string.h>
-
-#include <log/log.h>
-
-#include "logging.h"
-
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
-
-/*
- * Logging
- */
-void log_pcm_mask(const char* mask_name, struct pcm_mask* mask)
-{
- const size_t num_slots = ARRAY_SIZE(mask->bits);
- const size_t bits_per_slot = (sizeof(mask->bits[0]) * 8);
- const size_t chars_per_slot = (bits_per_slot + 1); /* comma */
-
- const size_t BUFF_SIZE =
- (num_slots * chars_per_slot + 2 + 1); /* brackets and null-terminator */
- char buff[BUFF_SIZE];
- buff[0] = '\0';
-
- size_t slot_index, bit_index;
- strcat(buff, "[");
- for (slot_index = 0; slot_index < num_slots; slot_index++) {
- unsigned bit_mask = 1;
- for (bit_index = 0; bit_index < bits_per_slot; bit_index++) {
- strcat(buff, (mask->bits[slot_index] & bit_mask) != 0 ? "1" : "0");
- bit_mask <<= 1;
- }
- if (slot_index < num_slots - 1) {
- strcat(buff, ",");
- }
- }
- strcat(buff, "]");
-
- ALOGV("%s: mask:%s", mask_name, buff);
-}
-
-void log_pcm_params(struct pcm_params * alsa_hw_params)
-{
- ALOGV("usb:audio_hw - PCM_PARAM_SAMPLE_BITS min:%u, max:%u",
- pcm_params_get_min(alsa_hw_params, PCM_PARAM_SAMPLE_BITS),
- pcm_params_get_max(alsa_hw_params, PCM_PARAM_SAMPLE_BITS));
- ALOGV("usb:audio_hw - PCM_PARAM_FRAME_BITS min:%u, max:%u",
- pcm_params_get_min(alsa_hw_params, PCM_PARAM_FRAME_BITS),
- pcm_params_get_max(alsa_hw_params, PCM_PARAM_FRAME_BITS));
- log_pcm_mask("PCM_PARAM_FORMAT",
- pcm_params_get_mask(alsa_hw_params, PCM_PARAM_FORMAT));
- log_pcm_mask("PCM_PARAM_SUBFORMAT",
- pcm_params_get_mask(alsa_hw_params, PCM_PARAM_SUBFORMAT));
- ALOGV("usb:audio_hw - PCM_PARAM_CHANNELS min:%u, max:%u",
- pcm_params_get_min(alsa_hw_params, PCM_PARAM_CHANNELS),
- pcm_params_get_max(alsa_hw_params, PCM_PARAM_CHANNELS));
- ALOGV("usb:audio_hw - PCM_PARAM_RATE min:%u, max:%u",
- pcm_params_get_min(alsa_hw_params, PCM_PARAM_RATE),
- pcm_params_get_max(alsa_hw_params, PCM_PARAM_RATE));
- ALOGV("usb:audio_hw - PCM_PARAM_PERIOD_TIME min:%u, max:%u",
- pcm_params_get_min(alsa_hw_params, PCM_PARAM_PERIOD_TIME),
- pcm_params_get_max(alsa_hw_params, PCM_PARAM_PERIOD_TIME));
- ALOGV("usb:audio_hw - PCM_PARAM_PERIOD_SIZE min:%u, max:%u",
- pcm_params_get_min(alsa_hw_params, PCM_PARAM_PERIOD_SIZE),
- pcm_params_get_max(alsa_hw_params, PCM_PARAM_PERIOD_SIZE));
- ALOGV("usb:audio_hw - PCM_PARAM_PERIOD_BYTES min:%u, max:%u",
- pcm_params_get_min(alsa_hw_params, PCM_PARAM_PERIOD_BYTES),
- pcm_params_get_max(alsa_hw_params, PCM_PARAM_PERIOD_BYTES));
- ALOGV("usb:audio_hw - PCM_PARAM_PERIODS min:%u, max:%u",
- pcm_params_get_min(alsa_hw_params, PCM_PARAM_PERIODS),
- pcm_params_get_max(alsa_hw_params, PCM_PARAM_PERIODS));
- ALOGV("usb:audio_hw - PCM_PARAM_BUFFER_TIME min:%u, max:%u",
- pcm_params_get_min(alsa_hw_params, PCM_PARAM_BUFFER_TIME),
- pcm_params_get_max(alsa_hw_params, PCM_PARAM_BUFFER_TIME));
- ALOGV("usb:audio_hw - PCM_PARAM_BUFFER_SIZE min:%u, max:%u",
- pcm_params_get_min(alsa_hw_params, PCM_PARAM_BUFFER_SIZE),
- pcm_params_get_max(alsa_hw_params, PCM_PARAM_BUFFER_SIZE));
- ALOGV("usb:audio_hw - PCM_PARAM_BUFFER_BYTES min:%u, max:%u",
- pcm_params_get_min(alsa_hw_params, PCM_PARAM_BUFFER_BYTES),
- pcm_params_get_max(alsa_hw_params, PCM_PARAM_BUFFER_BYTES));
- ALOGV("usb:audio_hw - PCM_PARAM_TICK_TIME min:%u, max:%u",
- pcm_params_get_min(alsa_hw_params, PCM_PARAM_TICK_TIME),
- pcm_params_get_max(alsa_hw_params, PCM_PARAM_TICK_TIME));
-}
-
-void log_pcm_config(struct pcm_config * config, const char* label) {
- ALOGV("log_pcm_config() - %s", label);
- ALOGV(" channels:%d", config->channels);
- ALOGV(" rate:%d", config->rate);
- ALOGV(" period_size:%d", config->period_size);
- ALOGV(" period_count:%d", config->period_count);
- ALOGV(" format:%d", config->format);
-#if 0
- /* Values to use for the ALSA start, stop and silence thresholds. Setting
- * any one of these values to 0 will cause the default tinyalsa values to be
- * used instead. Tinyalsa defaults are as follows.
- *
- * start_threshold : period_count * period_size
- * stop_threshold : period_count * period_size
- * silence_threshold : 0
- */
- unsigned int start_threshold;
- unsigned int stop_threshold;
- unsigned int silence_threshold;
-
- /* Minimum number of frames available before pcm_mmap_write() will actually
- * write into the kernel buffer. Only used if the stream is opened in mmap mode
- * (pcm_open() called with PCM_MMAP flag set). Use 0 for default.
- */
- int avail_min;
-#endif
-}
diff --git a/modules/usbaudio/logging.h b/modules/usbaudio/logging.h
deleted file mode 100644
index b5640ed..0000000
--- a/modules/usbaudio/logging.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2014 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 ANDROID_HARDWARE_LIBHARDWARE_MODULES_USBAUDIO_LOGGING_H
-#define ANDROID_HARDWARE_LIBHARDWARE_MODULES_USBAUDIO_LOGGING_H
-
-#include <tinyalsa/asoundlib.h>
-
-void log_pcm_mask(const char* mask_name, struct pcm_mask* mask);
-void log_pcm_params(struct pcm_params * alsa_hw_params);
-void log_pcm_config(struct pcm_config * config, const char* label);
-
-#endif /* ANDROID_HARDWARE_LIBHARDWARE_MODULES_USBAUDIO_LOGGING_H */
diff --git a/modules/vibrator/vibrator.c b/modules/vibrator/vibrator.c
index ce4c03c..6b3ce57 100644
--- a/modules/vibrator/vibrator.c
+++ b/modules/vibrator/vibrator.c
@@ -19,6 +19,7 @@
#include <cutils/log.h>
+#include <malloc.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
diff --git a/tests/camera2/Android.mk b/tests/camera2/Android.mk
index 577ba0a..1128522 100644
--- a/tests/camera2/Android.mk
+++ b/tests/camera2/Android.mk
@@ -19,7 +19,6 @@
liblog \
libutils \
libcutils \
- libstlport \
libhardware \
libcamera_metadata \
libcameraservice \
@@ -29,21 +28,13 @@
libui \
libdl
-LOCAL_STATIC_LIBRARIES := \
- libgtest
-
LOCAL_C_INCLUDES += \
- bionic \
- bionic/libstdc++/include \
- external/gtest/include \
- external/stlport/stlport \
system/media/camera/include \
frameworks/av/include/ \
frameworks/av/services/camera/libcameraservice \
frameworks/native/include \
LOCAL_CFLAGS += -Wall -Wextra
-
LOCAL_MODULE:= camera2_test
LOCAL_MODULE_STEM_32 := camera2_test
LOCAL_MODULE_STEM_64 := camera2_test64
diff --git a/tests/camera2/CameraBurstTests.cpp b/tests/camera2/CameraBurstTests.cpp
index 8dcc2a2..198c0c1 100644
--- a/tests/camera2/CameraBurstTests.cpp
+++ b/tests/camera2/CameraBurstTests.cpp
@@ -49,7 +49,7 @@
#define dout if (0) std::cout
#endif
-#define WARN_UNLESS(condition) (!(condition) ? (std::cerr) : (std::ostream(NULL)) << "Warning: ")
+#define WARN_UNLESS(condition) if(!(condition)) std::cerr << "Warning: "
#define WARN_LE(exp, act) WARN_UNLESS((exp) <= (act))
#define WARN_LT(exp, act) WARN_UNLESS((exp) < (act))
#define WARN_GT(exp, act) WARN_UNLESS((exp) > (act))
@@ -219,7 +219,7 @@
CameraMetadata tmpRequest = previewRequest;
ASSERT_EQ(OK, tmpRequest.update(ANDROID_SENSOR_EXPOSURE_TIME,
&exposures[i], 1));
- ALOGV("Submitting capture request %d with exposure %"PRId64, i,
+ ALOGV("Submitting capture request %d with exposure %" PRId64, i,
exposures[i]);
dout << "Capture request " << i << " exposure is "
<< (exposures[i]/1e6f) << std::endl;
@@ -231,7 +231,7 @@
float brightnesses[CAMERA_FRAME_BURST_COUNT];
// Get each frame (metadata) and then the buffer. Calculate brightness.
for (int i = 0; i < CAMERA_FRAME_BURST_COUNT; ++i) {
- ALOGV("Reading capture request %d with exposure %"PRId64, i, exposures[i]);
+ ALOGV("Reading capture request %d with exposure %" PRId64, i, exposures[i]);
ASSERT_EQ(OK, mDevice->waitForNextFrame(CAMERA_FRAME_TIMEOUT));
ALOGV("Reading capture request-1 %d", i);
CaptureResult result;
@@ -618,7 +618,7 @@
&durationList[i], 1));
ASSERT_EQ(OK, tmpRequest.update(ANDROID_SENSOR_SENSITIVITY,
&sensitivityList[i], 1));
- ALOGV("Submitting capture %zu with exposure %"PRId64", frame duration %"PRId64", sensitivity %d",
+ ALOGV("Submitting capture %zu with exposure %" PRId64 ", frame duration %" PRId64 ", sensitivity %d",
i, expList[i], durationList[i], sensitivityList[i]);
dout << "Capture request " << i <<
": exposure is " << (expList[i]/1e6f) << " ms" <<
diff --git a/tests/camera2/CameraModuleFixture.h b/tests/camera2/CameraModuleFixture.h
index bf82a97..3a2df69 100644
--- a/tests/camera2/CameraModuleFixture.h
+++ b/tests/camera2/CameraModuleFixture.h
@@ -65,7 +65,7 @@
ASSERT_LE(0, mNumberOfCameras);
ASSERT_LE(
- CAMERA_MODULE_API_VERSION_2_0, mModule->getRawModule()->module_api_version)
+ CAMERA_MODULE_API_VERSION_2_0, mModule->getModuleApiVersion())
<< "Wrong module API version";
/* For using this fixture in other tests only */
@@ -83,7 +83,7 @@
mDevice.clear();
if (!TEST_EXTENSION_FORKING_ENABLED) {
- ASSERT_EQ(0, HWModuleHelpers::closeModule(mModule->getRawModule()))
+ ASSERT_EQ(0, HWModuleHelpers::closeModule(mModule->getDso()))
<< "Failed to close camera HAL module";
}
}
diff --git a/tests/camera2/CameraMultiStreamTests.cpp b/tests/camera2/CameraMultiStreamTests.cpp
index b2ee3e9..0f8d578 100644
--- a/tests/camera2/CameraMultiStreamTests.cpp
+++ b/tests/camera2/CameraMultiStreamTests.cpp
@@ -356,7 +356,7 @@
ASSERT_EQ(OK, request.update(ANDROID_SENSOR_EXPOSURE_TIME, &exposures[i], 1));
ASSERT_EQ(OK, request.update(ANDROID_SENSOR_SENSITIVITY, &sensitivities[i], 1));
ASSERT_EQ(OK, mDevice->capture(request));
- ALOGV("Submitting request with: id %d with exposure %"PRId64", sensitivity %d",
+ ALOGV("Submitting request with: id %d with exposure %" PRId64 ", sensitivity %d",
*requestIdStart, exposures[i], sensitivities[i]);
if (CAMERA_MULTI_STREAM_DEBUGGING) {
request.dump(STDOUT_FILENO);
@@ -528,7 +528,8 @@
// Find the right sizes for preview, metering, and capture streams
int64_t minFrameDuration = DEFAULT_FRAME_DURATION;
- Size processedMinSize, processedMaxSize, jpegMaxSize;
+ Size processedMinSize = {0, 0}, processedMaxSize = {0, 0};
+ Size jpegMaxSize = {0, 0};
int32_t minIdx, maxIdx;
GetMinSize(implDefData, implDefCount, &processedMinSize, &minIdx);
@@ -554,7 +555,7 @@
minFrameDuration = DEFAULT_FRAME_DURATION;
}
- ALOGV("targeted minimal frame duration is: %"PRId64"ns", minFrameDuration);
+ ALOGV("targeted minimal frame duration is: %" PRId64 "ns", minFrameDuration);
GetMaxSize(jpegData, jpegCount, &jpegMaxSize, &maxIdx);
ALOGV("Found Jpeg size max idx = %d", maxIdx);
@@ -672,7 +673,7 @@
ASSERT_EQ(OK, previewRequest.update(
ANDROID_SENSOR_EXPOSURE_TIME,
&exposures[i], 1));
- ALOGV("Submitting preview request %zu with exposure %"PRId64,
+ ALOGV("Submitting preview request %zu with exposure %" PRId64,
i, exposures[i]);
ASSERT_EQ(OK, mDevice->setStreamingRequest(previewRequest));
diff --git a/tests/camera2/CameraStreamFixture.h b/tests/camera2/CameraStreamFixture.h
index 8a8c27d..e234f7e 100644
--- a/tests/camera2/CameraStreamFixture.h
+++ b/tests/camera2/CameraStreamFixture.h
@@ -111,7 +111,7 @@
mHeight = entry.data.i32[1];
} else {
buildOutputResolutions();
- const int32_t *implDefResolutions;
+ const int32_t *implDefResolutions = NULL;
size_t implDefResolutionsCount;
int format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
diff --git a/tests/camera2/camera2_utils.cpp b/tests/camera2/camera2_utils.cpp
index 930b909..d962939 100644
--- a/tests/camera2/camera2_utils.cpp
+++ b/tests/camera2/camera2_utils.cpp
@@ -580,14 +580,13 @@
mCondition.signal();
}
-int HWModuleHelpers::closeModule(const hw_module_t* module) {
+int HWModuleHelpers::closeModule(void *dso) {
int status;
-
- if (!module) {
+ if (!dso) {
return -EINVAL;
}
- status = dlclose(module->dso);
+ status = dlclose(dso);
if (status != 0) {
char const *err_str = dlerror();
ALOGE("%s dlclose failed, error: %s", __func__, err_str ?: "unknown");
diff --git a/tests/camera2/camera2_utils.h b/tests/camera2/camera2_utils.h
index 2072eb6..ab1fcfb 100644
--- a/tests/camera2/camera2_utils.h
+++ b/tests/camera2/camera2_utils.h
@@ -240,7 +240,7 @@
struct HWModuleHelpers {
/* attempt to unload the library with dlclose */
- static int closeModule(const hw_module_t* module);
+ static int closeModule(void* dso);
};
}
diff --git a/tests/fingerprint/fingerprint_tests.cpp b/tests/fingerprint/fingerprint_tests.cpp
index 4463751..4ae0d73 100644
--- a/tests/fingerprint/fingerprint_tests.cpp
+++ b/tests/fingerprint/fingerprint_tests.cpp
@@ -29,6 +29,11 @@
<< "remove() function is not implemented";
}
+TEST_F(FingerprintDevice, isThereAuthenticate) {
+ ASSERT_TRUE(NULL != fp_device()->authenticate)
+ << "authenticate() function is not implemented";
+}
+
TEST_F(FingerprintDevice, isThereSetNotify) {
ASSERT_TRUE(NULL != fp_device()->set_notify)
<< "set_notify() function is not implemented";
diff --git a/tests/keymaster/Android.mk b/tests/keymaster/Android.mk
index e53e67f..0c11795 100644
--- a/tests/keymaster/Android.mk
+++ b/tests/keymaster/Android.mk
@@ -6,26 +6,14 @@
LOCAL_SRC_FILES:= \
keymaster_test.cpp
-# Note that "bionic" is needed because of stlport
-LOCAL_C_INCLUDES := \
- bionic \
- external/gtest/include \
- external/openssl/include \
- external/stlport/stlport
-
LOCAL_SHARED_LIBRARIES := \
liblog \
libutils \
libcrypto \
- libstlport \
- libhardware
-
-LOCAL_STATIC_LIBRARIES := \
- libgtest \
- libgtest_main
+ libhardware \
LOCAL_MODULE := keymaster_test
LOCAL_MODULE_TAGS := tests
-include $(BUILD_EXECUTABLE)
+include $(BUILD_NATIVE_TEST)
diff --git a/tests/keymaster/keymaster_test.cpp b/tests/keymaster/keymaster_test.cpp
index 6b76ccb..e5e1dfd 100644
--- a/tests/keymaster/keymaster_test.cpp
+++ b/tests/keymaster/keymaster_test.cpp
@@ -35,7 +35,7 @@
#include <UniquePtr.h>
-#include <hardware/keymaster.h>
+#include <hardware/keymaster0.h>
namespace android {
@@ -92,13 +92,13 @@
class UniqueKey : public UniqueBlob {
public:
- UniqueKey(keymaster_device_t** dev, uint8_t* bytes, size_t length) :
+ UniqueKey(keymaster0_device_t** dev, uint8_t* bytes, size_t length) :
UniqueBlob(bytes, length), mDevice(dev) {
}
~UniqueKey() {
if (mDevice != NULL && *mDevice != NULL) {
- keymaster_device_t* dev = *mDevice;
+ keymaster0_device_t* dev = *mDevice;
if (dev->delete_keypair != NULL) {
dev->delete_keypair(dev, get(), length());
}
@@ -106,7 +106,7 @@
}
private:
- keymaster_device_t** mDevice;
+ keymaster0_device_t** mDevice;
};
class UniqueReadOnlyBlob {
@@ -341,7 +341,7 @@
std::cout << "Using keymaster module: " << mod->name << std::endl;
- ASSERT_EQ(0, keymaster_open(mod, &sDevice))
+ ASSERT_EQ(0, keymaster0_open(mod, &sDevice))
<< "Should be able to open the keymaster device";
ASSERT_EQ(KEYMASTER_MODULE_API_VERSION_0_2, mod->module_api_version)
@@ -364,14 +364,14 @@
}
static void TearDownTestCase() {
- ASSERT_EQ(0, keymaster_close(sDevice));
+ ASSERT_EQ(0, keymaster0_close(sDevice));
}
protected:
- static keymaster_device_t* sDevice;
+ static keymaster0_device_t* sDevice;
};
-keymaster_device_t* KeymasterBaseTest::sDevice = NULL;
+keymaster0_device_t* KeymasterBaseTest::sDevice = NULL;
class KeymasterTest : public KeymasterBaseTest {
};