bring over phonelibs minus frida-gum and qsml

This commit is contained in:
George Hotz
2020-01-17 10:37:11 -08:00
parent 6abffe0ede
commit da6863f427
2473 changed files with 759632 additions and 0 deletions
@@ -0,0 +1,223 @@
/*
* 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.
*/
/*
* Activity Recognition HAL. The goal is to provide low power, low latency, always-on activity
* recognition implemented in hardware (i.e. these activity recognition algorithms/classifers
* should NOT be run on the AP). By low power we mean that this may be activated 24/7 without
* impacting the battery drain speed (goal in order of 1mW including the power for sensors).
* This HAL does not specify the input sources that are used towards detecting these activities.
* It has one monitor interface which can be used to batch activities for always-on
* activity_recognition and if the latency is zero, the same interface can be used for low latency
* detection.
*/
#ifndef ANDROID_ACTIVITY_RECOGNITION_INTERFACE_H
#define ANDROID_ACTIVITY_RECOGNITION_INTERFACE_H
#include <hardware/hardware.h>
__BEGIN_DECLS
#define ACTIVITY_RECOGNITION_HEADER_VERSION 1
#define ACTIVITY_RECOGNITION_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION_2(0, 1, ACTIVITY_RECOGNITION_HEADER_VERSION)
#define ACTIVITY_RECOGNITION_HARDWARE_MODULE_ID "activity_recognition"
#define ACTIVITY_RECOGNITION_HARDWARE_INTERFACE "activity_recognition_hw_if"
/*
* Define types for various activities. Multiple activities may be active at the same time and
* sometimes none of these activities may be active.
*
* Each activity has a corresponding type. Only activities that are defined here should use
* android.activity_recognition.* prefix. OEM defined activities should not use this prefix.
* Activity type of OEM-defined activities should start with the reverse domain name of the entity
* defining the activity.
*
* When android introduces a new activity type that can potentially replace an OEM-defined activity
* type, the OEM must use the official activity type on versions of the HAL that support this new
* official activity type.
*
* Example (made up): Suppose Google's Glass team wants to detect nodding activity.
* - Such an activity is not officially supported in android L
* - Glass devices launching on L can implement a custom activity with
* type = "com.google.glass.nodding"
* - In M android release, if android decides to define ACITIVITY_TYPE_NODDING, those types
* should replace the Glass-team-specific types in all future launches.
* - When launching glass on the M release, Google should now use the official activity type
* - This way, other applications can use this activity.
*/
#define ACTIVITY_TYPE_IN_VEHICLE "android.activity_recognition.in_vehicle"
#define ACTIVITY_TYPE_ON_BICYCLE "android.activity_recognition.on_bicycle"
#define ACTIVITY_TYPE_WALKING "android.activity_recognition.walking"
#define ACTIVITY_TYPE_RUNNING "android.activity_recognition.running"
#define ACTIVITY_TYPE_STILL "android.activity_recognition.still"
#define ACTIVITY_TYPE_TILTING "android.activity_recognition.tilting"
/* Values for activity_event.event_types. */
enum {
/*
* A flush_complete event which indicates that a flush() has been successfully completed. This
* does not correspond to any activity/event. An event of this type should be added to the end
* of a batch FIFO and it indicates that all the events in the batch FIFO have been successfully
* reported to the framework. An event of this type should be generated only if flush() has been
* explicitly called and if the FIFO is empty at the time flush() is called it should trivially
* return a flush_complete_event to indicate that the FIFO is empty.
*
* A flush complete event should have the following parameters set.
* activity_event_t.event_type = ACTIVITY_EVENT_FLUSH_COMPLETE
* activity_event_t.activity = 0
* activity_event_t.timestamp = 0
* activity_event_t.reserved = 0
* See (*flush)() for more details.
*/
ACTIVITY_EVENT_FLUSH_COMPLETE = 0,
/* Signifies entering an activity. */
ACTIVITY_EVENT_ENTER = 1,
/* Signifies exiting an activity. */
ACTIVITY_EVENT_EXIT = 2
};
/*
* Each event is a separate activity with event_type indicating whether this activity has started
* or ended. Eg event: (event_type="enter", activity="ON_FOOT", timestamp)
*/
typedef struct activity_event {
/* One of the ACTIVITY_EVENT_* constants defined above. */
uint32_t event_type;
/*
* Index of the activity in the list returned by get_supported_activities_list. If this event
* is a flush complete event, this should be set to zero.
*/
uint32_t activity;
/* Time at which the transition/event has occurred in nanoseconds using elapsedRealTimeNano. */
int64_t timestamp;
/* Set to zero. */
int32_t reserved[4];
} activity_event_t;
typedef struct activity_recognition_module {
/**
* Common methods of the activity recognition module. This *must* be the first member of
* activity_recognition_module as users of this structure will cast a hw_module_t to
* activity_recognition_module pointer in contexts where it's known the hw_module_t
* references an activity_recognition_module.
*/
hw_module_t common;
/*
* List of all activities supported by this module including OEM defined activities. Each
* activity is represented using a string defined above. Each string should be null terminated.
* The index of the activity in this array is used as a "handle" for enabling/disabling and
* event delivery.
* Return value is the size of this list.
*/
int (*get_supported_activities_list)(struct activity_recognition_module* module,
char const* const* *activity_list);
} activity_recognition_module_t;
struct activity_recognition_device;
typedef struct activity_recognition_callback_procs {
// Callback for activity_data. This is guaranteed to not invoke any HAL methods.
// Memory allocated for the events can be reused after this method returns.
// events - Array of activity_event_t s that are reported.
// count - size of the array.
void (*activity_callback)(const struct activity_recognition_callback_procs* procs,
const activity_event_t* events, int count);
} activity_recognition_callback_procs_t;
typedef struct activity_recognition_device {
/**
* Common methods of the activity recognition device. This *must* be the first member of
* activity_recognition_device as users of this structure will cast a hw_device_t to
* activity_recognition_device pointer in contexts where it's known the hw_device_t
* references an activity_recognition_device.
*/
hw_device_t common;
/*
* Sets the callback to invoke when there are events to report. This call overwrites the
* previously registered callback (if any).
*/
void (*register_activity_callback)(const struct activity_recognition_device* dev,
const activity_recognition_callback_procs_t* callback);
/*
* Activates monitoring of activity transitions. Activities need not be reported as soon as they
* are detected. The detected activities are stored in a FIFO and reported in batches when the
* "max_batch_report_latency" expires or when the batch FIFO is full. The implementation should
* allow the AP to go into suspend mode while the activities are detected and stored in the
* batch FIFO. Whenever events need to be reported (like when the FIFO is full or when the
* max_batch_report_latency has expired for an activity, event pair), it should wake_up the AP
* so that no events are lost. Activities are stored as transitions and they are allowed to
* overlap with each other. Each (activity, event_type) pair can be activated or deactivated
* independently of the other. The HAL implementation needs to keep track of which pairs are
* currently active and needs to detect only those pairs.
*
* activity_handle - Index of the specific activity that needs to be detected in the list
* returned by get_supported_activities_list.
* event_type - Specific transition of the activity that needs to be detected.
* max_batch_report_latency_ns - a transition can be delayed by at most
* “max_batch_report_latency” nanoseconds.
* Return 0 on success, negative errno code otherwise.
*/
int (*enable_activity_event)(const struct activity_recognition_device* dev,
uint32_t activity_handle, uint32_t event_type, int64_t max_batch_report_latency_ns);
/*
* Disables detection of a specific (activity, event_type) pair.
*/
int (*disable_activity_event)(const struct activity_recognition_device* dev,
uint32_t activity_handle, uint32_t event_type);
/*
* Flush all the batch FIFOs. Report all the activities that were stored in the FIFO so far as
* if max_batch_report_latency had expired. This shouldn't change the latency in any way. Add
* a flush_complete_event to indicate the end of the FIFO after all events are delivered.
* See ACTIVITY_EVENT_FLUSH_COMPLETE for more details.
* Return 0 on success, negative errno code otherwise.
*/
int (*flush)(const struct activity_recognition_device* dev);
// Must be set to NULL.
void (*reserved_procs[16 - 4])(void);
} activity_recognition_device_t;
static inline int activity_recognition_open(const hw_module_t* module,
activity_recognition_device_t** device) {
return module->methods->open(module,
ACTIVITY_RECOGNITION_HARDWARE_INTERFACE, (hw_device_t**)device);
}
static inline int activity_recognition_close(activity_recognition_device_t* device) {
return device->common.close(&device->common);
}
__END_DECLS
#endif // ANDROID_ACTIVITY_RECOGNITION_INTERFACE_H
@@ -0,0 +1,700 @@
/*
* 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_AUDIO_HAL_INTERFACE_H
#define ANDROID_AUDIO_HAL_INTERFACE_H
#include <stdint.h>
#include <strings.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <cutils/bitops.h>
#include <hardware/hardware.h>
#include <system/audio.h>
#include <hardware/audio_effect.h>
#ifdef AUDIO_LISTEN_ENABLED
#include <listen_types.h>
#endif
__BEGIN_DECLS
/**
* The id of this module
*/
#define AUDIO_HARDWARE_MODULE_ID "audio"
/**
* Name of the audio devices to open
*/
#define AUDIO_HARDWARE_INTERFACE "audio_hw_if"
/* Use version 0.1 to be compatible with first generation of audio hw module with version_major
* hardcoded to 1. No audio module API change.
*/
#define AUDIO_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
#define AUDIO_MODULE_API_VERSION_CURRENT AUDIO_MODULE_API_VERSION_0_1
/* First generation of audio devices had version hardcoded to 0. all devices with versions < 1.0
* will be considered of first generation API.
*/
#define AUDIO_DEVICE_API_VERSION_0_0 HARDWARE_DEVICE_API_VERSION(0, 0)
#define AUDIO_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
#define AUDIO_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0)
#define AUDIO_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0)
#define AUDIO_DEVICE_API_VERSION_CURRENT AUDIO_DEVICE_API_VERSION_3_0
/* Minimal audio HAL version supported by the audio framework */
#define AUDIO_DEVICE_API_VERSION_MIN AUDIO_DEVICE_API_VERSION_2_0
/**
* List of known audio HAL modules. This is the base name of the audio HAL
* library composed of the "audio." prefix, one of the base names below and
* a suffix specific to the device.
* e.g: audio.primary.goldfish.so or audio.a2dp.default.so
*/
#define AUDIO_HARDWARE_MODULE_ID_PRIMARY "primary"
#define AUDIO_HARDWARE_MODULE_ID_A2DP "a2dp"
#define AUDIO_HARDWARE_MODULE_ID_USB "usb"
#define AUDIO_HARDWARE_MODULE_ID_REMOTE_SUBMIX "r_submix"
#define AUDIO_HARDWARE_MODULE_ID_CODEC_OFFLOAD "codec_offload"
/**************************************/
/**
* standard audio parameters that the HAL may need to handle
*/
/**
* audio device parameters
*/
/* BT SCO Noise Reduction + Echo Cancellation parameters */
#define AUDIO_PARAMETER_KEY_BT_NREC "bt_headset_nrec"
#define AUDIO_PARAMETER_VALUE_ON "on"
#define AUDIO_PARAMETER_VALUE_OFF "off"
/* TTY mode selection */
#define AUDIO_PARAMETER_KEY_TTY_MODE "tty_mode"
#define AUDIO_PARAMETER_VALUE_TTY_OFF "tty_off"
#define AUDIO_PARAMETER_VALUE_TTY_VCO "tty_vco"
#define AUDIO_PARAMETER_VALUE_TTY_HCO "tty_hco"
#define AUDIO_PARAMETER_VALUE_TTY_FULL "tty_full"
/* Hearing Aid Compatibility - Telecoil (HAC-T) mode on/off
Strings must be in sync with CallFeaturesSetting.java */
#define AUDIO_PARAMETER_KEY_HAC "HACSetting"
#define AUDIO_PARAMETER_VALUE_HAC_ON "ON"
#define AUDIO_PARAMETER_VALUE_HAC_OFF "OFF"
/* A2DP sink address set by framework */
#define AUDIO_PARAMETER_A2DP_SINK_ADDRESS "a2dp_sink_address"
/* A2DP source address set by framework */
#define AUDIO_PARAMETER_A2DP_SOURCE_ADDRESS "a2dp_source_address"
/* Screen state */
#define AUDIO_PARAMETER_KEY_SCREEN_STATE "screen_state"
/* Bluetooth SCO wideband */
#define AUDIO_PARAMETER_KEY_BT_SCO_WB "bt_wbs"
/* Get a new HW synchronization source identifier.
* Return a valid source (positive integer) or AUDIO_HW_SYNC_INVALID if an error occurs
* or no HW sync is available. */
#define AUDIO_PARAMETER_HW_AV_SYNC "hw_av_sync"
/* Device state*/
#define AUDIO_PARAMETER_KEY_DEV_SHUTDOWN "dev_shutdown"
/**
* audio stream parameters
*/
#define AUDIO_PARAMETER_STREAM_ROUTING "routing" /* audio_devices_t */
#define AUDIO_PARAMETER_STREAM_FORMAT "format" /* audio_format_t */
#define AUDIO_PARAMETER_STREAM_CHANNELS "channels" /* audio_channel_mask_t */
#define AUDIO_PARAMETER_STREAM_FRAME_COUNT "frame_count" /* size_t */
#define AUDIO_PARAMETER_STREAM_INPUT_SOURCE "input_source" /* audio_source_t */
#define AUDIO_PARAMETER_STREAM_SAMPLING_RATE "sampling_rate" /* uint32_t */
#define AUDIO_PARAMETER_DEVICE_CONNECT "connect" /* audio_devices_t */
#define AUDIO_PARAMETER_DEVICE_DISCONNECT "disconnect" /* audio_devices_t */
/* Query supported formats. The response is a '|' separated list of strings from
* audio_format_t enum e.g: "sup_formats=AUDIO_FORMAT_PCM_16_BIT" */
#define AUDIO_PARAMETER_STREAM_SUP_FORMATS "sup_formats"
/* Query supported channel masks. The response is a '|' separated list of strings from
* audio_channel_mask_t enum e.g: "sup_channels=AUDIO_CHANNEL_OUT_STEREO|AUDIO_CHANNEL_OUT_MONO" */
#define AUDIO_PARAMETER_STREAM_SUP_CHANNELS "sup_channels"
/* Query supported sampling rates. The response is a '|' separated list of integer values e.g:
* "sup_sampling_rates=44100|48000" */
#define AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES "sup_sampling_rates"
/* Set the HW synchronization source for an output stream. */
#define AUDIO_PARAMETER_STREAM_HW_AV_SYNC "hw_av_sync"
/**
* audio codec parameters
*/
#define AUDIO_OFFLOAD_CODEC_PARAMS "music_offload_codec_param"
#define AUDIO_OFFLOAD_CODEC_BIT_PER_SAMPLE "music_offload_bit_per_sample"
#define AUDIO_OFFLOAD_CODEC_BIT_RATE "music_offload_bit_rate"
#define AUDIO_OFFLOAD_CODEC_AVG_BIT_RATE "music_offload_avg_bit_rate"
#define AUDIO_OFFLOAD_CODEC_ID "music_offload_codec_id"
#define AUDIO_OFFLOAD_CODEC_BLOCK_ALIGN "music_offload_block_align"
#define AUDIO_OFFLOAD_CODEC_SAMPLE_RATE "music_offload_sample_rate"
#define AUDIO_OFFLOAD_CODEC_ENCODE_OPTION "music_offload_encode_option"
#define AUDIO_OFFLOAD_CODEC_NUM_CHANNEL "music_offload_num_channels"
#define AUDIO_OFFLOAD_CODEC_DOWN_SAMPLING "music_offload_down_sampling"
#define AUDIO_OFFLOAD_CODEC_DELAY_SAMPLES "delay_samples"
#define AUDIO_OFFLOAD_CODEC_PADDING_SAMPLES "padding_samples"
/**************************************/
/* common audio stream parameters and operations */
struct audio_stream {
/**
* Return the sampling rate in Hz - eg. 44100.
*/
uint32_t (*get_sample_rate)(const struct audio_stream *stream);
/* currently unused - use set_parameters with key
* AUDIO_PARAMETER_STREAM_SAMPLING_RATE
*/
int (*set_sample_rate)(struct audio_stream *stream, uint32_t rate);
/**
* Return size of input/output buffer in bytes for this stream - eg. 4800.
* It should be a multiple of the frame size. See also get_input_buffer_size.
*/
size_t (*get_buffer_size)(const struct audio_stream *stream);
/**
* Return the channel mask -
* e.g. AUDIO_CHANNEL_OUT_STEREO or AUDIO_CHANNEL_IN_STEREO
*/
audio_channel_mask_t (*get_channels)(const struct audio_stream *stream);
/**
* Return the audio format - e.g. AUDIO_FORMAT_PCM_16_BIT
*/
audio_format_t (*get_format)(const struct audio_stream *stream);
/* currently unused - use set_parameters with key
* AUDIO_PARAMETER_STREAM_FORMAT
*/
int (*set_format)(struct audio_stream *stream, audio_format_t format);
/**
* Put the audio hardware input/output into standby mode.
* Driver should exit from standby mode at the next I/O operation.
* Returns 0 on success and <0 on failure.
*/
int (*standby)(struct audio_stream *stream);
/** dump the state of the audio input/output device */
int (*dump)(const struct audio_stream *stream, int fd);
/** Return the set of device(s) which this stream is connected to */
audio_devices_t (*get_device)(const struct audio_stream *stream);
/**
* Currently unused - set_device() corresponds to set_parameters() with key
* AUDIO_PARAMETER_STREAM_ROUTING for both input and output.
* AUDIO_PARAMETER_STREAM_INPUT_SOURCE is an additional information used by
* input streams only.
*/
int (*set_device)(struct audio_stream *stream, audio_devices_t device);
/**
* set/get audio stream parameters. The function accepts a list of
* parameter key value pairs in the form: key1=value1;key2=value2;...
*
* Some keys are reserved for standard parameters (See AudioParameter class)
*
* If the implementation does not accept a parameter change while
* the output is active but the parameter is acceptable otherwise, it must
* return -ENOSYS.
*
* The audio flinger will put the stream in standby and then change the
* parameter value.
*/
int (*set_parameters)(struct audio_stream *stream, const char *kv_pairs);
/*
* Returns a pointer to a heap allocated string. The caller is responsible
* for freeing the memory for it using free().
*/
char * (*get_parameters)(const struct audio_stream *stream,
const char *keys);
int (*add_audio_effect)(const struct audio_stream *stream,
effect_handle_t effect);
int (*remove_audio_effect)(const struct audio_stream *stream,
effect_handle_t effect);
};
typedef struct audio_stream audio_stream_t;
/* type of asynchronous write callback events. Mutually exclusive */
typedef enum {
STREAM_CBK_EVENT_WRITE_READY, /* non blocking write completed */
STREAM_CBK_EVENT_DRAIN_READY /* drain completed */
} stream_callback_event_t;
typedef int (*stream_callback_t)(stream_callback_event_t event, void *param, void *cookie);
/* type of drain requested to audio_stream_out->drain(). Mutually exclusive */
typedef enum {
AUDIO_DRAIN_ALL, /* drain() returns when all data has been played */
AUDIO_DRAIN_EARLY_NOTIFY /* drain() returns a short time before all data
from the current track has been played to
give time for gapless track switch */
} audio_drain_type_t;
/**
* audio_stream_out is the abstraction interface for the audio output hardware.
*
* It provides information about various properties of the audio output
* hardware driver.
*/
struct audio_stream_out {
/**
* Common methods of the audio stream out. This *must* be the first member of audio_stream_out
* as users of this structure will cast a audio_stream to audio_stream_out pointer in contexts
* where it's known the audio_stream references an audio_stream_out.
*/
struct audio_stream common;
/**
* Return the audio hardware driver estimated latency in milliseconds.
*/
uint32_t (*get_latency)(const struct audio_stream_out *stream);
/**
* Use this method in situations where audio mixing is done in the
* hardware. This method serves as a direct interface with hardware,
* allowing you to directly set the volume as apposed to via the framework.
* This method might produce multiple PCM outputs or hardware accelerated
* codecs, such as MP3 or AAC.
*/
int (*set_volume)(struct audio_stream_out *stream, float left, float right);
/**
* Write audio buffer to driver. Returns number of bytes written, or a
* negative status_t. If at least one frame was written successfully prior to the error,
* it is suggested that the driver return that successful (short) byte count
* and then return an error in the subsequent call.
*
* If set_callback() has previously been called to enable non-blocking mode
* the write() is not allowed to block. It must write only the number of
* bytes that currently fit in the driver/hardware buffer and then return
* this byte count. If this is less than the requested write size the
* callback function must be called when more space is available in the
* driver/hardware buffer.
*/
ssize_t (*write)(struct audio_stream_out *stream, const void* buffer,
size_t bytes);
/* return the number of audio frames written by the audio dsp to DAC since
* the output has exited standby
*/
int (*get_render_position)(const struct audio_stream_out *stream,
uint32_t *dsp_frames);
/**
* get the local time at which the next write to the audio driver will be presented.
* The units are microseconds, where the epoch is decided by the local audio HAL.
*/
int (*get_next_write_timestamp)(const struct audio_stream_out *stream,
int64_t *timestamp);
/**
* set the callback function for notifying completion of non-blocking
* write and drain.
* Calling this function implies that all future write() and drain()
* must be non-blocking and use the callback to signal completion.
*/
int (*set_callback)(struct audio_stream_out *stream,
stream_callback_t callback, void *cookie);
/**
* Notifies to the audio driver to stop playback however the queued buffers are
* retained by the hardware. Useful for implementing pause/resume. Empty implementation
* if not supported however should be implemented for hardware with non-trivial
* latency. In the pause state audio hardware could still be using power. User may
* consider calling suspend after a timeout.
*
* Implementation of this function is mandatory for offloaded playback.
*/
int (*pause)(struct audio_stream_out* stream);
/**
* Notifies to the audio driver to resume playback following a pause.
* Returns error if called without matching pause.
*
* Implementation of this function is mandatory for offloaded playback.
*/
int (*resume)(struct audio_stream_out* stream);
/**
* Requests notification when data buffered by the driver/hardware has
* been played. If set_callback() has previously been called to enable
* non-blocking mode, the drain() must not block, instead it should return
* quickly and completion of the drain is notified through the callback.
* If set_callback() has not been called, the drain() must block until
* completion.
* If type==AUDIO_DRAIN_ALL, the drain completes when all previously written
* data has been played.
* If type==AUDIO_DRAIN_EARLY_NOTIFY, the drain completes shortly before all
* data for the current track has played to allow time for the framework
* to perform a gapless track switch.
*
* Drain must return immediately on stop() and flush() call
*
* Implementation of this function is mandatory for offloaded playback.
*/
int (*drain)(struct audio_stream_out* stream, audio_drain_type_t type );
/**
* Notifies to the audio driver to flush the queued data. Stream must already
* be paused before calling flush().
*
* Implementation of this function is mandatory for offloaded playback.
*/
int (*flush)(struct audio_stream_out* stream);
/**
* Return a recent count of the number of audio frames presented to an external observer.
* This excludes frames which have been written but are still in the pipeline.
* The count is not reset to zero when output enters standby.
* Also returns the value of CLOCK_MONOTONIC as of this presentation count.
* The returned count is expected to be 'recent',
* but does not need to be the most recent possible value.
* However, the associated time should correspond to whatever count is returned.
* Example: assume that N+M frames have been presented, where M is a 'small' number.
* Then it is permissible to return N instead of N+M,
* and the timestamp should correspond to N rather than N+M.
* The terms 'recent' and 'small' are not defined.
* They reflect the quality of the implementation.
*
* 3.0 and higher only.
*/
int (*get_presentation_position)(const struct audio_stream_out *stream,
uint64_t *frames, struct timespec *timestamp);
};
typedef struct audio_stream_out audio_stream_out_t;
struct audio_stream_in {
/**
* Common methods of the audio stream in. This *must* be the first member of audio_stream_in
* as users of this structure will cast a audio_stream to audio_stream_in pointer in contexts
* where it's known the audio_stream references an audio_stream_in.
*/
struct audio_stream common;
/** set the input gain for the audio driver. This method is for
* for future use */
int (*set_gain)(struct audio_stream_in *stream, float gain);
/** Read audio buffer in from audio driver. Returns number of bytes read, or a
* negative status_t. If at least one frame was read prior to the error,
* read should return that byte count and then return an error in the subsequent call.
*/
ssize_t (*read)(struct audio_stream_in *stream, void* buffer,
size_t bytes);
/**
* Return the amount of input frames lost in the audio driver since the
* last call of this function.
* Audio driver is expected to reset the value to 0 and restart counting
* upon returning the current value by this function call.
* Such loss typically occurs when the user space process is blocked
* longer than the capacity of audio driver buffers.
*
* Unit: the number of input audio frames
*/
uint32_t (*get_input_frames_lost)(struct audio_stream_in *stream);
};
typedef struct audio_stream_in audio_stream_in_t;
/**
* return the frame size (number of bytes per sample).
*
* Deprecated: use audio_stream_out_frame_size() or audio_stream_in_frame_size() instead.
*/
__attribute__((__deprecated__))
static inline size_t audio_stream_frame_size(const struct audio_stream *s)
{
size_t chan_samp_sz;
audio_format_t format = s->get_format(s);
if (audio_is_linear_pcm(format)) {
chan_samp_sz = audio_bytes_per_sample(format);
return popcount(s->get_channels(s)) * chan_samp_sz;
}
return sizeof(int8_t);
}
/**
* return the frame size (number of bytes per sample) of an output stream.
*/
static inline size_t audio_stream_out_frame_size(const struct audio_stream_out *s)
{
size_t chan_samp_sz;
audio_format_t format = s->common.get_format(&s->common);
if (audio_is_linear_pcm(format)) {
chan_samp_sz = audio_bytes_per_sample(format);
return audio_channel_count_from_out_mask(s->common.get_channels(&s->common)) * chan_samp_sz;
}
return sizeof(int8_t);
}
/**
* return the frame size (number of bytes per sample) of an input stream.
*/
static inline size_t audio_stream_in_frame_size(const struct audio_stream_in *s)
{
size_t chan_samp_sz;
audio_format_t format = s->common.get_format(&s->common);
if (audio_is_linear_pcm(format)) {
chan_samp_sz = audio_bytes_per_sample(format);
return audio_channel_count_from_in_mask(s->common.get_channels(&s->common)) * chan_samp_sz;
}
return sizeof(int8_t);
}
/**********************************************************************/
/**
* 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 audio_module {
struct hw_module_t common;
};
struct audio_hw_device {
/**
* Common methods of the audio device. This *must* be the first member of audio_hw_device
* as users of this structure will cast a hw_device_t to audio_hw_device pointer in contexts
* where it's known the hw_device_t references an audio_hw_device.
*/
struct hw_device_t common;
/**
* used by audio flinger to enumerate what devices are supported by
* each audio_hw_device implementation.
*
* Return value is a bitmask of 1 or more values of audio_devices_t
*
* NOTE: audio HAL implementations starting with
* AUDIO_DEVICE_API_VERSION_2_0 do not implement this function.
* All supported devices should be listed in audio_policy.conf
* file and the audio policy manager must choose the appropriate
* audio module based on information in this file.
*/
uint32_t (*get_supported_devices)(const struct audio_hw_device *dev);
/**
* check to see if the audio hardware interface has been initialized.
* returns 0 on success, -ENODEV on failure.
*/
int (*init_check)(const struct audio_hw_device *dev);
/** set the audio volume of a voice call. Range is between 0.0 and 1.0 */
int (*set_voice_volume)(struct audio_hw_device *dev, float volume);
/**
* set the audio volume for all audio activities other than voice call.
* Range between 0.0 and 1.0. If any value other than 0 is returned,
* the software mixer will emulate this capability.
*/
int (*set_master_volume)(struct audio_hw_device *dev, float volume);
/**
* Get the current master volume value for the HAL, if the HAL supports
* master volume control. AudioFlinger will query this value from the
* primary audio HAL when the service starts and use the value for setting
* the initial master volume across all HALs. HALs which do not support
* this method may leave it set to NULL.
*/
int (*get_master_volume)(struct audio_hw_device *dev, float *volume);
/**
* set_mode is called when the audio mode changes. AUDIO_MODE_NORMAL mode
* is for standard audio playback, AUDIO_MODE_RINGTONE when a ringtone is
* playing, and AUDIO_MODE_IN_CALL when a call is in progress.
*/
int (*set_mode)(struct audio_hw_device *dev, audio_mode_t mode);
/* mic mute */
int (*set_mic_mute)(struct audio_hw_device *dev, bool state);
int (*get_mic_mute)(const struct audio_hw_device *dev, bool *state);
/* set/get global audio parameters */
int (*set_parameters)(struct audio_hw_device *dev, const char *kv_pairs);
/*
* Returns a pointer to a heap allocated string. The caller is responsible
* for freeing the memory for it using free().
*/
char * (*get_parameters)(const struct audio_hw_device *dev,
const char *keys);
/* Returns audio input buffer size according to parameters passed or
* 0 if one of the parameters is not supported.
* See also get_buffer_size which is for a particular stream.
*/
size_t (*get_input_buffer_size)(const struct audio_hw_device *dev,
const struct audio_config *config);
/** This method creates and opens the audio hardware output stream.
* The "address" parameter qualifies the "devices" audio device type if needed.
* The format format depends on the device type:
* - Bluetooth devices use the MAC address of the device in the form "00:11:22:AA:BB:CC"
* - USB devices use the ALSA card and device numbers in the form "card=X;device=Y"
* - Other devices may use a number or any other string.
*/
int (*open_output_stream)(struct audio_hw_device *dev,
audio_io_handle_t handle,
audio_devices_t devices,
audio_output_flags_t flags,
struct audio_config *config,
struct audio_stream_out **stream_out,
const char *address);
void (*close_output_stream)(struct audio_hw_device *dev,
struct audio_stream_out* stream_out);
/** This method creates and opens the audio hardware input stream */
int (*open_input_stream)(struct audio_hw_device *dev,
audio_io_handle_t handle,
audio_devices_t devices,
struct audio_config *config,
struct audio_stream_in **stream_in,
audio_input_flags_t flags,
const char *address,
audio_source_t source);
void (*close_input_stream)(struct audio_hw_device *dev,
struct audio_stream_in *stream_in);
/** This method dumps the state of the audio hardware */
int (*dump)(const struct audio_hw_device *dev, int fd);
/**
* set the audio mute status for all audio activities. If any value other
* than 0 is returned, the software mixer will emulate this capability.
*/
int (*set_master_mute)(struct audio_hw_device *dev, bool mute);
/**
* Get the current master mute status for the HAL, if the HAL supports
* master mute control. AudioFlinger will query this value from the primary
* audio HAL when the service starts and use the value for setting the
* initial master mute across all HALs. HALs which do not support this
* method may leave it set to NULL.
*/
int (*get_master_mute)(struct audio_hw_device *dev, bool *mute);
/**
* Routing control
*/
/* Creates an audio patch between several source and sink ports.
* The handle is allocated by the HAL and should be unique for this
* audio HAL module. */
int (*create_audio_patch)(struct audio_hw_device *dev,
unsigned int num_sources,
const struct audio_port_config *sources,
unsigned int num_sinks,
const struct audio_port_config *sinks,
audio_patch_handle_t *handle);
/* Release an audio patch */
int (*release_audio_patch)(struct audio_hw_device *dev,
audio_patch_handle_t handle);
/* Fills the list of supported attributes for a given audio port.
* As input, "port" contains the information (type, role, address etc...)
* needed by the HAL to identify the port.
* As output, "port" contains possible attributes (sampling rates, formats,
* channel masks, gain controllers...) for this port.
*/
int (*get_audio_port)(struct audio_hw_device *dev,
struct audio_port *port);
/* Set audio port configuration */
int (*set_audio_port_config)(struct audio_hw_device *dev,
const struct audio_port_config *config);
#ifdef AUDIO_LISTEN_ENABLED
/** This method creates the listen session and returns handle */
int (*open_listen_session)(struct audio_hw_device *dev,
listen_open_params_t *params,
struct listen_session** handle);
/** This method closes the listen session */
int (*close_listen_session)(struct audio_hw_device *dev,
struct listen_session* handle);
/** This method sets the mad observer callback */
int (*set_mad_observer)(struct audio_hw_device *dev,
listen_callback_t cb_func);
/**
* This method is used for setting listen hal specfic parameters.
* If multiple paramets are set in one call and setting any one of them
* fails it will return failure.
*/
int (*listen_set_parameters)(struct audio_hw_device *dev,
const char *kv_pairs);
#endif
};
typedef struct audio_hw_device audio_hw_device_t;
/** convenience API for opening and closing a supported device */
static inline int audio_hw_device_open(const struct hw_module_t* module,
struct audio_hw_device** device)
{
return module->methods->open(module, AUDIO_HARDWARE_INTERFACE,
(struct hw_device_t**)device);
}
static inline int audio_hw_device_close(struct audio_hw_device* device)
{
return device->common.close(&device->common);
}
__END_DECLS
#endif // ANDROID_AUDIO_INTERFACE_H
@@ -0,0 +1,102 @@
/*
* 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.
*/
/* This file contains shared utility functions to handle the tinyalsa
* implementation for Android internal audio, generally in the hardware layer.
* Some routines may log a fatal error on failure, as noted.
*/
#ifndef ANDROID_AUDIO_ALSAOPS_H
#define ANDROID_AUDIO_ALSAOPS_H
#include <cutils/log.h>
#include <system/audio.h>
#include <tinyalsa/asoundlib.h>
__BEGIN_DECLS
/* Converts audio_format to pcm_format.
* Parameters:
* format the audio_format_t to convert
*
* Logs a fatal error if format is not a valid convertible audio_format_t.
*/
static inline enum pcm_format pcm_format_from_audio_format(audio_format_t format)
{
switch (format) {
#ifdef HAVE_BIG_ENDIAN
case AUDIO_FORMAT_PCM_16_BIT:
return PCM_FORMAT_S16_BE;
case AUDIO_FORMAT_PCM_24_BIT_PACKED:
return PCM_FORMAT_S24_3BE;
case AUDIO_FORMAT_PCM_32_BIT:
return PCM_FORMAT_S32_BE;
case AUDIO_FORMAT_PCM_8_24_BIT:
return PCM_FORMAT_S24_BE;
#else
case AUDIO_FORMAT_PCM_16_BIT:
return PCM_FORMAT_S16_LE;
case AUDIO_FORMAT_PCM_24_BIT_PACKED:
return PCM_FORMAT_S24_3LE;
case AUDIO_FORMAT_PCM_32_BIT:
return PCM_FORMAT_S32_LE;
case AUDIO_FORMAT_PCM_8_24_BIT:
return PCM_FORMAT_S24_LE;
#endif
case AUDIO_FORMAT_PCM_FLOAT: /* there is no equivalent for float */
default:
LOG_ALWAYS_FATAL("pcm_format_from_audio_format: invalid audio format %#x", format);
return 0;
}
}
/* Converts pcm_format to audio_format.
* Parameters:
* format the pcm_format to convert
*
* Logs a fatal error if format is not a valid convertible pcm_format.
*/
static inline audio_format_t audio_format_from_pcm_format(enum pcm_format format)
{
switch (format) {
#ifdef HAVE_BIG_ENDIAN
case PCM_FORMAT_S16_BE:
return AUDIO_FORMAT_PCM_16_BIT;
case PCM_FORMAT_S24_3BE:
return AUDIO_FORMAT_PCM_24_BIT_PACKED;
case PCM_FORMAT_S24_BE:
return AUDIO_FORMAT_PCM_8_24_BIT;
case PCM_FORMAT_S32_BE:
return AUDIO_FORMAT_PCM_32_BIT;
#else
case PCM_FORMAT_S16_LE:
return AUDIO_FORMAT_PCM_16_BIT;
case PCM_FORMAT_S24_3LE:
return AUDIO_FORMAT_PCM_24_BIT_PACKED;
case PCM_FORMAT_S24_LE:
return AUDIO_FORMAT_PCM_8_24_BIT;
case PCM_FORMAT_S32_LE:
return AUDIO_FORMAT_PCM_32_BIT;
#endif
default:
LOG_ALWAYS_FATAL("audio_format_from_pcm_format: invalid pcm format %#x", format);
return 0;
}
}
__END_DECLS
#endif /* ANDROID_AUDIO_ALSAOPS_H */
@@ -0,0 +1,144 @@
/*
* Copyright (C) 2015, The CyanogenMod 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 CM_AUDIO_AMPLIFIER_INTERFACE_H
#define CM_AUDIO_AMPLIFIER_INTERFACE_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <hardware/audio.h>
#include <hardware/hardware.h>
#include <system/audio.h>
__BEGIN_DECLS
#define AMPLIFIER_HARDWARE_MODULE_ID "audio_amplifier"
#define AMPLIFIER_HARDWARE_INTERFACE "audio_amplifier_hw_if"
#define AMPLIFIER_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
#define AMPLIFIER_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
#define AMPLIFIER_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0)
#define AMPLIFIER_DEVICE_API_VERSION_CURRENT AMPLIFIER_DEVICE_API_VERSION_2_0
struct str_parms;
typedef struct amplifier_device {
/**
* Common methods of the amplifier device. This *must* be the first member
* of amplifier_device as users of this structure will cast a hw_device_t
* to amplifier_device pointer in contexts where it's known
* the hw_device_t references a amplifier_device.
*/
struct hw_device_t common;
/**
* Notify amplifier device of current input devices
*
* This function should handle only input devices.
*/
int (*set_input_devices)(struct amplifier_device *device, uint32_t devices);
/**
* Notify amplifier device of current output devices
*
* This function should handle only output devices.
*/
int (*set_output_devices)(struct amplifier_device *device, uint32_t devices);
/**
* Notify amplifier device of output device enable/disable
*
* This function should handle only output devices.
*/
int (*enable_output_devices)(struct amplifier_device *device,
uint32_t devices, bool enable);
/**
* Notify amplifier device of input device enable/disable
*
* This function should handle only input devices.
*/
int (*enable_input_devices)(struct amplifier_device *device,
uint32_t devices, bool enable);
/**
* Notify amplifier device about current audio mode
*/
int (*set_mode)(struct amplifier_device *device, audio_mode_t mode);
/**
* Notify amplifier device that an output stream has started
*/
int (*output_stream_start)(struct amplifier_device *device,
struct audio_stream_out *stream, bool offload);
/**
* Notify amplifier device that an input stream has started
*/
int (*input_stream_start)(struct amplifier_device *device,
struct audio_stream_in *stream);
/**
* Notify amplifier device that an output stream has stopped
*/
int (*output_stream_standby)(struct amplifier_device *device,
struct audio_stream_out *stream);
/**
* Notify amplifier device that an input stream has stopped
*/
int (*input_stream_standby)(struct amplifier_device *device,
struct audio_stream_in *stream);
/**
* set/get output audio device parameters.
*/
int (*set_parameters)(struct amplifier_device *device,
struct str_parms *parms);
} amplifier_device_t;
typedef struct amplifier_module {
/**
* Common methods of the amplifier module. This *must* be the first member
* of amplifier_module as users of this structure will cast a hw_module_t
* to amplifier_module pointer in contexts where it's known
* the hw_module_t references a amplifier_module.
*/
struct hw_module_t common;
} amplifier_module_t;
/** convenience API for opening and closing a supported device */
static inline int amplifier_device_open(const struct hw_module_t *module,
struct amplifier_device **device)
{
return module->methods->open(module, AMPLIFIER_HARDWARE_INTERFACE,
(struct hw_device_t **) device);
}
static inline int amplifier_device_close(struct amplifier_device *device)
{
return device->common.close(&device->common);
}
__END_DECLS
#endif // CM_AUDIO_AMPLIFIER_INTERFACE_H
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,457 @@
/*
* 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_AUDIO_POLICY_INTERFACE_H
#define ANDROID_AUDIO_POLICY_INTERFACE_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <hardware/hardware.h>
#include <system/audio.h>
#include <system/audio_policy.h>
__BEGIN_DECLS
/**
* The id of this module
*/
#define AUDIO_POLICY_HARDWARE_MODULE_ID "audio_policy"
/**
* Name of the audio devices to open
*/
#define AUDIO_POLICY_INTERFACE "policy"
/* ---------------------------------------------------------------------------- */
/*
* The audio_policy and audio_policy_service_ops structs define the
* communication interfaces between the platform specific audio policy manager
* and Android generic audio policy manager.
* The platform specific audio policy manager must implement methods of the
* audio_policy struct.
* This implementation makes use of the audio_policy_service_ops to control
* the activity and configuration of audio input and output streams.
*
* The platform specific audio policy manager is in charge of the audio
* routing and volume control policies for a given platform.
* The main roles of this module are:
* - keep track of current system state (removable device connections, phone
* state, user requests...).
* System state changes and user actions are notified to audio policy
* manager with methods of the audio_policy.
*
* - process get_output() queries received when AudioTrack objects are
* created: Those queries return a handler on an output that has been
* selected, configured and opened by the audio policy manager and that
* must be used by the AudioTrack when registering to the AudioFlinger
* with the createTrack() method.
* When the AudioTrack object is released, a release_output() query
* is received and the audio policy manager can decide to close or
* reconfigure the output depending on other streams using this output and
* current system state.
*
* - similarly process get_input() and release_input() queries received from
* AudioRecord objects and configure audio inputs.
* - process volume control requests: the stream volume is converted from
* an index value (received from UI) to a float value applicable to each
* output as a function of platform specific settings and current output
* route (destination device). It also make sure that streams are not
* muted if not allowed (e.g. camera shutter sound in some countries).
*/
/* XXX: this should be defined OUTSIDE of frameworks/base */
struct effect_descriptor_s;
struct audio_policy {
/*
* configuration functions
*/
/* indicate a change in device connection status */
int (*set_device_connection_state)(struct audio_policy *pol,
audio_devices_t device,
audio_policy_dev_state_t state,
const char *device_address);
/* retrieve a device connection status */
audio_policy_dev_state_t (*get_device_connection_state)(
const struct audio_policy *pol,
audio_devices_t device,
const char *device_address);
/* indicate a change in phone state. Valid phones states are defined
* by audio_mode_t */
void (*set_phone_state)(struct audio_policy *pol, audio_mode_t state);
/* deprecated, never called (was "indicate a change in ringer mode") */
void (*set_ringer_mode)(struct audio_policy *pol, uint32_t mode,
uint32_t mask);
/* force using a specific device category for the specified usage */
void (*set_force_use)(struct audio_policy *pol,
audio_policy_force_use_t usage,
audio_policy_forced_cfg_t config);
/* retrieve current device category forced for a given usage */
audio_policy_forced_cfg_t (*get_force_use)(const struct audio_policy *pol,
audio_policy_force_use_t usage);
/* if can_mute is true, then audio streams that are marked ENFORCED_AUDIBLE
* can still be muted. */
void (*set_can_mute_enforced_audible)(struct audio_policy *pol,
bool can_mute);
/* check proper initialization */
int (*init_check)(const struct audio_policy *pol);
/*
* Audio routing query functions
*/
/* request an output appropriate for playback of the supplied stream type and
* parameters */
audio_io_handle_t (*get_output)(struct audio_policy *pol,
audio_stream_type_t stream,
uint32_t samplingRate,
audio_format_t format,
audio_channel_mask_t channelMask,
audio_output_flags_t flags,
const audio_offload_info_t *offloadInfo);
/* indicates to the audio policy manager that the output starts being used
* by corresponding stream. */
int (*start_output)(struct audio_policy *pol,
audio_io_handle_t output,
audio_stream_type_t stream,
int session);
/* indicates to the audio policy manager that the output stops being used
* by corresponding stream. */
int (*stop_output)(struct audio_policy *pol,
audio_io_handle_t output,
audio_stream_type_t stream,
int session);
/* releases the output. */
void (*release_output)(struct audio_policy *pol, audio_io_handle_t output);
/* request an input appropriate for record from the supplied device with
* supplied parameters. */
audio_io_handle_t (*get_input)(struct audio_policy *pol, audio_source_t inputSource,
uint32_t samplingRate,
audio_format_t format,
audio_channel_mask_t channelMask,
audio_in_acoustics_t acoustics);
/* indicates to the audio policy manager that the input starts being used */
int (*start_input)(struct audio_policy *pol, audio_io_handle_t input);
/* indicates to the audio policy manager that the input stops being used. */
int (*stop_input)(struct audio_policy *pol, audio_io_handle_t input);
/* releases the input. */
void (*release_input)(struct audio_policy *pol, audio_io_handle_t input);
/*
* volume control functions
*/
/* initialises stream volume conversion parameters by specifying volume
* index range. The index range for each stream is defined by AudioService. */
void (*init_stream_volume)(struct audio_policy *pol,
audio_stream_type_t stream,
int index_min,
int index_max);
/* sets the new stream volume at a level corresponding to the supplied
* index. The index is within the range specified by init_stream_volume() */
int (*set_stream_volume_index)(struct audio_policy *pol,
audio_stream_type_t stream,
int index);
/* retrieve current volume index for the specified stream */
int (*get_stream_volume_index)(const struct audio_policy *pol,
audio_stream_type_t stream,
int *index);
/* sets the new stream volume at a level corresponding to the supplied
* index for the specified device.
* The index is within the range specified by init_stream_volume() */
int (*set_stream_volume_index_for_device)(struct audio_policy *pol,
audio_stream_type_t stream,
int index,
audio_devices_t device);
/* retrieve current volume index for the specified stream for the specified device */
int (*get_stream_volume_index_for_device)(const struct audio_policy *pol,
audio_stream_type_t stream,
int *index,
audio_devices_t device);
/* return the strategy corresponding to a given stream type */
uint32_t (*get_strategy_for_stream)(const struct audio_policy *pol,
audio_stream_type_t stream);
/* return the enabled output devices for the given stream type */
audio_devices_t (*get_devices_for_stream)(const struct audio_policy *pol,
audio_stream_type_t stream);
/* Audio effect management */
audio_io_handle_t (*get_output_for_effect)(struct audio_policy *pol,
const struct effect_descriptor_s *desc);
int (*register_effect)(struct audio_policy *pol,
const struct effect_descriptor_s *desc,
audio_io_handle_t output,
uint32_t strategy,
int session,
int id);
int (*unregister_effect)(struct audio_policy *pol, int id);
int (*set_effect_enabled)(struct audio_policy *pol, int id, bool enabled);
bool (*is_stream_active)(const struct audio_policy *pol,
audio_stream_type_t stream,
uint32_t in_past_ms);
bool (*is_stream_active_remotely)(const struct audio_policy *pol,
audio_stream_type_t stream,
uint32_t in_past_ms);
bool (*is_source_active)(const struct audio_policy *pol,
audio_source_t source);
/* dump state */
int (*dump)(const struct audio_policy *pol, int fd);
/* check if offload is possible for given sample rate, bitrate, duration, ... */
bool (*is_offload_supported)(const struct audio_policy *pol,
const audio_offload_info_t *info);
};
struct audio_policy_service_ops {
/*
* Audio output Control functions
*/
/* Opens an audio output with the requested parameters.
*
* The parameter values can indicate to use the default values in case the
* audio policy manager has no specific requirements for the output being
* opened.
*
* When the function returns, the parameter values reflect the actual
* values used by the audio hardware output stream.
*
* The audio policy manager can check if the proposed parameters are
* suitable or not and act accordingly.
*/
audio_io_handle_t (*open_output)(void *service,
audio_devices_t *pDevices,
uint32_t *pSamplingRate,
audio_format_t *pFormat,
audio_channel_mask_t *pChannelMask,
uint32_t *pLatencyMs,
audio_output_flags_t flags);
/* creates a special output that is duplicated to the two outputs passed as
* arguments. The duplication is performed by
* a special mixer thread in the AudioFlinger.
*/
audio_io_handle_t (*open_duplicate_output)(void *service,
audio_io_handle_t output1,
audio_io_handle_t output2);
/* closes the output stream */
int (*close_output)(void *service, audio_io_handle_t output);
/* suspends the output.
*
* When an output is suspended, the corresponding audio hardware output
* stream is placed in standby and the AudioTracks attached to the mixer
* thread are still processed but the output mix is discarded.
*/
int (*suspend_output)(void *service, audio_io_handle_t output);
/* restores a suspended output. */
int (*restore_output)(void *service, audio_io_handle_t output);
/* */
/* Audio input Control functions */
/* */
/* opens an audio input
* deprecated - new implementations should use open_input_on_module,
* and the acoustics parameter is ignored
*/
audio_io_handle_t (*open_input)(void *service,
audio_devices_t *pDevices,
uint32_t *pSamplingRate,
audio_format_t *pFormat,
audio_channel_mask_t *pChannelMask,
audio_in_acoustics_t acoustics);
/* closes an audio input */
int (*close_input)(void *service, audio_io_handle_t input);
/* */
/* misc control functions */
/* */
/* set a stream volume for a particular output.
*
* For the same user setting, a given stream type can have different
* volumes for each output (destination device) it is attached to.
*/
int (*set_stream_volume)(void *service,
audio_stream_type_t stream,
float volume,
audio_io_handle_t output,
int delay_ms);
/* invalidate a stream type, causing a reroute to an unspecified new output */
int (*invalidate_stream)(void *service,
audio_stream_type_t stream);
/* function enabling to send proprietary informations directly from audio
* policy manager to audio hardware interface. */
void (*set_parameters)(void *service,
audio_io_handle_t io_handle,
const char *kv_pairs,
int delay_ms);
/* function enabling to receive proprietary informations directly from
* audio hardware interface to audio policy manager.
*
* Returns a pointer to a heap allocated string. The caller is responsible
* for freeing the memory for it using free().
*/
char * (*get_parameters)(void *service, audio_io_handle_t io_handle,
const char *keys);
/* request the playback of a tone on the specified stream.
* used for instance to replace notification sounds when playing over a
* telephony device during a phone call.
*/
int (*start_tone)(void *service,
audio_policy_tone_t tone,
audio_stream_type_t stream);
int (*stop_tone)(void *service);
/* set down link audio volume. */
int (*set_voice_volume)(void *service,
float volume,
int delay_ms);
/* move effect to the specified output */
int (*move_effects)(void *service,
int session,
audio_io_handle_t src_output,
audio_io_handle_t dst_output);
/* loads an audio hw module.
*
* The module name passed is the base name of the HW module library, e.g "primary" or "a2dp".
* The function returns a handle on the module that will be used to specify a particular
* module when calling open_output_on_module() or open_input_on_module()
*/
audio_module_handle_t (*load_hw_module)(void *service,
const char *name);
/* Opens an audio output on a particular HW module.
*
* Same as open_output() but specifying a specific HW module on which the output must be opened.
*/
audio_io_handle_t (*open_output_on_module)(void *service,
audio_module_handle_t module,
audio_devices_t *pDevices,
uint32_t *pSamplingRate,
audio_format_t *pFormat,
audio_channel_mask_t *pChannelMask,
uint32_t *pLatencyMs,
audio_output_flags_t flags,
const audio_offload_info_t *offloadInfo);
/* Opens an audio input on a particular HW module.
*
* Same as open_input() but specifying a specific HW module on which the input must be opened.
* Also removed deprecated acoustics parameter
*/
audio_io_handle_t (*open_input_on_module)(void *service,
audio_module_handle_t module,
audio_devices_t *pDevices,
uint32_t *pSamplingRate,
audio_format_t *pFormat,
audio_channel_mask_t *pChannelMask);
};
/**********************************************************************/
/**
* 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.
*/
typedef struct audio_policy_module {
struct hw_module_t common;
} audio_policy_module_t;
struct audio_policy_device {
/**
* Common methods of the audio policy device. This *must* be the first member of
* audio_policy_device as users of this structure will cast a hw_device_t to
* audio_policy_device pointer in contexts where it's known the hw_device_t references an
* audio_policy_device.
*/
struct hw_device_t common;
int (*create_audio_policy)(const struct audio_policy_device *device,
struct audio_policy_service_ops *aps_ops,
void *service,
struct audio_policy **ap);
int (*destroy_audio_policy)(const struct audio_policy_device *device,
struct audio_policy *ap);
};
/** convenience API for opening and closing a supported device */
static inline int audio_policy_dev_open(const hw_module_t* module,
struct audio_policy_device** device)
{
return module->methods->open(module, AUDIO_POLICY_INTERFACE,
(hw_device_t**)device);
}
static inline int audio_policy_dev_close(struct audio_policy_device* device)
{
return device->common.close(&device->common);
}
__END_DECLS
#endif // ANDROID_AUDIO_POLICY_INTERFACE_H
@@ -0,0 +1,595 @@
/*
* Copyright (C) 2012 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_BLUETOOTH_H
#define ANDROID_INCLUDE_BLUETOOTH_H
#include <stdbool.h>
#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <hardware/hardware.h>
__BEGIN_DECLS
/**
* The Bluetooth Hardware Module ID
*/
#define BT_HARDWARE_MODULE_ID "bluetooth"
#define BT_STACK_MODULE_ID "bluetooth"
#define BT_STACK_TEST_MODULE_ID "bluetooth_test"
/* Bluetooth profile interface IDs */
#define BT_PROFILE_HANDSFREE_ID "handsfree"
#define BT_PROFILE_HANDSFREE_CLIENT_ID "handsfree_client"
#define BT_PROFILE_ADVANCED_AUDIO_ID "a2dp"
#define BT_PROFILE_ADVANCED_AUDIO_SINK_ID "a2dp_sink"
#define BT_PROFILE_HEALTH_ID "health"
#define BT_PROFILE_SOCKETS_ID "socket"
#define BT_PROFILE_HIDHOST_ID "hidhost"
#define BT_PROFILE_HIDDEV_ID "hiddev"
#define BT_PROFILE_PAN_ID "pan"
#define BT_PROFILE_MAP_CLIENT_ID "map_client"
#define BT_PROFILE_SDP_CLIENT_ID "sdp"
#define BT_PROFILE_GATT_ID "gatt"
#define BT_PROFILE_AV_RC_ID "avrcp"
#define WIPOWER_PROFILE_ID "wipower"
#define BT_PROFILE_AV_RC_CTRL_ID "avrcp_ctrl"
/** Bluetooth Address */
typedef struct {
uint8_t address[6];
} __attribute__((packed))bt_bdaddr_t;
/** Bluetooth Device Name */
typedef struct {
uint8_t name[249];
} __attribute__((packed))bt_bdname_t;
/** Bluetooth Adapter Visibility Modes*/
typedef enum {
BT_SCAN_MODE_NONE,
BT_SCAN_MODE_CONNECTABLE,
BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE
} bt_scan_mode_t;
/** Bluetooth Adapter State */
typedef enum {
BT_STATE_OFF,
BT_STATE_ON
} bt_state_t;
/** Bluetooth Error Status */
/** We need to build on this */
typedef enum {
BT_STATUS_SUCCESS,
BT_STATUS_FAIL,
BT_STATUS_NOT_READY,
BT_STATUS_NOMEM,
BT_STATUS_BUSY,
BT_STATUS_DONE, /* request already completed */
BT_STATUS_UNSUPPORTED,
BT_STATUS_PARM_INVALID,
BT_STATUS_UNHANDLED,
BT_STATUS_AUTH_FAILURE,
BT_STATUS_RMT_DEV_DOWN,
BT_STATUS_AUTH_REJECTED
} bt_status_t;
/** Bluetooth PinKey Code */
typedef struct {
uint8_t pin[16];
} __attribute__((packed))bt_pin_code_t;
typedef struct {
uint8_t status;
uint8_t ctrl_state; /* stack reported state */
uint64_t tx_time; /* in ms */
uint64_t rx_time; /* in ms */
uint64_t idle_time; /* in ms */
uint64_t energy_used; /* a product of mA, V and ms */
} __attribute__((packed))bt_activity_energy_info;
/** Bluetooth Adapter Discovery state */
typedef enum {
BT_DISCOVERY_STOPPED,
BT_DISCOVERY_STARTED
} bt_discovery_state_t;
/** Bluetooth ACL connection state */
typedef enum {
BT_ACL_STATE_CONNECTED,
BT_ACL_STATE_DISCONNECTED
} bt_acl_state_t;
/** Bluetooth 128-bit UUID */
typedef struct {
uint8_t uu[16];
} bt_uuid_t;
/** Bluetooth SDP service record */
typedef struct
{
bt_uuid_t uuid;
uint16_t channel;
char name[256]; // what's the maximum length
} bt_service_record_t;
/** Bluetooth Remote Version info */
typedef struct
{
int version;
int sub_ver;
int manufacturer;
} bt_remote_version_t;
typedef struct
{
uint16_t version_supported;
uint8_t local_privacy_enabled;
uint8_t max_adv_instance;
uint8_t rpa_offload_supported;
uint8_t max_irk_list_size;
uint8_t max_adv_filter_supported;
uint8_t activity_energy_info_supported;
uint16_t scan_result_storage_size;
uint16_t total_trackable_advertisers;
bool extended_scan_support;
bool debug_logging_supported;
}bt_local_le_features_t;
/* Bluetooth Adapter and Remote Device property types */
typedef enum {
/* Properties common to both adapter and remote device */
/**
* Description - Bluetooth Device Name
* Access mode - Adapter name can be GET/SET. Remote device can be GET
* Data type - bt_bdname_t
*/
BT_PROPERTY_BDNAME = 0x1,
/**
* Description - Bluetooth Device Address
* Access mode - Only GET.
* Data type - bt_bdaddr_t
*/
BT_PROPERTY_BDADDR,
/**
* Description - Bluetooth Service 128-bit UUIDs
* Access mode - Only GET.
* Data type - Array of bt_uuid_t (Array size inferred from property length).
*/
BT_PROPERTY_UUIDS,
/**
* Description - Bluetooth Class of Device as found in Assigned Numbers
* Access mode - Only GET.
* Data type - uint32_t.
*/
BT_PROPERTY_CLASS_OF_DEVICE,
/**
* Description - Device Type - BREDR, BLE or DUAL Mode
* Access mode - Only GET.
* Data type - bt_device_type_t
*/
BT_PROPERTY_TYPE_OF_DEVICE,
/**
* Description - Bluetooth Service Record
* Access mode - Only GET.
* Data type - bt_service_record_t
*/
BT_PROPERTY_SERVICE_RECORD,
/* Properties unique to adapter */
/**
* Description - Bluetooth Adapter scan mode
* Access mode - GET and SET
* Data type - bt_scan_mode_t.
*/
BT_PROPERTY_ADAPTER_SCAN_MODE,
/**
* Description - List of bonded devices
* Access mode - Only GET.
* Data type - Array of bt_bdaddr_t of the bonded remote devices
* (Array size inferred from property length).
*/
BT_PROPERTY_ADAPTER_BONDED_DEVICES,
/**
* Description - Bluetooth Adapter Discovery timeout (in seconds)
* Access mode - GET and SET
* Data type - uint32_t
*/
BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
/* Properties unique to remote device */
/**
* Description - User defined friendly name of the remote device
* Access mode - GET and SET
* Data type - bt_bdname_t.
*/
BT_PROPERTY_REMOTE_FRIENDLY_NAME,
/**
* Description - RSSI value of the inquired remote device
* Access mode - Only GET.
* Data type - int32_t.
*/
BT_PROPERTY_REMOTE_RSSI,
/**
* Description - Remote version info
* Access mode - SET/GET.
* Data type - bt_remote_version_t.
*/
BT_PROPERTY_REMOTE_VERSION_INFO,
/**
* Description - Local LE features
* Access mode - GET.
* Data type - bt_local_le_features_t.
*/
BT_PROPERTY_LOCAL_LE_FEATURES,
BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP = 0xFF,
} bt_property_type_t;
/** Bluetooth Adapter Property data structure */
typedef struct
{
bt_property_type_t type;
int len;
void *val;
} bt_property_t;
/** Bluetooth Device Type */
typedef enum {
BT_DEVICE_DEVTYPE_BREDR = 0x1,
BT_DEVICE_DEVTYPE_BLE,
BT_DEVICE_DEVTYPE_DUAL
} bt_device_type_t;
/** Bluetooth Bond state */
typedef enum {
BT_BOND_STATE_NONE,
BT_BOND_STATE_BONDING,
BT_BOND_STATE_BONDED
} bt_bond_state_t;
/** Bluetooth SSP Bonding Variant */
typedef enum {
BT_SSP_VARIANT_PASSKEY_CONFIRMATION,
BT_SSP_VARIANT_PASSKEY_ENTRY,
BT_SSP_VARIANT_CONSENT,
BT_SSP_VARIANT_PASSKEY_NOTIFICATION
} bt_ssp_variant_t;
#define BT_MAX_NUM_UUIDS 32
/** Bluetooth Interface callbacks */
/** Bluetooth Enable/Disable Callback. */
typedef void (*adapter_state_changed_callback)(bt_state_t state);
/** GET/SET Adapter Properties callback */
/* TODO: For the GET/SET property APIs/callbacks, we may need a session
* identifier to associate the call with the callback. This would be needed
* whenever more than one simultaneous instance of the same adapter_type
* is get/set.
*
* If this is going to be handled in the Java framework, then we do not need
* to manage sessions here.
*/
typedef void (*adapter_properties_callback)(bt_status_t status,
int num_properties,
bt_property_t *properties);
/** GET/SET Remote Device Properties callback */
/** TODO: For remote device properties, do not see a need to get/set
* multiple properties - num_properties shall be 1
*/
typedef void (*remote_device_properties_callback)(bt_status_t status,
bt_bdaddr_t *bd_addr,
int num_properties,
bt_property_t *properties);
/** New device discovered callback */
/** If EIR data is not present, then BD_NAME and RSSI shall be NULL and -1
* respectively */
typedef void (*device_found_callback)(int num_properties,
bt_property_t *properties);
/** Discovery state changed callback */
typedef void (*discovery_state_changed_callback)(bt_discovery_state_t state);
/** Bluetooth Legacy PinKey Request callback */
typedef void (*pin_request_callback)(bt_bdaddr_t *remote_bd_addr,
bt_bdname_t *bd_name, uint32_t cod, bool min_16_digit);
/** Bluetooth SSP Request callback - Just Works & Numeric Comparison*/
/** pass_key - Shall be 0 for BT_SSP_PAIRING_VARIANT_CONSENT &
* BT_SSP_PAIRING_PASSKEY_ENTRY */
/* TODO: Passkey request callback shall not be needed for devices with display
* capability. We still need support this in the stack for completeness */
typedef void (*ssp_request_callback)(bt_bdaddr_t *remote_bd_addr,
bt_bdname_t *bd_name,
uint32_t cod,
bt_ssp_variant_t pairing_variant,
uint32_t pass_key);
/** Bluetooth Bond state changed callback */
/* Invoked in response to create_bond, cancel_bond or remove_bond */
typedef void (*bond_state_changed_callback)(bt_status_t status,
bt_bdaddr_t *remote_bd_addr,
bt_bond_state_t state);
/** Bluetooth ACL connection state changed callback */
typedef void (*acl_state_changed_callback)(bt_status_t status, bt_bdaddr_t *remote_bd_addr,
bt_acl_state_t state);
typedef enum {
ASSOCIATE_JVM,
DISASSOCIATE_JVM
} bt_cb_thread_evt;
/** Thread Associate/Disassociate JVM Callback */
/* Callback that is invoked by the callback thread to allow upper layer to attach/detach to/from
* the JVM */
typedef void (*callback_thread_event)(bt_cb_thread_evt evt);
/** Bluetooth Test Mode Callback */
/* Receive any HCI event from controller. Must be in DUT Mode for this callback to be received */
typedef void (*dut_mode_recv_callback)(uint16_t opcode, uint8_t *buf, uint8_t len);
/** Bluetooth HCI event Callback */
/* Receive any HCI event from controller for raw commands */
typedef void (*hci_event_recv_callback)(uint8_t event_code, uint8_t *buf, uint8_t len);
/* LE Test mode callbacks
* This callback shall be invoked whenever the le_tx_test, le_rx_test or le_test_end is invoked
* The num_packets is valid only for le_test_end command */
typedef void (*le_test_mode_callback)(bt_status_t status, uint16_t num_packets);
/** Callback invoked when energy details are obtained */
/* Ctrl_state-Current controller state-Active-1,scan-2,or idle-3 state as defined by HCI spec.
* If the ctrl_state value is 0, it means the API call failed
* Time values-In milliseconds as returned by the controller
* Energy used-Value as returned by the controller
* Status-Provides the status of the read_energy_info API call */
typedef void (*energy_info_callback)(bt_activity_energy_info *energy_info);
/** TODO: Add callbacks for Link Up/Down and other generic
* notifications/callbacks */
/** Bluetooth DM callback structure. */
typedef struct {
/** set to sizeof(bt_callbacks_t) */
size_t size;
adapter_state_changed_callback adapter_state_changed_cb;
adapter_properties_callback adapter_properties_cb;
remote_device_properties_callback remote_device_properties_cb;
device_found_callback device_found_cb;
discovery_state_changed_callback discovery_state_changed_cb;
pin_request_callback pin_request_cb;
ssp_request_callback ssp_request_cb;
bond_state_changed_callback bond_state_changed_cb;
acl_state_changed_callback acl_state_changed_cb;
callback_thread_event thread_evt_cb;
dut_mode_recv_callback dut_mode_recv_cb;
le_test_mode_callback le_test_mode_cb;
energy_info_callback energy_info_cb;
hci_event_recv_callback hci_event_recv_cb;
} bt_callbacks_t;
typedef void (*alarm_cb)(void *data);
typedef bool (*set_wake_alarm_callout)(uint64_t delay_millis, bool should_wake, alarm_cb cb, void *data);
typedef int (*acquire_wake_lock_callout)(const char *lock_name);
typedef int (*release_wake_lock_callout)(const char *lock_name);
/** The set of functions required by bluedroid to set wake alarms and
* grab wake locks. This struct is passed into the stack through the
* |set_os_callouts| function on |bt_interface_t|.
*/
typedef struct {
/* set to sizeof(bt_os_callouts_t) */
size_t size;
set_wake_alarm_callout set_wake_alarm;
acquire_wake_lock_callout acquire_wake_lock;
release_wake_lock_callout release_wake_lock;
} bt_os_callouts_t;
/** NOTE: By default, no profiles are initialized at the time of init/enable.
* Whenever the application invokes the 'init' API of a profile, then one of
* the following shall occur:
*
* 1.) If Bluetooth is not enabled, then the Bluetooth core shall mark the
* profile as enabled. Subsequently, when the application invokes the
* Bluetooth 'enable', as part of the enable sequence the profile that were
* marked shall be enabled by calling appropriate stack APIs. The
* 'adapter_properties_cb' shall return the list of UUIDs of the
* enabled profiles.
*
* 2.) If Bluetooth is enabled, then the Bluetooth core shall invoke the stack
* profile API to initialize the profile and trigger a
* 'adapter_properties_cb' with the current list of UUIDs including the
* newly added profile's UUID.
*
* The reverse shall occur whenever the profile 'cleanup' APIs are invoked
*/
/** Represents the standard Bluetooth DM interface. */
typedef struct {
/** set to sizeof(bt_interface_t) */
size_t size;
/**
* Opens the interface and provides the callback routines
* to the implemenation of this interface.
*/
int (*init)(bt_callbacks_t* callbacks );
/** Enable Bluetooth. */
int (*enable)(bool guest_mode);
/** Disable Bluetooth. */
int (*disable)(void);
/** Closes the interface. */
void (*cleanup)(void);
/** SSR cleanup. */
void (*ssrcleanup)(void);
/** Get all Bluetooth Adapter properties at init */
int (*get_adapter_properties)(void);
/** Get Bluetooth Adapter property of 'type' */
int (*get_adapter_property)(bt_property_type_t type);
/** Set Bluetooth Adapter property of 'type' */
/* Based on the type, val shall be one of
* bt_bdaddr_t or bt_bdname_t or bt_scanmode_t etc
*/
int (*set_adapter_property)(const bt_property_t *property);
/** Get all Remote Device properties */
int (*get_remote_device_properties)(bt_bdaddr_t *remote_addr);
/** Get Remote Device property of 'type' */
int (*get_remote_device_property)(bt_bdaddr_t *remote_addr,
bt_property_type_t type);
/** Set Remote Device property of 'type' */
int (*set_remote_device_property)(bt_bdaddr_t *remote_addr,
const bt_property_t *property);
/** Get Remote Device's service record for the given UUID */
int (*get_remote_service_record)(bt_bdaddr_t *remote_addr,
bt_uuid_t *uuid);
/** Start SDP to get remote services */
int (*get_remote_services)(bt_bdaddr_t *remote_addr);
/** Start Discovery */
int (*start_discovery)(void);
/** Cancel Discovery */
int (*cancel_discovery)(void);
/** Create Bluetooth Bonding */
int (*create_bond)(const bt_bdaddr_t *bd_addr, int transport);
/** Remove Bond */
int (*remove_bond)(const bt_bdaddr_t *bd_addr);
/** Cancel Bond */
int (*cancel_bond)(const bt_bdaddr_t *bd_addr);
/**
* Get the connection status for a given remote device.
* return value of 0 means the device is not connected,
* non-zero return status indicates an active connection.
*/
int (*get_connection_state)(const bt_bdaddr_t *bd_addr);
/** BT Legacy PinKey Reply */
/** If accept==FALSE, then pin_len and pin_code shall be 0x0 */
int (*pin_reply)(const bt_bdaddr_t *bd_addr, uint8_t accept,
uint8_t pin_len, bt_pin_code_t *pin_code);
/** BT SSP Reply - Just Works, Numeric Comparison and Passkey
* passkey shall be zero for BT_SSP_VARIANT_PASSKEY_COMPARISON &
* BT_SSP_VARIANT_CONSENT
* For BT_SSP_VARIANT_PASSKEY_ENTRY, if accept==FALSE, then passkey
* shall be zero */
int (*ssp_reply)(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
uint8_t accept, uint32_t passkey);
/** Get Bluetooth profile interface */
const void* (*get_profile_interface) (const char *profile_id);
/** Bluetooth Test Mode APIs - Bluetooth must be enabled for these APIs */
/* Configure DUT Mode - Use this mode to enter/exit DUT mode */
int (*dut_mode_configure)(uint8_t enable);
/* Send any test HCI (vendor-specific) command to the controller. Must be in DUT Mode */
int (*dut_mode_send)(uint16_t opcode, uint8_t *buf, uint8_t len);
/* Send any test HCI command to the controller. */
int (*hci_cmd_send)(uint16_t opcode, uint8_t *buf, uint8_t len);
/** BLE Test Mode APIs */
/* opcode MUST be one of: LE_Receiver_Test, LE_Transmitter_Test, LE_Test_End */
int (*le_test_mode)(uint16_t opcode, uint8_t *buf, uint8_t len);
/* enable or disable bluetooth HCI snoop log */
int (*config_hci_snoop_log)(uint8_t enable);
/** Sets the OS call-out functions that bluedroid needs for alarms and wake locks.
* This should be called immediately after a successful |init|.
*/
int (*set_os_callouts)(bt_os_callouts_t *callouts);
/** Read Energy info details - return value indicates BT_STATUS_SUCCESS or BT_STATUS_NOT_READY
* Success indicates that the VSC command was sent to controller
*/
int (*read_energy_info)();
/**
* Native support for dumpsys function
* Function is synchronous and |fd| is owned by caller.
*/
void (*dump)(int fd);
/**
* Clear /data/misc/bt_config.conf and erase all stored connections
*/
int (*config_clear)(void);
/** BT stack Test interface */
const void* (*get_testapp_interface)(int test_app_profile);
/**
* Clear (reset) the dynamic portion of the device interoperability database.
*/
void (*interop_database_clear)(void);
/**
* Add a new device interoperability workaround for a remote device whose
* first |len| bytes of the its device address match |addr|.
* NOTE: |feature| has to match an item defined in interop_feature_t (interop.h).
*/
void (*interop_database_add)(uint16_t feature, const bt_bdaddr_t *addr, size_t len);
} bt_interface_t;
/** TODO: Need to add APIs for Service Discovery, Service authorization and
* connection management. Also need to add APIs for configuring
* properties of remote bonded devices such as name, UUID etc. */
typedef struct {
struct hw_device_t common;
const bt_interface_t* (*get_bluetooth_interface)();
} bluetooth_device_t;
typedef bluetooth_device_t bluetooth_module_t;
__END_DECLS
#endif /* ANDROID_INCLUDE_BLUETOOTH_H */
@@ -0,0 +1,133 @@
/*
* Copyright (C) 2013-2014, The Linux Foundation. All rights reserved.
* Not a Contribution.
*
* Copyright (C) 2012 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_BT_AV_H
#define ANDROID_INCLUDE_BT_AV_H
__BEGIN_DECLS
/* Bluetooth AV connection states */
typedef enum {
BTAV_CONNECTION_STATE_DISCONNECTED = 0,
BTAV_CONNECTION_STATE_CONNECTING,
BTAV_CONNECTION_STATE_CONNECTED,
BTAV_CONNECTION_STATE_DISCONNECTING
} btav_connection_state_t;
/* Bluetooth AV datapath states */
typedef enum {
BTAV_AUDIO_STATE_REMOTE_SUSPEND = 0,
BTAV_AUDIO_STATE_STOPPED,
BTAV_AUDIO_STATE_STARTED,
} btav_audio_state_t;
/** Callback for connection state change.
* state will have one of the values from btav_connection_state_t
*/
typedef void (* btav_connection_state_callback)(btav_connection_state_t state,
bt_bdaddr_t *bd_addr);
/** Callback for audiopath state change.
* state will have one of the values from btav_audio_state_t
*/
typedef void (* btav_audio_state_callback)(btav_audio_state_t state,
bt_bdaddr_t *bd_addr);
/** Callback for connection priority of device for incoming connection
* btav_connection_priority_t
*/
typedef void (* btav_connection_priority_callback)(bt_bdaddr_t *bd_addr);
/** Callback for audio configuration change.
* Used only for the A2DP sink interface.
* state will have one of the values from btav_audio_state_t
* sample_rate: sample rate in Hz
* channel_count: number of channels (1 for mono, 2 for stereo)
*/
typedef void (* btav_audio_config_callback)(bt_bdaddr_t *bd_addr,
uint32_t sample_rate,
uint8_t channel_count);
/** Callback for updating apps for A2dp multicast state.
*/
typedef void (* btav_is_multicast_enabled_callback)(int state);
/*
* Callback for audio focus request to be used only in
* case of A2DP Sink. This is required because we are using
* AudioTrack approach for audio data rendering.
*/
typedef void (* btav_audio_focus_request_callback)(bt_bdaddr_t *bd_addr);
/** BT-AV callback structure. */
typedef struct {
/** set to sizeof(btav_callbacks_t) */
size_t size;
btav_connection_state_callback connection_state_cb;
btav_audio_state_callback audio_state_cb;
btav_audio_config_callback audio_config_cb;
btav_connection_priority_callback connection_priority_cb;
btav_is_multicast_enabled_callback multicast_state_cb;
btav_audio_focus_request_callback audio_focus_request_cb;
} btav_callbacks_t;
/**
* NOTE:
*
* 1. AVRCP 1.0 shall be supported initially. AVRCP passthrough commands
* shall be handled internally via uinput
*
* 2. A2DP data path shall be handled via a socket pipe between the AudioFlinger
* android_audio_hw library and the Bluetooth stack.
*
*/
/** Represents the standard BT-AV interface.
* Used for both the A2DP source and sink interfaces.
*/
typedef struct {
/** set to sizeof(btav_interface_t) */
size_t size;
/**
* Register the BtAv callbacks
*/
bt_status_t (*init)( btav_callbacks_t* callbacks , int max_a2dp_connections,
int a2dp_multicast_state);
/** connect to headset */
bt_status_t (*connect)( bt_bdaddr_t *bd_addr );
/** dis-connect from headset */
bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr );
/** Closes the interface. */
void (*cleanup)( void );
/** Send priority of device to stack*/
void (*allow_connection)( int is_valid , bt_bdaddr_t *bd_addr);
/** Sends Audio Focus State. */
void (*audio_focus_state)( int focus_state );
} btav_interface_t;
__END_DECLS
#endif /* ANDROID_INCLUDE_BT_AV_H */
@@ -0,0 +1,44 @@
/*
* 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.
*/
/******************************************************************************
*
* This file contains constants and definitions that can be used commonly between JNI and stack layer
*
******************************************************************************/
#ifndef ANDROID_INCLUDE_BT_COMMON_TYPES_H
#define ANDROID_INCLUDE_BT_COMMON_TYPES_H
#include "bluetooth.h"
typedef struct
{
uint8_t client_if;
uint8_t filt_index;
uint8_t advertiser_state;
uint8_t advertiser_info_present;
uint8_t addr_type;
uint8_t tx_power;
int8_t rssi_value;
uint16_t time_stamp;
bt_bdaddr_t bd_addr;
uint8_t adv_pkt_len;
uint8_t *p_adv_pkt_data;
uint8_t scan_rsp_len;
uint8_t *p_scan_rsp_data;
} btgatt_track_adv_info_t;
#endif /* ANDROID_INCLUDE_BT_COMMON_TYPES_H */
@@ -0,0 +1,61 @@
/*
* Copyright (C) 2013 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_BT_GATT_H
#define ANDROID_INCLUDE_BT_GATT_H
#include <stdint.h>
#include "bt_gatt_client.h"
#include "bt_gatt_server.h"
__BEGIN_DECLS
/** BT-GATT callbacks */
typedef struct {
/** Set to sizeof(btgatt_callbacks_t) */
size_t size;
/** GATT Client callbacks */
const btgatt_client_callbacks_t* client;
/** GATT Server callbacks */
const btgatt_server_callbacks_t* server;
} btgatt_callbacks_t;
/** Represents the standard Bluetooth GATT interface. */
typedef struct {
/** Set to sizeof(btgatt_interface_t) */
size_t size;
/**
* Initializes the interface and provides callback routines
*/
bt_status_t (*init)( const btgatt_callbacks_t* callbacks );
/** Closes the interface */
void (*cleanup)( void );
/** Pointer to the GATT client interface methods.*/
const btgatt_client_interface_t* client;
/** Pointer to the GATT server interface methods.*/
const btgatt_server_interface_t* server;
} btgatt_interface_t;
__END_DECLS
#endif /* ANDROID_INCLUDE_BT_GATT_H */
@@ -0,0 +1,455 @@
/*
* Copyright (C) 2013 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_BT_GATT_CLIENT_H
#define ANDROID_INCLUDE_BT_GATT_CLIENT_H
#include <stdint.h>
#include "bt_gatt_types.h"
#include "bt_common_types.h"
__BEGIN_DECLS
/**
* Buffer sizes for maximum attribute length and maximum read/write
* operation buffer size.
*/
#define BTGATT_MAX_ATTR_LEN 600
/** Buffer type for unformatted reads/writes */
typedef struct
{
uint8_t value[BTGATT_MAX_ATTR_LEN];
uint16_t len;
} btgatt_unformatted_value_t;
/** Parameters for GATT read operations */
typedef struct
{
btgatt_srvc_id_t srvc_id;
btgatt_gatt_id_t char_id;
btgatt_gatt_id_t descr_id;
btgatt_unformatted_value_t value;
uint16_t value_type;
uint8_t status;
} btgatt_read_params_t;
/** Parameters for GATT write operations */
typedef struct
{
btgatt_srvc_id_t srvc_id;
btgatt_gatt_id_t char_id;
btgatt_gatt_id_t descr_id;
uint8_t status;
} btgatt_write_params_t;
/** Attribute change notification parameters */
typedef struct
{
uint8_t value[BTGATT_MAX_ATTR_LEN];
bt_bdaddr_t bda;
btgatt_srvc_id_t srvc_id;
btgatt_gatt_id_t char_id;
uint16_t len;
uint8_t is_notify;
} btgatt_notify_params_t;
typedef struct
{
uint8_t client_if;
uint8_t action;
uint8_t filt_index;
uint16_t feat_seln;
uint16_t list_logic_type;
uint8_t filt_logic_type;
uint8_t rssi_high_thres;
uint8_t rssi_low_thres;
uint8_t dely_mode;
uint16_t found_timeout;
uint16_t lost_timeout;
uint8_t found_timeout_cnt;
uint16_t num_of_tracking_entries;
} btgatt_filt_param_setup_t;
typedef struct
{
bt_bdaddr_t *bda1;
bt_uuid_t *uuid1;
uint16_t u1;
uint16_t u2;
uint16_t u3;
uint16_t u4;
uint16_t u5;
} btgatt_test_params_t;
/* BT GATT client error codes */
typedef enum
{
BT_GATTC_COMMAND_SUCCESS = 0, /* 0 Command succeeded */
BT_GATTC_COMMAND_STARTED, /* 1 Command started OK. */
BT_GATTC_COMMAND_BUSY, /* 2 Device busy with another command */
BT_GATTC_COMMAND_STORED, /* 3 request is stored in control block */
BT_GATTC_NO_RESOURCES, /* 4 No resources to issue command */
BT_GATTC_MODE_UNSUPPORTED, /* 5 Request for 1 or more unsupported modes */
BT_GATTC_ILLEGAL_VALUE, /* 6 Illegal command /parameter value */
BT_GATTC_INCORRECT_STATE, /* 7 Device in wrong state for request */
BT_GATTC_UNKNOWN_ADDR, /* 8 Unknown remote BD address */
BT_GATTC_DEVICE_TIMEOUT, /* 9 Device timeout */
BT_GATTC_INVALID_CONTROLLER_OUTPUT,/* 10 An incorrect value was received from HCI */
BT_GATTC_SECURITY_ERROR, /* 11 Authorization or security failure or not authorized */
BT_GATTC_DELAYED_ENCRYPTION_CHECK, /*12 Delayed encryption check */
BT_GATTC_ERR_PROCESSING /* 12 Generic error */
} btgattc_error_t;
/** BT-GATT Client callback structure. */
/** Callback invoked in response to register_client */
typedef void (*register_client_callback)(int status, int client_if,
bt_uuid_t *app_uuid);
/** Callback for scan results */
typedef void (*scan_result_callback)(bt_bdaddr_t* bda, int rssi, uint8_t* adv_data);
/** GATT open callback invoked in response to open */
typedef void (*connect_callback)(int conn_id, int status, int client_if, bt_bdaddr_t* bda);
/** Callback invoked in response to close */
typedef void (*disconnect_callback)(int conn_id, int status,
int client_if, bt_bdaddr_t* bda);
/**
* Invoked in response to search_service when the GATT service search
* has been completed.
*/
typedef void (*search_complete_callback)(int conn_id, int status);
/** Reports GATT services on a remote device */
typedef void (*search_result_callback)( int conn_id, btgatt_srvc_id_t *srvc_id);
/** GATT characteristic enumeration result callback */
typedef void (*get_characteristic_callback)(int conn_id, int status,
btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
int char_prop);
/** GATT descriptor enumeration result callback */
typedef void (*get_descriptor_callback)(int conn_id, int status,
btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
btgatt_gatt_id_t *descr_id);
/** GATT included service enumeration result callback */
typedef void (*get_included_service_callback)(int conn_id, int status,
btgatt_srvc_id_t *srvc_id, btgatt_srvc_id_t *incl_srvc_id);
/** Callback invoked in response to [de]register_for_notification */
typedef void (*register_for_notification_callback)(int conn_id,
int registered, int status, btgatt_srvc_id_t *srvc_id,
btgatt_gatt_id_t *char_id);
/**
* Remote device notification callback, invoked when a remote device sends
* a notification or indication that a client has registered for.
*/
typedef void (*notify_callback)(int conn_id, btgatt_notify_params_t *p_data);
/** Reports result of a GATT read operation */
typedef void (*read_characteristic_callback)(int conn_id, int status,
btgatt_read_params_t *p_data);
/** GATT write characteristic operation callback */
typedef void (*write_characteristic_callback)(int conn_id, int status,
btgatt_write_params_t *p_data);
/** GATT execute prepared write callback */
typedef void (*execute_write_callback)(int conn_id, int status);
/** Callback invoked in response to read_descriptor */
typedef void (*read_descriptor_callback)(int conn_id, int status,
btgatt_read_params_t *p_data);
/** Callback invoked in response to write_descriptor */
typedef void (*write_descriptor_callback)(int conn_id, int status,
btgatt_write_params_t *p_data);
/** Callback triggered in response to read_remote_rssi */
typedef void (*read_remote_rssi_callback)(int client_if, bt_bdaddr_t* bda,
int rssi, int status);
/**
* Callback indicating the status of a listen() operation
*/
typedef void (*listen_callback)(int status, int server_if);
/** Callback invoked when the MTU for a given connection changes */
typedef void (*configure_mtu_callback)(int conn_id, int status, int mtu);
/** Callback invoked when a scan filter configuration command has completed */
typedef void (*scan_filter_cfg_callback)(int action, int client_if, int status, int filt_type,
int avbl_space);
/** Callback invoked when scan param has been added, cleared, or deleted */
typedef void (*scan_filter_param_callback)(int action, int client_if, int status,
int avbl_space);
/** Callback invoked when a scan filter configuration command has completed */
typedef void (*scan_filter_status_callback)(int enable, int client_if, int status);
/** Callback invoked when multi-adv enable operation has completed */
typedef void (*multi_adv_enable_callback)(int client_if, int status);
/** Callback invoked when multi-adv param update operation has completed */
typedef void (*multi_adv_update_callback)(int client_if, int status);
/** Callback invoked when multi-adv instance data set operation has completed */
typedef void (*multi_adv_data_callback)(int client_if, int status);
/** Callback invoked when multi-adv disable operation has completed */
typedef void (*multi_adv_disable_callback)(int client_if, int status);
/**
* Callback notifying an application that a remote device connection is currently congested
* and cannot receive any more data. An application should avoid sending more data until
* a further callback is received indicating the congestion status has been cleared.
*/
typedef void (*congestion_callback)(int conn_id, bool congested);
/** Callback invoked when batchscan storage config operation has completed */
typedef void (*batchscan_cfg_storage_callback)(int client_if, int status);
/** Callback invoked when batchscan enable / disable operation has completed */
typedef void (*batchscan_enable_disable_callback)(int action, int client_if, int status);
/** Callback invoked when batchscan reports are obtained */
typedef void (*batchscan_reports_callback)(int client_if, int status, int report_format,
int num_records, int data_len, uint8_t* rep_data);
/** Callback invoked when batchscan storage threshold limit is crossed */
typedef void (*batchscan_threshold_callback)(int client_if);
/** Track ADV VSE callback invoked when tracked device is found or lost */
typedef void (*track_adv_event_callback)(btgatt_track_adv_info_t *p_track_adv_info);
/** Callback invoked when scan parameter setup has completed */
typedef void (*scan_parameter_setup_completed_callback)(int client_if,
btgattc_error_t status);
typedef struct {
register_client_callback register_client_cb;
scan_result_callback scan_result_cb;
connect_callback open_cb;
disconnect_callback close_cb;
search_complete_callback search_complete_cb;
search_result_callback search_result_cb;
get_characteristic_callback get_characteristic_cb;
get_descriptor_callback get_descriptor_cb;
get_included_service_callback get_included_service_cb;
register_for_notification_callback register_for_notification_cb;
notify_callback notify_cb;
read_characteristic_callback read_characteristic_cb;
write_characteristic_callback write_characteristic_cb;
read_descriptor_callback read_descriptor_cb;
write_descriptor_callback write_descriptor_cb;
execute_write_callback execute_write_cb;
read_remote_rssi_callback read_remote_rssi_cb;
listen_callback listen_cb;
configure_mtu_callback configure_mtu_cb;
scan_filter_cfg_callback scan_filter_cfg_cb;
scan_filter_param_callback scan_filter_param_cb;
scan_filter_status_callback scan_filter_status_cb;
multi_adv_enable_callback multi_adv_enable_cb;
multi_adv_update_callback multi_adv_update_cb;
multi_adv_data_callback multi_adv_data_cb;
multi_adv_disable_callback multi_adv_disable_cb;
congestion_callback congestion_cb;
batchscan_cfg_storage_callback batchscan_cfg_storage_cb;
batchscan_enable_disable_callback batchscan_enb_disable_cb;
batchscan_reports_callback batchscan_reports_cb;
batchscan_threshold_callback batchscan_threshold_cb;
track_adv_event_callback track_adv_event_cb;
scan_parameter_setup_completed_callback scan_parameter_setup_completed_cb;
} btgatt_client_callbacks_t;
/** Represents the standard BT-GATT client interface. */
typedef struct {
/** Registers a GATT client application with the stack */
bt_status_t (*register_client)( bt_uuid_t *uuid );
/** Unregister a client application from the stack */
bt_status_t (*unregister_client)(int client_if );
/** Start or stop LE device scanning */
bt_status_t (*scan)( bool start );
/** Create a connection to a remote LE or dual-mode device */
bt_status_t (*connect)( int client_if, const bt_bdaddr_t *bd_addr,
bool is_direct, int transport );
/** Disconnect a remote device or cancel a pending connection */
bt_status_t (*disconnect)( int client_if, const bt_bdaddr_t *bd_addr,
int conn_id);
/** Start or stop advertisements to listen for incoming connections */
bt_status_t (*listen)(int client_if, bool start);
/** Clear the attribute cache for a given device */
bt_status_t (*refresh)( int client_if, const bt_bdaddr_t *bd_addr );
/**
* Enumerate all GATT services on a connected device.
* Optionally, the results can be filtered for a given UUID.
*/
bt_status_t (*search_service)(int conn_id, bt_uuid_t *filter_uuid );
/**
* Enumerate included services for a given service.
* Set start_incl_srvc_id to NULL to get the first included service.
*/
bt_status_t (*get_included_service)( int conn_id, btgatt_srvc_id_t *srvc_id,
btgatt_srvc_id_t *start_incl_srvc_id);
/**
* Enumerate characteristics for a given service.
* Set start_char_id to NULL to get the first characteristic.
*/
bt_status_t (*get_characteristic)( int conn_id,
btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *start_char_id);
/**
* Enumerate descriptors for a given characteristic.
* Set start_descr_id to NULL to get the first descriptor.
*/
bt_status_t (*get_descriptor)( int conn_id,
btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
btgatt_gatt_id_t *start_descr_id);
/** Read a characteristic on a remote device */
bt_status_t (*read_characteristic)( int conn_id,
btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
int auth_req );
/** Write a remote characteristic */
bt_status_t (*write_characteristic)(int conn_id,
btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
int write_type, int len, int auth_req,
char* p_value);
/** Read the descriptor for a given characteristic */
bt_status_t (*read_descriptor)(int conn_id,
btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
btgatt_gatt_id_t *descr_id, int auth_req);
/** Write a remote descriptor for a given characteristic */
bt_status_t (*write_descriptor)( int conn_id,
btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
btgatt_gatt_id_t *descr_id, int write_type, int len,
int auth_req, char* p_value);
/** Execute a prepared write operation */
bt_status_t (*execute_write)(int conn_id, int execute);
/**
* Register to receive notifications or indications for a given
* characteristic
*/
bt_status_t (*register_for_notification)( int client_if,
const bt_bdaddr_t *bd_addr, btgatt_srvc_id_t *srvc_id,
btgatt_gatt_id_t *char_id);
/** Deregister a previous request for notifications/indications */
bt_status_t (*deregister_for_notification)( int client_if,
const bt_bdaddr_t *bd_addr, btgatt_srvc_id_t *srvc_id,
btgatt_gatt_id_t *char_id);
/** Request RSSI for a given remote device */
bt_status_t (*read_remote_rssi)( int client_if, const bt_bdaddr_t *bd_addr);
/** Setup scan filter params */
bt_status_t (*scan_filter_param_setup)(btgatt_filt_param_setup_t filt_param);
/** Configure a scan filter condition */
bt_status_t (*scan_filter_add_remove)(int client_if, int action, int filt_type,
int filt_index, int company_id,
int company_id_mask, const bt_uuid_t *p_uuid,
const bt_uuid_t *p_uuid_mask, const bt_bdaddr_t *bd_addr,
char addr_type, int data_len, char* p_data, int mask_len,
char* p_mask);
/** Clear all scan filter conditions for specific filter index*/
bt_status_t (*scan_filter_clear)(int client_if, int filt_index);
/** Enable / disable scan filter feature*/
bt_status_t (*scan_filter_enable)(int client_if, bool enable);
/** Determine the type of the remote device (LE, BR/EDR, Dual-mode) */
int (*get_device_type)( const bt_bdaddr_t *bd_addr );
/** Set the advertising data or scan response data */
bt_status_t (*set_adv_data)(int client_if, bool set_scan_rsp, bool include_name,
bool include_txpower, int min_interval, int max_interval, int appearance,
uint16_t manufacturer_len, char* manufacturer_data,
uint16_t service_data_len, char* service_data,
uint16_t service_uuid_len, char* service_uuid);
/** Configure the MTU for a given connection */
bt_status_t (*configure_mtu)(int conn_id, int mtu);
/** Request a connection parameter update */
bt_status_t (*conn_parameter_update)(const bt_bdaddr_t *bd_addr, int min_interval,
int max_interval, int latency, int timeout);
/** Sets the LE scan interval and window in units of N*0.625 msec */
bt_status_t (*set_scan_parameters)(int client_if, int scan_interval, int scan_window);
/* Setup the parameters as per spec, user manual specified values and enable multi ADV */
bt_status_t (*multi_adv_enable)(int client_if, int min_interval,int max_interval,int adv_type,
int chnl_map, int tx_power, int timeout_s);
/* Update the parameters as per spec, user manual specified values and restart multi ADV */
bt_status_t (*multi_adv_update)(int client_if, int min_interval,int max_interval,int adv_type,
int chnl_map, int tx_power, int timeout_s);
/* Setup the data for the specified instance */
bt_status_t (*multi_adv_set_inst_data)(int client_if, bool set_scan_rsp, bool include_name,
bool incl_txpower, int appearance, int manufacturer_len,
char* manufacturer_data, int service_data_len,
char* service_data, int service_uuid_len, char* service_uuid);
/* Disable the multi adv instance */
bt_status_t (*multi_adv_disable)(int client_if);
/* Configure the batchscan storage */
bt_status_t (*batchscan_cfg_storage)(int client_if, int batch_scan_full_max,
int batch_scan_trunc_max, int batch_scan_notify_threshold);
/* Enable batchscan */
bt_status_t (*batchscan_enb_batch_scan)(int client_if, int scan_mode,
int scan_interval, int scan_window, int addr_type, int discard_rule);
/* Disable batchscan */
bt_status_t (*batchscan_dis_batch_scan)(int client_if);
/* Read out batchscan reports */
bt_status_t (*batchscan_read_reports)(int client_if, int scan_mode);
/** Test mode interface */
bt_status_t (*test_command)( int command, btgatt_test_params_t* params);
} btgatt_client_interface_t;
__END_DECLS
#endif /* ANDROID_INCLUDE_BT_GATT_CLIENT_H */
@@ -0,0 +1,196 @@
/*
* Copyright (C) 2013 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_BT_GATT_SERVER_H
#define ANDROID_INCLUDE_BT_GATT_SERVER_H
#include <stdint.h>
#include "bt_gatt_types.h"
__BEGIN_DECLS
/** GATT value type used in response to remote read requests */
typedef struct
{
uint8_t value[BTGATT_MAX_ATTR_LEN];
uint16_t handle;
uint16_t offset;
uint16_t len;
uint8_t auth_req;
} btgatt_value_t;
/** GATT remote read request response type */
typedef union
{
btgatt_value_t attr_value;
uint16_t handle;
} btgatt_response_t;
/** BT-GATT Server callback structure. */
/** Callback invoked in response to register_server */
typedef void (*register_server_callback)(int status, int server_if,
bt_uuid_t *app_uuid);
/** Callback indicating that a remote device has connected or been disconnected */
typedef void (*connection_callback)(int conn_id, int server_if, int connected,
bt_bdaddr_t *bda);
/** Callback invoked in response to create_service */
typedef void (*service_added_callback)(int status, int server_if,
btgatt_srvc_id_t *srvc_id, int srvc_handle);
/** Callback indicating that an included service has been added to a service */
typedef void (*included_service_added_callback)(int status, int server_if,
int srvc_handle, int incl_srvc_handle);
/** Callback invoked when a characteristic has been added to a service */
typedef void (*characteristic_added_callback)(int status, int server_if,
bt_uuid_t *uuid, int srvc_handle, int char_handle);
/** Callback invoked when a descriptor has been added to a characteristic */
typedef void (*descriptor_added_callback)(int status, int server_if,
bt_uuid_t *uuid, int srvc_handle, int descr_handle);
/** Callback invoked in response to start_service */
typedef void (*service_started_callback)(int status, int server_if,
int srvc_handle);
/** Callback invoked in response to stop_service */
typedef void (*service_stopped_callback)(int status, int server_if,
int srvc_handle);
/** Callback triggered when a service has been deleted */
typedef void (*service_deleted_callback)(int status, int server_if,
int srvc_handle);
/**
* Callback invoked when a remote device has requested to read a characteristic
* or descriptor. The application must respond by calling send_response
*/
typedef void (*request_read_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda,
int attr_handle, int offset, bool is_long);
/**
* Callback invoked when a remote device has requested to write to a
* characteristic or descriptor.
*/
typedef void (*request_write_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda,
int attr_handle, int offset, int length,
bool need_rsp, bool is_prep, uint8_t* value);
/** Callback invoked when a previously prepared write is to be executed */
typedef void (*request_exec_write_callback)(int conn_id, int trans_id,
bt_bdaddr_t *bda, int exec_write);
/**
* Callback triggered in response to send_response if the remote device
* sends a confirmation.
*/
typedef void (*response_confirmation_callback)(int status, int handle);
/**
* Callback confirming that a notification or indication has been sent
* to a remote device.
*/
typedef void (*indication_sent_callback)(int conn_id, int status);
/**
* Callback notifying an application that a remote device connection is currently congested
* and cannot receive any more data. An application should avoid sending more data until
* a further callback is received indicating the congestion status has been cleared.
*/
typedef void (*congestion_callback)(int conn_id, bool congested);
/** Callback invoked when the MTU for a given connection changes */
typedef void (*mtu_changed_callback)(int conn_id, int mtu);
typedef struct {
register_server_callback register_server_cb;
connection_callback connection_cb;
service_added_callback service_added_cb;
included_service_added_callback included_service_added_cb;
characteristic_added_callback characteristic_added_cb;
descriptor_added_callback descriptor_added_cb;
service_started_callback service_started_cb;
service_stopped_callback service_stopped_cb;
service_deleted_callback service_deleted_cb;
request_read_callback request_read_cb;
request_write_callback request_write_cb;
request_exec_write_callback request_exec_write_cb;
response_confirmation_callback response_confirmation_cb;
indication_sent_callback indication_sent_cb;
congestion_callback congestion_cb;
mtu_changed_callback mtu_changed_cb;
} btgatt_server_callbacks_t;
/** Represents the standard BT-GATT server interface. */
typedef struct {
/** Registers a GATT server application with the stack */
bt_status_t (*register_server)( bt_uuid_t *uuid );
/** Unregister a server application from the stack */
bt_status_t (*unregister_server)(int server_if );
/** Create a connection to a remote peripheral */
bt_status_t (*connect)(int server_if, const bt_bdaddr_t *bd_addr,
bool is_direct, int transport);
/** Disconnect an established connection or cancel a pending one */
bt_status_t (*disconnect)(int server_if, const bt_bdaddr_t *bd_addr,
int conn_id );
/** Create a new service */
bt_status_t (*add_service)( int server_if, btgatt_srvc_id_t *srvc_id, int num_handles);
/** Assign an included service to it's parent service */
bt_status_t (*add_included_service)( int server_if, int service_handle, int included_handle);
/** Add a characteristic to a service */
bt_status_t (*add_characteristic)( int server_if,
int service_handle, bt_uuid_t *uuid,
int properties, int permissions);
/** Add a descriptor to a given service */
bt_status_t (*add_descriptor)(int server_if, int service_handle,
bt_uuid_t *uuid, int permissions);
/** Starts a local service */
bt_status_t (*start_service)(int server_if, int service_handle,
int transport);
/** Stops a local service */
bt_status_t (*stop_service)(int server_if, int service_handle);
/** Delete a local service */
bt_status_t (*delete_service)(int server_if, int service_handle);
/** Send value indication to a remote device */
bt_status_t (*send_indication)(int server_if, int attribute_handle,
int conn_id, int len, int confirm,
char* p_value);
/** Send a response to a read/write operation */
bt_status_t (*send_response)(int conn_id, int trans_id,
int status, btgatt_response_t *response);
} btgatt_server_interface_t;
__END_DECLS
#endif /* ANDROID_INCLUDE_BT_GATT_CLIENT_H */
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2013 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_BT_GATT_TYPES_H
#define ANDROID_INCLUDE_BT_GATT_TYPES_H
#include <stdint.h>
#include <stdbool.h>
__BEGIN_DECLS
/**
* GATT Service types
*/
#define BTGATT_SERVICE_TYPE_PRIMARY 0
#define BTGATT_SERVICE_TYPE_SECONDARY 1
/** GATT ID adding instance id tracking to the UUID */
typedef struct
{
bt_uuid_t uuid;
uint8_t inst_id;
} btgatt_gatt_id_t;
/** GATT Service ID also identifies the service type (primary/secondary) */
typedef struct
{
btgatt_gatt_id_t id;
uint8_t is_primary;
} btgatt_srvc_id_t;
/** Preferred physical Transport for GATT connection */
typedef enum
{
GATT_TRANSPORT_AUTO,
GATT_TRANSPORT_BREDR,
GATT_TRANSPORT_LE
} btgatt_transport_t;
__END_DECLS
#endif /* ANDROID_INCLUDE_BT_GATT_TYPES_H */
@@ -0,0 +1,129 @@
/*
* Copyright (c) 2013, The Linux Foundation. All rights reserved.
* Not a Contribution
* Copyright (C) 2012 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_BT_HD_H
#define ANDROID_INCLUDE_BT_HD_H
#include <stdint.h>
__BEGIN_DECLS
typedef enum
{
BTHD_REPORT_TYPE_OTHER = 0,
BTHD_REPORT_TYPE_INPUT,
BTHD_REPORT_TYPE_OUTPUT,
BTHD_REPORT_TYPE_FEATURE,
BTHD_REPORT_TYPE_INTRDATA // special value for reports to be sent on INTR (INPUT is assumed)
} bthd_report_type_t;
typedef enum
{
BTHD_APP_STATE_NOT_REGISTERED,
BTHD_APP_STATE_REGISTERED
} bthd_application_state_t;
typedef enum
{
BTHD_CONN_STATE_CONNECTED,
BTHD_CONN_STATE_CONNECTING,
BTHD_CONN_STATE_DISCONNECTED,
BTHD_CONN_STATE_DISCONNECTING,
BTHD_CONN_STATE_UNKNOWN
} bthd_connection_state_t;
typedef struct
{
const char *name;
const char *description;
const char *provider;
uint8_t subclass;
uint8_t *desc_list;
int desc_list_len;
} bthd_app_param_t;
typedef struct
{
uint8_t service_type;
uint32_t token_rate;
uint32_t token_bucket_size;
uint32_t peak_bandwidth;
uint32_t access_latency;
uint32_t delay_variation;
} bthd_qos_param_t;
typedef void (* bthd_application_state_callback)(bt_bdaddr_t *bd_addr, bthd_application_state_t state);
typedef void (* bthd_connection_state_callback)(bt_bdaddr_t *bd_addr, bthd_connection_state_t state);
typedef void (* bthd_get_report_callback)(uint8_t type, uint8_t id, uint16_t buffer_size);
typedef void (* bthd_set_report_callback)(uint8_t type, uint8_t id, uint16_t len, uint8_t *p_data);
typedef void (* bthd_set_protocol_callback)(uint8_t protocol);
typedef void (* bthd_intr_data_callback)(uint8_t report_id, uint16_t len, uint8_t *p_data);
typedef void (* bthd_vc_unplug_callback)(void);
/** BT-HD callbacks */
typedef struct {
size_t size;
bthd_application_state_callback application_state_cb;
bthd_connection_state_callback connection_state_cb;
bthd_get_report_callback get_report_cb;
bthd_set_report_callback set_report_cb;
bthd_set_protocol_callback set_protocol_cb;
bthd_intr_data_callback intr_data_cb;
bthd_vc_unplug_callback vc_unplug_cb;
} bthd_callbacks_t;
/** BT-HD interface */
typedef struct {
size_t size;
/** init interface and register callbacks */
bt_status_t (*init)(bthd_callbacks_t* callbacks);
/** close interface */
void (*cleanup)(void);
/** register application */
bt_status_t (*register_app)(bthd_app_param_t *app_param, bthd_qos_param_t *in_qos,
bthd_qos_param_t *out_qos);
/** unregister application */
bt_status_t (*unregister_app)(void);
/** connects to host with virtual cable */
bt_status_t (*connect)(void);
/** disconnects from currently connected host */
bt_status_t (*disconnect)(void);
/** send report */
bt_status_t (*send_report)(bthd_report_type_t type, uint8_t id, uint16_t len, uint8_t *p_data);
/** notifies error for invalid SET_REPORT */
bt_status_t (*report_error)(uint8_t error);
/** send Virtual Cable Unplug */
bt_status_t (*virtual_cable_unplug)(void);
} bthd_interface_t;
__END_DECLS
#endif /* ANDROID_INCLUDE_BT_HD_H */
@@ -0,0 +1,348 @@
/*
* Copyright (C) 2012 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_BT_HF_H
#define ANDROID_INCLUDE_BT_HF_H
__BEGIN_DECLS
/* AT response code - OK/Error */
typedef enum {
BTHF_AT_RESPONSE_ERROR = 0,
BTHF_AT_RESPONSE_OK
} bthf_at_response_t;
typedef enum {
BTHF_CONNECTION_STATE_DISCONNECTED = 0,
BTHF_CONNECTION_STATE_CONNECTING,
BTHF_CONNECTION_STATE_CONNECTED,
BTHF_CONNECTION_STATE_SLC_CONNECTED,
BTHF_CONNECTION_STATE_DISCONNECTING
} bthf_connection_state_t;
typedef enum {
BTHF_AUDIO_STATE_DISCONNECTED = 0,
BTHF_AUDIO_STATE_CONNECTING,
BTHF_AUDIO_STATE_CONNECTED,
BTHF_AUDIO_STATE_DISCONNECTING
} bthf_audio_state_t;
typedef enum {
BTHF_VR_STATE_STOPPED = 0,
BTHF_VR_STATE_STARTED
} bthf_vr_state_t;
typedef enum {
BTHF_VOLUME_TYPE_SPK = 0,
BTHF_VOLUME_TYPE_MIC
} bthf_volume_type_t;
/* Noise Reduction and Echo Cancellation */
typedef enum
{
BTHF_NREC_STOP,
BTHF_NREC_START
} bthf_nrec_t;
/* WBS codec setting */
typedef enum
{
BTHF_WBS_NONE,
BTHF_WBS_NO,
BTHF_WBS_YES
}bthf_wbs_config_t;
/* BIND type*/
typedef enum
{
BTHF_BIND_SET,
BTHF_BIND_READ,
BTHF_BIND_TEST
}bthf_bind_type_t;
/* CHLD - Call held handling */
typedef enum
{
BTHF_CHLD_TYPE_RELEASEHELD, // Terminate all held or set UDUB("busy") to a waiting call
BTHF_CHLD_TYPE_RELEASEACTIVE_ACCEPTHELD, // Terminate all active calls and accepts a waiting/held call
BTHF_CHLD_TYPE_HOLDACTIVE_ACCEPTHELD, // Hold all active calls and accepts a waiting/held call
BTHF_CHLD_TYPE_ADDHELDTOCONF, // Add all held calls to a conference
} bthf_chld_type_t;
/** Callback for connection state change.
* state will have one of the values from BtHfConnectionState
*/
typedef void (* bthf_connection_state_callback)(bthf_connection_state_t state, bt_bdaddr_t *bd_addr);
/** Callback for audio connection state change.
* state will have one of the values from BtHfAudioState
*/
typedef void (* bthf_audio_state_callback)(bthf_audio_state_t state, bt_bdaddr_t *bd_addr);
/** Callback for VR connection state change.
* state will have one of the values from BtHfVRState
*/
typedef void (* bthf_vr_cmd_callback)(bthf_vr_state_t state, bt_bdaddr_t *bd_addr);
/** Callback for answer incoming call (ATA)
*/
typedef void (* bthf_answer_call_cmd_callback)(bt_bdaddr_t *bd_addr);
/** Callback for disconnect call (AT+CHUP)
*/
typedef void (* bthf_hangup_call_cmd_callback)(bt_bdaddr_t *bd_addr);
/** Callback for disconnect call (AT+CHUP)
* type will denote Speaker/Mic gain (BtHfVolumeControl).
*/
typedef void (* bthf_volume_cmd_callback)(bthf_volume_type_t type, int volume, bt_bdaddr_t *bd_addr);
/** Callback for dialing an outgoing call
* If number is NULL, redial
*/
typedef void (* bthf_dial_call_cmd_callback)(char *number, bt_bdaddr_t *bd_addr);
/** Callback for sending DTMF tones
* tone contains the dtmf character to be sent
*/
typedef void (* bthf_dtmf_cmd_callback)(char tone, bt_bdaddr_t *bd_addr);
/** Callback for enabling/disabling noise reduction/echo cancellation
* value will be 1 to enable, 0 to disable
*/
typedef void (* bthf_nrec_cmd_callback)(bthf_nrec_t nrec, bt_bdaddr_t *bd_addr);
/** Callback for AT+BCS and event from BAC
* WBS enable, WBS disable
*/
typedef void (* bthf_wbs_callback)(bthf_wbs_config_t wbs, bt_bdaddr_t *bd_addr);
/** Callback for call hold handling (AT+CHLD)
* value will contain the call hold command (0, 1, 2, 3)
*/
typedef void (* bthf_chld_cmd_callback)(bthf_chld_type_t chld, bt_bdaddr_t *bd_addr);
/** Callback for CNUM (subscriber number)
*/
typedef void (* bthf_cnum_cmd_callback)(bt_bdaddr_t *bd_addr);
/** Callback for indicators (CIND)
*/
typedef void (* bthf_cind_cmd_callback)(bt_bdaddr_t *bd_addr);
/** Callback for operator selection (COPS)
*/
typedef void (* bthf_cops_cmd_callback)(bt_bdaddr_t *bd_addr);
/** Callback for call list (AT+CLCC)
*/
typedef void (* bthf_clcc_cmd_callback) (bt_bdaddr_t *bd_addr);
/** Callback for unknown AT command recd from HF
* at_string will contain the unparsed AT string
*/
typedef void (* bthf_unknown_at_cmd_callback)(char *at_string, bt_bdaddr_t *bd_addr);
/** Callback for keypressed (HSP) event.
*/
typedef void (* bthf_key_pressed_cmd_callback)(bt_bdaddr_t *bd_addr);
/** Callback for HF indicators (BIND)
*/
typedef void (* bthf_bind_cmd_callback)(char* hf_ind, bthf_bind_type_t type, bt_bdaddr_t *bd_addr);
/** Callback for HF indicator value (BIEV)
*/
typedef void (* bthf_biev_cmd_callback)(char* hf_ind_val, bt_bdaddr_t *bd_addr);
/** BT-HF callback structure. */
typedef struct {
/** set to sizeof(BtHfCallbacks) */
size_t size;
bthf_connection_state_callback connection_state_cb;
bthf_audio_state_callback audio_state_cb;
bthf_vr_cmd_callback vr_cmd_cb;
bthf_answer_call_cmd_callback answer_call_cmd_cb;
bthf_hangup_call_cmd_callback hangup_call_cmd_cb;
bthf_volume_cmd_callback volume_cmd_cb;
bthf_dial_call_cmd_callback dial_call_cmd_cb;
bthf_dtmf_cmd_callback dtmf_cmd_cb;
bthf_nrec_cmd_callback nrec_cmd_cb;
bthf_wbs_callback wbs_cb;
bthf_chld_cmd_callback chld_cmd_cb;
bthf_cnum_cmd_callback cnum_cmd_cb;
bthf_cind_cmd_callback cind_cmd_cb;
bthf_cops_cmd_callback cops_cmd_cb;
bthf_clcc_cmd_callback clcc_cmd_cb;
bthf_unknown_at_cmd_callback unknown_at_cmd_cb;
bthf_key_pressed_cmd_callback key_pressed_cmd_cb;
bthf_bind_cmd_callback bind_cmd_cb;
bthf_biev_cmd_callback biev_cmd_cb;
} bthf_callbacks_t;
/** Network Status */
typedef enum
{
BTHF_NETWORK_STATE_NOT_AVAILABLE = 0,
BTHF_NETWORK_STATE_AVAILABLE
} bthf_network_state_t;
/** Service type */
typedef enum
{
BTHF_SERVICE_TYPE_HOME = 0,
BTHF_SERVICE_TYPE_ROAMING
} bthf_service_type_t;
typedef enum {
BTHF_CALL_STATE_ACTIVE = 0,
BTHF_CALL_STATE_HELD,
BTHF_CALL_STATE_DIALING,
BTHF_CALL_STATE_ALERTING,
BTHF_CALL_STATE_INCOMING,
BTHF_CALL_STATE_WAITING,
BTHF_CALL_STATE_IDLE
} bthf_call_state_t;
typedef enum {
BTHF_CALL_DIRECTION_OUTGOING = 0,
BTHF_CALL_DIRECTION_INCOMING
} bthf_call_direction_t;
typedef enum {
BTHF_CALL_TYPE_VOICE = 0,
BTHF_CALL_TYPE_DATA,
BTHF_CALL_TYPE_FAX
} bthf_call_mode_t;
typedef enum {
BTHF_CALL_MPTY_TYPE_SINGLE = 0,
BTHF_CALL_MPTY_TYPE_MULTI
} bthf_call_mpty_type_t;
typedef enum {
BTHF_HF_INDICATOR_STATE_DISABLED = 0,
BTHF_HF_INDICATOR_STATE_ENABLED
} bthf_hf_indicator_status_t;
typedef enum {
BTHF_CALL_ADDRTYPE_UNKNOWN = 0x81,
BTHF_CALL_ADDRTYPE_INTERNATIONAL = 0x91
} bthf_call_addrtype_t;
typedef enum {
BTHF_VOIP_CALL_NETWORK_TYPE_MOBILE = 0,
BTHF_VOIP_CALL_NETWORK_TYPE_WIFI
} bthf_voip_call_network_type_t;
typedef enum {
BTHF_VOIP_STATE_STOPPED = 0,
BTHF_VOIP_STATE_STARTED
} bthf_voip_state_t;
/** Represents the standard BT-HF interface. */
typedef struct {
/** set to sizeof(BtHfInterface) */
size_t size;
/**
* Register the BtHf callbacks
*/
bt_status_t (*init)( bthf_callbacks_t* callbacks, int max_hf_clients);
/** connect to headset */
bt_status_t (*connect)( bt_bdaddr_t *bd_addr );
/** dis-connect from headset */
bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr );
/** create an audio connection */
bt_status_t (*connect_audio)( bt_bdaddr_t *bd_addr );
/** close the audio connection */
bt_status_t (*disconnect_audio)( bt_bdaddr_t *bd_addr );
/** start voice recognition */
bt_status_t (*start_voice_recognition)( bt_bdaddr_t *bd_addr );
/** stop voice recognition */
bt_status_t (*stop_voice_recognition)( bt_bdaddr_t *bd_addr );
/** volume control */
bt_status_t (*volume_control) (bthf_volume_type_t type, int volume, bt_bdaddr_t *bd_addr );
/** Combined device status change notification */
bt_status_t (*device_status_notification)(bthf_network_state_t ntk_state, bthf_service_type_t svc_type, int signal,
int batt_chg);
/** Response for COPS command */
bt_status_t (*cops_response)(const char *cops, bt_bdaddr_t *bd_addr );
/** Response for CIND command */
bt_status_t (*cind_response)(int svc, int num_active, int num_held, bthf_call_state_t call_setup_state,
int signal, int roam, int batt_chg, bt_bdaddr_t *bd_addr );
/** Pre-formatted AT response, typically in response to unknown AT cmd */
bt_status_t (*formatted_at_response)(const char *rsp, bt_bdaddr_t *bd_addr );
/** ok/error response
* ERROR (0)
* OK (1)
*/
bt_status_t (*at_response) (bthf_at_response_t response_code, int error_code, bt_bdaddr_t *bd_addr );
/** response for CLCC command
* Can be iteratively called for each call index
* Call index of 0 will be treated as NULL termination (Completes response)
*/
bt_status_t (*clcc_response) (int index, bthf_call_direction_t dir,
bthf_call_state_t state, bthf_call_mode_t mode,
bthf_call_mpty_type_t mpty, const char *number,
bthf_call_addrtype_t type, bt_bdaddr_t *bd_addr );
/** notify of a call state change
* Each update notifies
* 1. Number of active/held/ringing calls
* 2. call_state: This denotes the state change that triggered this msg
* This will take one of the values from BtHfCallState
* 3. number & type: valid only for incoming & waiting call
*/
bt_status_t (*phone_state_change) (int num_active, int num_held, bthf_call_state_t call_setup_state,
const char *number, bthf_call_addrtype_t type);
/** Closes the interface. */
void (*cleanup)( void );
/** configureation for the SCO codec */
bt_status_t (*configure_wbs)( bt_bdaddr_t *bd_addr ,bthf_wbs_config_t config );
/** Response for BIND READ command and activation/deactivation of HF indicator */
bt_status_t (*bind_response) (int anum, bthf_hf_indicator_status_t status,
bt_bdaddr_t *bd_addr);
/** Response for BIND TEST command */
bt_status_t (*bind_string_response) (const char* result, bt_bdaddr_t *bd_addr);
/** Sends connectivity network type used by Voip currently to stack */
bt_status_t (*voip_network_type_wifi) (bthf_voip_state_t is_voip_started,
bthf_voip_call_network_type_t is_network_wifi);
} bthf_interface_t;
__END_DECLS
#endif /* ANDROID_INCLUDE_BT_HF_H */
@@ -0,0 +1,375 @@
/*
* Copyright (C) 2012-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_INCLUDE_BT_HF_CLIENT_H
#define ANDROID_INCLUDE_BT_HF_CLIENT_H
__BEGIN_DECLS
typedef enum {
BTHF_CLIENT_CONNECTION_STATE_DISCONNECTED = 0,
BTHF_CLIENT_CONNECTION_STATE_CONNECTING,
BTHF_CLIENT_CONNECTION_STATE_CONNECTED,
BTHF_CLIENT_CONNECTION_STATE_SLC_CONNECTED,
BTHF_CLIENT_CONNECTION_STATE_DISCONNECTING
} bthf_client_connection_state_t;
typedef enum {
BTHF_CLIENT_AUDIO_STATE_DISCONNECTED = 0,
BTHF_CLIENT_AUDIO_STATE_CONNECTING,
BTHF_CLIENT_AUDIO_STATE_CONNECTED,
BTHF_CLIENT_AUDIO_STATE_CONNECTED_MSBC,
} bthf_client_audio_state_t;
typedef enum {
BTHF_CLIENT_VR_STATE_STOPPED = 0,
BTHF_CLIENT_VR_STATE_STARTED
} bthf_client_vr_state_t;
typedef enum {
BTHF_CLIENT_VOLUME_TYPE_SPK = 0,
BTHF_CLIENT_VOLUME_TYPE_MIC
} bthf_client_volume_type_t;
typedef enum
{
BTHF_CLIENT_NETWORK_STATE_NOT_AVAILABLE = 0,
BTHF_CLIENT_NETWORK_STATE_AVAILABLE
} bthf_client_network_state_t;
typedef enum
{
BTHF_CLIENT_SERVICE_TYPE_HOME = 0,
BTHF_CLIENT_SERVICE_TYPE_ROAMING
} bthf_client_service_type_t;
typedef enum {
BTHF_CLIENT_CALL_STATE_ACTIVE = 0,
BTHF_CLIENT_CALL_STATE_HELD,
BTHF_CLIENT_CALL_STATE_DIALING,
BTHF_CLIENT_CALL_STATE_ALERTING,
BTHF_CLIENT_CALL_STATE_INCOMING,
BTHF_CLIENT_CALL_STATE_WAITING,
BTHF_CLIENT_CALL_STATE_HELD_BY_RESP_HOLD,
} bthf_client_call_state_t;
typedef enum {
BTHF_CLIENT_CALL_NO_CALLS_IN_PROGRESS = 0,
BTHF_CLIENT_CALL_CALLS_IN_PROGRESS
} bthf_client_call_t;
typedef enum {
BTHF_CLIENT_CALLSETUP_NONE = 0,
BTHF_CLIENT_CALLSETUP_INCOMING,
BTHF_CLIENT_CALLSETUP_OUTGOING,
BTHF_CLIENT_CALLSETUP_ALERTING
} bthf_client_callsetup_t;
typedef enum {
BTHF_CLIENT_CALLHELD_NONE = 0,
BTHF_CLIENT_CALLHELD_HOLD_AND_ACTIVE,
BTHF_CLIENT_CALLHELD_HOLD,
} bthf_client_callheld_t;
typedef enum {
BTHF_CLIENT_RESP_AND_HOLD_HELD = 0,
BTRH_CLIENT_RESP_AND_HOLD_ACCEPT,
BTRH_CLIENT_RESP_AND_HOLD_REJECT,
} bthf_client_resp_and_hold_t;
typedef enum {
BTHF_CLIENT_CALL_DIRECTION_OUTGOING = 0,
BTHF_CLIENT_CALL_DIRECTION_INCOMING
} bthf_client_call_direction_t;
typedef enum {
BTHF_CLIENT_CALL_MPTY_TYPE_SINGLE = 0,
BTHF_CLIENT_CALL_MPTY_TYPE_MULTI
} bthf_client_call_mpty_type_t;
typedef enum {
BTHF_CLIENT_CMD_COMPLETE_OK = 0,
BTHF_CLIENT_CMD_COMPLETE_ERROR,
BTHF_CLIENT_CMD_COMPLETE_ERROR_NO_CARRIER,
BTHF_CLIENT_CMD_COMPLETE_ERROR_BUSY,
BTHF_CLIENT_CMD_COMPLETE_ERROR_NO_ANSWER,
BTHF_CLIENT_CMD_COMPLETE_ERROR_DELAYED,
BTHF_CLIENT_CMD_COMPLETE_ERROR_BLACKLISTED,
BTHF_CLIENT_CMD_COMPLETE_ERROR_CME
} bthf_client_cmd_complete_t;
typedef enum {
BTHF_CLIENT_CALL_ACTION_CHLD_0 = 0,
BTHF_CLIENT_CALL_ACTION_CHLD_1,
BTHF_CLIENT_CALL_ACTION_CHLD_2,
BTHF_CLIENT_CALL_ACTION_CHLD_3,
BTHF_CLIENT_CALL_ACTION_CHLD_4,
BTHF_CLIENT_CALL_ACTION_CHLD_1x,
BTHF_CLIENT_CALL_ACTION_CHLD_2x,
BTHF_CLIENT_CALL_ACTION_ATA,
BTHF_CLIENT_CALL_ACTION_CHUP,
BTHF_CLIENT_CALL_ACTION_BTRH_0,
BTHF_CLIENT_CALL_ACTION_BTRH_1,
BTHF_CLIENT_CALL_ACTION_BTRH_2,
} bthf_client_call_action_t;
typedef enum {
BTHF_CLIENT_SERVICE_UNKNOWN = 0,
BTHF_CLIENT_SERVICE_VOICE,
BTHF_CLIENT_SERVICE_FAX
} bthf_client_subscriber_service_type_t;
typedef enum {
BTHF_CLIENT_IN_BAND_RINGTONE_NOT_PROVIDED = 0,
BTHF_CLIENT_IN_BAND_RINGTONE_PROVIDED,
} bthf_client_in_band_ring_state_t;
/* Peer features masks */
#define BTHF_CLIENT_PEER_FEAT_3WAY 0x00000001 /* Three-way calling */
#define BTHF_CLIENT_PEER_FEAT_ECNR 0x00000002 /* Echo cancellation and/or noise reduction */
#define BTHF_CLIENT_PEER_FEAT_VREC 0x00000004 /* Voice recognition */
#define BTHF_CLIENT_PEER_FEAT_INBAND 0x00000008 /* In-band ring tone */
#define BTHF_CLIENT_PEER_FEAT_VTAG 0x00000010 /* Attach a phone number to a voice tag */
#define BTHF_CLIENT_PEER_FEAT_REJECT 0x00000020 /* Ability to reject incoming call */
#define BTHF_CLIENT_PEER_FEAT_ECS 0x00000040 /* Enhanced Call Status */
#define BTHF_CLIENT_PEER_FEAT_ECC 0x00000080 /* Enhanced Call Control */
#define BTHF_CLIENT_PEER_FEAT_EXTERR 0x00000100 /* Extended error codes */
#define BTHF_CLIENT_PEER_FEAT_CODEC 0x00000200 /* Codec Negotiation */
/* Peer call handling features masks */
#define BTHF_CLIENT_CHLD_FEAT_REL 0x00000001 /* 0 Release waiting call or held calls */
#define BTHF_CLIENT_CHLD_FEAT_REL_ACC 0x00000002 /* 1 Release active calls and accept other
(waiting or held) cal */
#define BTHF_CLIENT_CHLD_FEAT_REL_X 0x00000004 /* 1x Release specified active call only */
#define BTHF_CLIENT_CHLD_FEAT_HOLD_ACC 0x00000008 /* 2 Active calls on hold and accept other
(waiting or held) call */
#define BTHF_CLIENT_CHLD_FEAT_PRIV_X 0x00000010 /* 2x Request private mode with specified
call (put the rest on hold) */
#define BTHF_CLIENT_CHLD_FEAT_MERGE 0x00000020 /* 3 Add held call to multiparty */
#define BTHF_CLIENT_CHLD_FEAT_MERGE_DETACH 0x00000040 /* 4 Connect two calls and leave
(disconnect from) multiparty */
/** Callback for connection state change.
* state will have one of the values from BtHfConnectionState
* peer/chld_features are valid only for BTHF_CLIENT_CONNECTION_STATE_SLC_CONNECTED state
*/
typedef void (* bthf_client_connection_state_callback)(bthf_client_connection_state_t state,
unsigned int peer_feat,
unsigned int chld_feat,
bt_bdaddr_t *bd_addr);
/** Callback for audio connection state change.
* state will have one of the values from BtHfAudioState
*/
typedef void (* bthf_client_audio_state_callback)(bthf_client_audio_state_t state,
bt_bdaddr_t *bd_addr);
/** Callback for VR connection state change.
* state will have one of the values from BtHfVRState
*/
typedef void (* bthf_client_vr_cmd_callback)(bthf_client_vr_state_t state);
/** Callback for network state change
*/
typedef void (* bthf_client_network_state_callback) (bthf_client_network_state_t state);
/** Callback for network roaming status change
*/
typedef void (* bthf_client_network_roaming_callback) (bthf_client_service_type_t type);
/** Callback for signal strength indication
*/
typedef void (* bthf_client_network_signal_callback) (int signal_strength);
/** Callback for battery level indication
*/
typedef void (* bthf_client_battery_level_callback) (int battery_level);
/** Callback for current operator name
*/
typedef void (* bthf_client_current_operator_callback) (const char *name);
/** Callback for call indicator
*/
typedef void (* bthf_client_call_callback) (bthf_client_call_t call);
/** Callback for callsetup indicator
*/
typedef void (* bthf_client_callsetup_callback) (bthf_client_callsetup_t callsetup);
/** Callback for callheld indicator
*/
typedef void (* bthf_client_callheld_callback) (bthf_client_callheld_t callheld);
/** Callback for response and hold
*/
typedef void (* bthf_client_resp_and_hold_callback) (bthf_client_resp_and_hold_t resp_and_hold);
/** Callback for Calling Line Identification notification
* Will be called only when there is an incoming call and number is provided.
*/
typedef void (* bthf_client_clip_callback) (const char *number);
/**
* Callback for Call Waiting notification
*/
typedef void (* bthf_client_call_waiting_callback) (const char *number);
/**
* Callback for listing current calls. Can be called multiple time.
* If number is unknown NULL is passed.
*/
typedef void (*bthf_client_current_calls) (int index, bthf_client_call_direction_t dir,
bthf_client_call_state_t state,
bthf_client_call_mpty_type_t mpty,
const char *number);
/** Callback for audio volume change
*/
typedef void (*bthf_client_volume_change_callback) (bthf_client_volume_type_t type, int volume);
/** Callback for command complete event
* cme is valid only for BTHF_CLIENT_CMD_COMPLETE_ERROR_CME type
*/
typedef void (*bthf_client_cmd_complete_callback) (bthf_client_cmd_complete_t type, int cme);
/** Callback for subscriber information
*/
typedef void (* bthf_client_subscriber_info_callback) (const char *name,
bthf_client_subscriber_service_type_t type);
/** Callback for in-band ring tone settings
*/
typedef void (* bthf_client_in_band_ring_tone_callback) (bthf_client_in_band_ring_state_t state);
/**
* Callback for requested number from AG
*/
typedef void (* bthf_client_last_voice_tag_number_callback) (const char *number);
/**
* Callback for sending ring indication to app
*/
typedef void (* bthf_client_ring_indication_callback) (void);
/**
* Callback for sending cgmi indication to app
*/
typedef void (* bthf_client_cgmi_indication_callback) (const char *str);
/**
* Callback for sending cgmm indication to app
*/
typedef void (* bthf_client_cgmm_indication_callback) (const char *str);
/** BT-HF callback structure. */
typedef struct {
/** set to sizeof(BtHfClientCallbacks) */
size_t size;
bthf_client_connection_state_callback connection_state_cb;
bthf_client_audio_state_callback audio_state_cb;
bthf_client_vr_cmd_callback vr_cmd_cb;
bthf_client_network_state_callback network_state_cb;
bthf_client_network_roaming_callback network_roaming_cb;
bthf_client_network_signal_callback network_signal_cb;
bthf_client_battery_level_callback battery_level_cb;
bthf_client_current_operator_callback current_operator_cb;
bthf_client_call_callback call_cb;
bthf_client_callsetup_callback callsetup_cb;
bthf_client_callheld_callback callheld_cb;
bthf_client_resp_and_hold_callback resp_and_hold_cb;
bthf_client_clip_callback clip_cb;
bthf_client_call_waiting_callback call_waiting_cb;
bthf_client_current_calls current_calls_cb;
bthf_client_volume_change_callback volume_change_cb;
bthf_client_cmd_complete_callback cmd_complete_cb;
bthf_client_subscriber_info_callback subscriber_info_cb;
bthf_client_in_band_ring_tone_callback in_band_ring_tone_cb;
bthf_client_last_voice_tag_number_callback last_voice_tag_number_callback;
bthf_client_ring_indication_callback ring_indication_cb;
bthf_client_cgmi_indication_callback cgmi_cb;
bthf_client_cgmm_indication_callback cgmm_cb;
} bthf_client_callbacks_t;
/** Represents the standard BT-HF interface. */
typedef struct {
/** set to sizeof(BtHfClientInterface) */
size_t size;
/**
* Register the BtHf callbacks
*/
bt_status_t (*init)(bthf_client_callbacks_t* callbacks);
/** connect to audio gateway */
bt_status_t (*connect)(bt_bdaddr_t *bd_addr);
/** disconnect from audio gateway */
bt_status_t (*disconnect)(bt_bdaddr_t *bd_addr);
/** create an audio connection */
bt_status_t (*connect_audio)(bt_bdaddr_t *bd_addr);
/** close the audio connection */
bt_status_t (*disconnect_audio)(bt_bdaddr_t *bd_addr);
/** start voice recognition */
bt_status_t (*start_voice_recognition)(void);
/** stop voice recognition */
bt_status_t (*stop_voice_recognition)(void);
/** volume control */
bt_status_t (*volume_control) (bthf_client_volume_type_t type, int volume);
/** place a call with number a number
* if number is NULL last called number is called (aka re-dial)*/
bt_status_t (*dial) (const char *number);
/** place a call with number specified by location (speed dial) */
bt_status_t (*dial_memory) (int location);
/** perform specified call related action
* idx is limited only for enhanced call control related action
*/
bt_status_t (*handle_call_action) (bthf_client_call_action_t action, int idx);
/** query list of current calls */
bt_status_t (*query_current_calls) (void);
/** query name of current selected operator */
bt_status_t (*query_current_operator_name) (void);
/** Retrieve subscriber information */
bt_status_t (*retrieve_subscriber_info) (void);
/** Send DTMF code*/
bt_status_t (*send_dtmf) (char code);
/** Request a phone number from AG corresponding to last voice tag recorded */
bt_status_t (*request_last_voice_tag_number) (void);
/** Closes the interface. */
void (*cleanup)(void);
/** Send AT Command. */
bt_status_t (*send_at_cmd) (int cmd, int val1, int val2, const char *arg);
} bthf_client_interface_t;
__END_DECLS
#endif /* ANDROID_INCLUDE_BT_HF_CLIENT_H */
@@ -0,0 +1,191 @@
/*
* Copyright (C) 2012 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_BT_HH_H
#define ANDROID_INCLUDE_BT_HH_H
#include <stdint.h>
__BEGIN_DECLS
#define BTHH_MAX_DSC_LEN 884
/* HH connection states */
typedef enum
{
BTHH_CONN_STATE_CONNECTED = 0,
BTHH_CONN_STATE_CONNECTING,
BTHH_CONN_STATE_DISCONNECTED,
BTHH_CONN_STATE_DISCONNECTING,
BTHH_CONN_STATE_FAILED_MOUSE_FROM_HOST,
BTHH_CONN_STATE_FAILED_KBD_FROM_HOST,
BTHH_CONN_STATE_FAILED_TOO_MANY_DEVICES,
BTHH_CONN_STATE_FAILED_NO_BTHID_DRIVER,
BTHH_CONN_STATE_FAILED_GENERIC,
BTHH_CONN_STATE_UNKNOWN
} bthh_connection_state_t;
typedef enum
{
BTHH_OK = 0,
BTHH_HS_HID_NOT_READY, /* handshake error : device not ready */
BTHH_HS_INVALID_RPT_ID, /* handshake error : invalid report ID */
BTHH_HS_TRANS_NOT_SPT, /* handshake error : transaction not spt */
BTHH_HS_INVALID_PARAM, /* handshake error : invalid paremter */
BTHH_HS_ERROR, /* handshake error : unspecified HS error */
BTHH_ERR, /* general BTA HH error */
BTHH_ERR_SDP, /* SDP error */
BTHH_ERR_PROTO, /* SET_Protocol error,
only used in BTA_HH_OPEN_EVT callback */
BTHH_ERR_DB_FULL, /* device database full error, used */
BTHH_ERR_TOD_UNSPT, /* type of device not supported */
BTHH_ERR_NO_RES, /* out of system resources */
BTHH_ERR_AUTH_FAILED, /* authentication fail */
BTHH_ERR_HDL
}bthh_status_t;
/* Protocol modes */
typedef enum {
BTHH_REPORT_MODE = 0x00,
BTHH_BOOT_MODE = 0x01,
BTHH_UNSUPPORTED_MODE = 0xff
}bthh_protocol_mode_t;
/* Report types */
typedef enum {
BTHH_INPUT_REPORT = 1,
BTHH_OUTPUT_REPORT,
BTHH_FEATURE_REPORT
}bthh_report_type_t;
typedef struct
{
int attr_mask;
uint8_t sub_class;
uint8_t app_id;
int vendor_id;
int product_id;
int version;
uint8_t ctry_code;
int dl_len;
uint8_t dsc_list[BTHH_MAX_DSC_LEN];
} bthh_hid_info_t;
/** Callback for connection state change.
* state will have one of the values from bthh_connection_state_t
*/
typedef void (* bthh_connection_state_callback)(bt_bdaddr_t *bd_addr, bthh_connection_state_t state);
/** Callback for vitual unplug api.
* the status of the vitual unplug
*/
typedef void (* bthh_virtual_unplug_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status);
/** Callback for get hid info
* hid_info will contain attr_mask, sub_class, app_id, vendor_id, product_id, version, ctry_code, len
*/
typedef void (* bthh_hid_info_callback)(bt_bdaddr_t *bd_addr, bthh_hid_info_t hid_info);
/** Callback for get protocol api.
* the protocol mode is one of the value from bthh_protocol_mode_t
*/
typedef void (* bthh_protocol_mode_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, bthh_protocol_mode_t mode);
/** Callback for get/set_idle_time api.
*/
typedef void (* bthh_idle_time_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, int idle_rate);
/** Callback for get report api.
* if staus is ok rpt_data contains the report data
*/
typedef void (* bthh_get_report_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, uint8_t* rpt_data, int rpt_size);
/** Callback for set_report/set_protocol api and if error
* occurs for get_report/get_protocol api.
*/
typedef void (* bthh_handshake_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status);
/** BT-HH callback structure. */
typedef struct {
/** set to sizeof(BtHfCallbacks) */
size_t size;
bthh_connection_state_callback connection_state_cb;
bthh_hid_info_callback hid_info_cb;
bthh_protocol_mode_callback protocol_mode_cb;
bthh_idle_time_callback idle_time_cb;
bthh_get_report_callback get_report_cb;
bthh_virtual_unplug_callback virtual_unplug_cb;
bthh_handshake_callback handshake_cb;
} bthh_callbacks_t;
/** Represents the standard BT-HH interface. */
typedef struct {
/** set to sizeof(BtHhInterface) */
size_t size;
/**
* Register the BtHh callbacks
*/
bt_status_t (*init)( bthh_callbacks_t* callbacks );
/** connect to hid device */
bt_status_t (*connect)( bt_bdaddr_t *bd_addr);
/** dis-connect from hid device */
bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr );
/** Virtual UnPlug (VUP) the specified HID device */
bt_status_t (*virtual_unplug)(bt_bdaddr_t *bd_addr);
/** Set the HID device descriptor for the specified HID device. */
bt_status_t (*set_info)(bt_bdaddr_t *bd_addr, bthh_hid_info_t hid_info );
/** Get the HID proto mode. */
bt_status_t (*get_protocol) (bt_bdaddr_t *bd_addr, bthh_protocol_mode_t protocolMode);
/** Set the HID proto mode. */
bt_status_t (*set_protocol)(bt_bdaddr_t *bd_addr, bthh_protocol_mode_t protocolMode);
/** Get the HID Idle Time */
bt_status_t (*get_idle_time)(bt_bdaddr_t *bd_addr);
/** Set the HID Idle Time */
bt_status_t (*set_idle_time)(bt_bdaddr_t *bd_addr, uint8_t idleTime);
/** Send a GET_REPORT to HID device. */
bt_status_t (*get_report)(bt_bdaddr_t *bd_addr, bthh_report_type_t reportType, uint8_t reportId, int bufferSize);
/** Send a SET_REPORT to HID device. */
bt_status_t (*set_report)(bt_bdaddr_t *bd_addr, bthh_report_type_t reportType, char* report);
/** Send data to HID device. */
bt_status_t (*send_data)(bt_bdaddr_t *bd_addr, char* data);
/** Closes the interface. */
void (*cleanup)( void );
} bthh_interface_t;
__END_DECLS
#endif /* ANDROID_INCLUDE_BT_HH_H */
@@ -0,0 +1,123 @@
/*
* Copyright (C) 2012 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_BT_HL_H
#define ANDROID_INCLUDE_BT_HL_H
__BEGIN_DECLS
/* HL connection states */
typedef enum
{
BTHL_MDEP_ROLE_SOURCE,
BTHL_MDEP_ROLE_SINK
} bthl_mdep_role_t;
typedef enum {
BTHL_APP_REG_STATE_REG_SUCCESS,
BTHL_APP_REG_STATE_REG_FAILED,
BTHL_APP_REG_STATE_DEREG_SUCCESS,
BTHL_APP_REG_STATE_DEREG_FAILED
} bthl_app_reg_state_t;
typedef enum
{
BTHL_CHANNEL_TYPE_RELIABLE,
BTHL_CHANNEL_TYPE_STREAMING,
BTHL_CHANNEL_TYPE_ANY
} bthl_channel_type_t;
/* HL connection states */
typedef enum {
BTHL_CONN_STATE_CONNECTING,
BTHL_CONN_STATE_CONNECTED,
BTHL_CONN_STATE_DISCONNECTING,
BTHL_CONN_STATE_DISCONNECTED,
BTHL_CONN_STATE_DESTROYED
} bthl_channel_state_t;
typedef struct
{
bthl_mdep_role_t mdep_role;
int data_type;
bthl_channel_type_t channel_type;
const char *mdep_description; /* MDEP description to be used in the SDP (optional); null terminated */
} bthl_mdep_cfg_t;
typedef struct
{
const char *application_name;
const char *provider_name; /* provider name to be used in the SDP (optional); null terminated */
const char *srv_name; /* service name to be used in the SDP (optional); null terminated*/
const char *srv_desp; /* service description to be used in the SDP (optional); null terminated */
int number_of_mdeps;
bthl_mdep_cfg_t *mdep_cfg; /* Dynamic array */
} bthl_reg_param_t;
/** Callback for application registration status.
* state will have one of the values from bthl_app_reg_state_t
*/
typedef void (* bthl_app_reg_state_callback)(int app_id, bthl_app_reg_state_t state);
/** Callback for channel connection state change.
* state will have one of the values from
* bthl_connection_state_t and fd (file descriptor)
*/
typedef void (* bthl_channel_state_callback)(int app_id, bt_bdaddr_t *bd_addr, int mdep_cfg_index, int channel_id, bthl_channel_state_t state, int fd);
/** BT-HL callback structure. */
typedef struct {
/** set to sizeof(bthl_callbacks_t) */
size_t size;
bthl_app_reg_state_callback app_reg_state_cb;
bthl_channel_state_callback channel_state_cb;
} bthl_callbacks_t;
/** Represents the standard BT-HL interface. */
typedef struct {
/** set to sizeof(bthl_interface_t) */
size_t size;
/**
* Register the Bthl callbacks
*/
bt_status_t (*init)( bthl_callbacks_t* callbacks );
/** Register HL application */
bt_status_t (*register_application) ( bthl_reg_param_t *p_reg_param, int *app_id);
/** Unregister HL application */
bt_status_t (*unregister_application) (int app_id);
/** connect channel */
bt_status_t (*connect_channel)(int app_id, bt_bdaddr_t *bd_addr, int mdep_cfg_index, int *channel_id);
/** destroy channel */
bt_status_t (*destroy_channel)(int channel_id);
/** Close the Bthl callback **/
void (*cleanup)(void);
} bthl_interface_t;
__END_DECLS
#endif /* ANDROID_INCLUDE_BT_HL_H */
@@ -0,0 +1,54 @@
/*
* 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_INCLUDE_BT_MCE_H
#define ANDROID_INCLUDE_BT_MCE_H
__BEGIN_DECLS
/** MAS instance description */
typedef struct
{
int id;
int scn;
int msg_types;
char *p_name;
} btmce_mas_instance_t;
/** callback for get_remote_mas_instances */
typedef void (*btmce_remote_mas_instances_callback)(bt_status_t status, bt_bdaddr_t *bd_addr,
int num_instances, btmce_mas_instance_t *instances);
typedef struct {
/** set to sizeof(btmce_callbacks_t) */
size_t size;
btmce_remote_mas_instances_callback remote_mas_instances_cb;
} btmce_callbacks_t;
typedef struct {
/** set to size of this struct */
size_t size;
/** register BT MCE callbacks */
bt_status_t (*init)(btmce_callbacks_t *callbacks);
/** search for MAS instances on remote device */
bt_status_t (*get_remote_mas_instances)(bt_bdaddr_t *bd_addr);
} btmce_interface_t;
__END_DECLS
#endif /* ANDROID_INCLUDE_BT_MCE_H */
@@ -0,0 +1,87 @@
/*
* Copyright (C) 2012 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_BT_PAN_H
#define ANDROID_INCLUDE_BT_PAN_H
__BEGIN_DECLS
#define BTPAN_ROLE_NONE 0
#define BTPAN_ROLE_PANNAP 1
#define BTPAN_ROLE_PANU 2
typedef enum {
BTPAN_STATE_CONNECTED = 0,
BTPAN_STATE_CONNECTING = 1,
BTPAN_STATE_DISCONNECTED = 2,
BTPAN_STATE_DISCONNECTING = 3
} btpan_connection_state_t;
typedef enum {
BTPAN_STATE_ENABLED = 0,
BTPAN_STATE_DISABLED = 1
} btpan_control_state_t;
/**
* Callback for pan connection state
*/
typedef void (*btpan_connection_state_callback)(btpan_connection_state_t state, bt_status_t error,
const bt_bdaddr_t *bd_addr, int local_role, int remote_role);
typedef void (*btpan_control_state_callback)(btpan_control_state_t state, int local_role,
bt_status_t error, const char* ifname);
typedef struct {
size_t size;
btpan_control_state_callback control_state_cb;
btpan_connection_state_callback connection_state_cb;
} btpan_callbacks_t;
typedef struct {
/** set to size of this struct*/
size_t size;
/**
* Initialize the pan interface and register the btpan callbacks
*/
bt_status_t (*init)(const btpan_callbacks_t* callbacks);
/*
* enable the pan service by specified role. The result state of
* enabl will be returned by btpan_control_state_callback. when pan-nap is enabled,
* the state of connecting panu device will be notified by btpan_connection_state_callback
*/
bt_status_t (*enable)(int local_role);
/*
* get current pan local role
*/
int (*get_local_role)(void);
/**
* start bluetooth pan connection to the remote device by specified pan role. The result state will be
* returned by btpan_connection_state_callback
*/
bt_status_t (*connect)(const bt_bdaddr_t *bd_addr, int local_role, int remote_role);
/**
* stop bluetooth pan connection. The result state will be returned by btpan_connection_state_callback
*/
bt_status_t (*disconnect)(const bt_bdaddr_t *bd_addr);
/**
* Cleanup the pan interface
*/
void (*cleanup)(void);
} btpan_interface_t;
__END_DECLS
#endif /* ANDROID_INCLUDE_BT_PAN_H */
@@ -0,0 +1,527 @@
/*
* Copyright (C) 2013-2014, The Linux Foundation. All rights reserved.
* Not a Contribution.
*
* Copyright (C) 2012 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_BT_RC_H
#define ANDROID_INCLUDE_BT_RC_H
__BEGIN_DECLS
/* Macros */
#define BTRC_MAX_ATTR_STR_LEN 255
#define BTRC_UID_SIZE 8
#define BTRC_MAX_APP_SETTINGS 8
#define BTRC_MAX_FOLDER_DEPTH 4
#define BTRC_MAX_APP_ATTR_SIZE 16
#define BTRC_MAX_ELEM_ATTR_SIZE 7
#define BTRC_CHARSET_UTF8 0x006A
typedef uint8_t btrc_uid_t[BTRC_UID_SIZE];
typedef enum {
BTRC_FEAT_NONE = 0x00, /* AVRCP 1.0 */
BTRC_FEAT_METADATA = 0x01, /* AVRCP 1.3 */
BTRC_FEAT_ABSOLUTE_VOLUME = 0x02, /* Supports TG role and volume sync */
BTRC_FEAT_BROWSE = 0x04, /* AVRCP 1.4 and up, with Browsing support */
} btrc_remote_features_t;
typedef enum {
BTRC_PLAYSTATE_STOPPED = 0x00, /* Stopped */
BTRC_PLAYSTATE_PLAYING = 0x01, /* Playing */
BTRC_PLAYSTATE_PAUSED = 0x02, /* Paused */
BTRC_PLAYSTATE_FWD_SEEK = 0x03, /* Fwd Seek*/
BTRC_PLAYSTATE_REV_SEEK = 0x04, /* Rev Seek*/
BTRC_PLAYSTATE_ERROR = 0xFF, /* Error */
} btrc_play_status_t;
typedef enum {
BTRC_EVT_PLAY_STATUS_CHANGED = 0x01,
BTRC_EVT_TRACK_CHANGE = 0x02,
BTRC_EVT_TRACK_REACHED_END = 0x03,
BTRC_EVT_TRACK_REACHED_START = 0x04,
BTRC_EVT_PLAY_POS_CHANGED = 0x05,
BTRC_EVT_APP_SETTINGS_CHANGED = 0x08,
BTRC_EVT_NOW_PLAYING_CONTENT_CHANGED = 0x09,
BTRC_EVT_AVAILABLE_PLAYERS_CHANGED = 0x0a,
BTRC_EVT_ADDRESSED_PLAYER_CHANGED = 0x0b,
} btrc_event_id_t;
//used for Scope
typedef enum {
BTRC_EVT_MEDIA_PLAYLIST = 0,
BTRC_EVT_MEDIA_VIRTUALFILESYST = 1,
BTRC_EVT_SEARCH = 2,
BTRC_EVT_NOWPLAYING = 3,
BTRC_EVT_MAX_BROWSE = 4,
} btrc_browse_folderitem_t;
typedef enum {
BTRC_NOTIFICATION_TYPE_INTERIM = 0,
BTRC_NOTIFICATION_TYPE_CHANGED = 1,
BTRC_NOTIFICATION_TYPE_REJECT = 2,
} btrc_notification_type_t;
typedef enum {
BTRC_PLAYER_ATTR_EQUALIZER = 0x01,
BTRC_PLAYER_ATTR_REPEAT = 0x02,
BTRC_PLAYER_ATTR_SHUFFLE = 0x03,
BTRC_PLAYER_ATTR_SCAN = 0x04,
} btrc_player_attr_t;
typedef enum {
BTRC_MEDIA_ATTR_TITLE = 0x01,
BTRC_MEDIA_ATTR_ARTIST = 0x02,
BTRC_MEDIA_ATTR_ALBUM = 0x03,
BTRC_MEDIA_ATTR_TRACK_NUM = 0x04,
BTRC_MEDIA_ATTR_NUM_TRACKS = 0x05,
BTRC_MEDIA_ATTR_GENRE = 0x06,
BTRC_MEDIA_ATTR_PLAYING_TIME = 0x07,
} btrc_media_attr_t;
typedef enum {
BTRC_PLAYER_VAL_OFF_REPEAT = 0x01,
BTRC_PLAYER_VAL_SINGLE_REPEAT = 0x02,
BTRC_PLAYER_VAL_ALL_REPEAT = 0x03,
BTRC_PLAYER_VAL_GROUP_REPEAT = 0x04
} btrc_player_repeat_val_t;
typedef enum {
BTRC_PLAYER_VAL_OFF_SHUFFLE = 0x01,
BTRC_PLAYER_VAL_ALL_SHUFFLE = 0x02,
BTRC_PLAYER_VAL_GROUP_SHUFFLE = 0x03
} btrc_player_shuffle_val_t;
typedef enum {
BTRC_STS_BAD_CMD = 0x00, /* Invalid command */
BTRC_STS_BAD_PARAM = 0x01, /* Invalid parameter */
BTRC_STS_NOT_FOUND = 0x02, /* Specified parameter is wrong or not found */
BTRC_STS_INTERNAL_ERR = 0x03, /* Internal Error */
BTRC_STS_NO_ERROR = 0x04 /* Operation Success */
} btrc_status_t;
typedef enum {
BTRC_TYPE_MEDIA_PLAYER = 0x01,
BTRC_TYPE_FOLDER = 0x02,
BTRC_TYPE_MEDIA_ELEMENT = 0x03
} btrc_folder_list_item_type_t;
typedef struct {
uint8_t num_attr;
uint8_t attr_ids[BTRC_MAX_APP_SETTINGS];
uint8_t attr_values[BTRC_MAX_APP_SETTINGS];
} btrc_player_settings_t;
typedef struct {
uint32_t start_item;
uint32_t end_item;
uint32_t size;
uint32_t attrs[BTRC_MAX_ELEM_ATTR_SIZE];
uint8_t attr_count;
}btrc_getfolderitem_t;
typedef union
{
btrc_play_status_t play_status;
btrc_uid_t track; /* queue position in NowPlaying */
uint32_t song_pos;
btrc_player_settings_t player_setting;
uint16_t player_id;
} btrc_register_notification_t;
typedef struct {
uint8_t id; /* can be attr_id or value_id */
uint8_t text[BTRC_MAX_ATTR_STR_LEN];
} btrc_player_setting_text_t;
typedef struct {
uint32_t attr_id;
uint8_t text[BTRC_MAX_ATTR_STR_LEN];
} btrc_element_attr_val_t;
/** Callback for the controller's supported feautres */
typedef void (* btrc_remote_features_callback)(bt_bdaddr_t *bd_addr,
btrc_remote_features_t features);
#define BTRC_FEATURE_MASK_SIZE 16
typedef uint8_t btrc_feature_mask_t[BTRC_FEATURE_MASK_SIZE];
typedef struct {
uint16_t charset_id;
uint16_t str_len;
uint8_t *p_str;
} btrc_player_full_name_t;
typedef struct
{
uint32_t sub_type;
uint16_t player_id;
uint8_t major_type;
uint8_t play_status;
btrc_feature_mask_t features; /* Supported feature bit mask*/
btrc_player_full_name_t name; /* The player name, name length and character set id.*/
} btrc_folder_list_item_player_t;
typedef struct
{
uint64_t uid;
uint8_t type;
uint8_t playable;
btrc_player_full_name_t name;
} btrc_folder_list_item_folder_t;
typedef struct
{
uint32_t attr_id;
btrc_player_full_name_t name;
} btrc_attr_entry_t;
typedef struct
{
uint64_t uid;
uint8_t type;
uint8_t attr_count;
btrc_player_full_name_t name;
btrc_attr_entry_t* p_attr_list;
} btrc_folder_list_item_media_t;
typedef struct {
uint16_t str_len;
uint8_t *p_str;
} btrc_name_t;
/* SetBrowsedPlayer */
typedef struct
{
uint32_t num_items;
uint16_t uid_counter;
uint16_t charset_id;
uint8_t status;
uint8_t folder_depth;
btrc_name_t *p_folders;
} btrc_set_browsed_player_rsp_t;
typedef struct
{
uint8_t item_type;
union
{
btrc_folder_list_item_player_t player;
btrc_folder_list_item_folder_t folder;
btrc_folder_list_item_media_t media;
} u;
} btrc_folder_list_item_t;
/* GetFolderItems */
typedef struct
{
uint16_t uid_counter;
uint16_t item_count;
uint8_t status;
btrc_folder_list_item_t *p_item_list;
} btrc_folder_list_entries_t;
/** Callback for play status request */
typedef void (* btrc_get_play_status_callback)(bt_bdaddr_t *bd_addr);
/** Callback for list player application attributes (Shuffle, Repeat,...) */
typedef void (* btrc_list_player_app_attr_callback)(bt_bdaddr_t *bd_addr);
/** Callback for list player application attributes (Shuffle, Repeat,...) */
typedef void (* btrc_list_player_app_values_callback)(btrc_player_attr_t attr_id,
bt_bdaddr_t *bd_addr);
/** Callback for getting the current player application settings value
** num_attr: specifies the number of attribute ids contained in p_attrs
*/
typedef void (* btrc_get_player_app_value_callback) (uint8_t num_attr, btrc_player_attr_t *p_attrs,
bt_bdaddr_t *bd_addr);
/** Callback for getting the player application settings attributes' text
** num_attr: specifies the number of attribute ids contained in p_attrs
*/
typedef void (* btrc_get_player_app_attrs_text_callback) (uint8_t num_attr,
btrc_player_attr_t *p_attrs, bt_bdaddr_t *bd_addr);
/** Callback for getting the player application settings values' text
** num_attr: specifies the number of value ids contained in p_vals
*/
typedef void (* btrc_get_player_app_values_text_callback) (uint8_t attr_id,
uint8_t num_val, uint8_t *p_vals, bt_bdaddr_t *bd_addr);
/** Callback for setting the player application settings values */
typedef void (* btrc_set_player_app_value_callback) (btrc_player_settings_t *p_vals,
bt_bdaddr_t *bd_addr);
/** Callback to fetch the get element attributes of the current song
** num_attr: specifies the number of attributes requested in p_attrs
*/
typedef void (* btrc_get_element_attr_callback) (uint8_t num_attr, btrc_media_attr_t *p_attrs,
bt_bdaddr_t *bd_addr);
/** Callback for register notification (Play state change/track change/...)
** param: Is only valid if event_id is BTRC_EVT_PLAY_POS_CHANGED
*/
typedef void (* btrc_register_notification_callback) (btrc_event_id_t event_id, uint32_t param,
bt_bdaddr_t *bd_addr);
/* AVRCP 1.4 Enhancements */
/** Callback for volume change on CT
** volume: Current volume setting on the CT (0-127)
*/
typedef void (* btrc_volume_change_callback) (uint8_t volume, uint8_t ctype, bt_bdaddr_t *bd_addr);
/** Callback for passthrough commands */
typedef void (* btrc_passthrough_cmd_callback) (int id, int key_state, bt_bdaddr_t *bd_addr);
/** BT-RC Target callback structure. */
typedef void (* btrc_get_folder_items_callback) (btrc_browse_folderitem_t id,
btrc_getfolderitem_t *param, bt_bdaddr_t *bd_addr);
typedef void (* btrc_set_addressed_player_callback) (uint32_t player_id, bt_bdaddr_t *bd_addr);
typedef void (* btrc_set_browsed_player_callback) (uint32_t player_id, bt_bdaddr_t *bd_addr);
typedef void (* btrc_change_path_callback) (uint8_t direction, uint64_t uid, bt_bdaddr_t *bd_addr);
typedef void (* btrc_play_item_callback) (uint8_t scope, uint64_t uid, bt_bdaddr_t *bd_addr);
typedef void (* btrc_get_item_attr_callback) (uint8_t scope, uint64_t uid,
uint8_t num_attr, btrc_media_attr_t *p_attrs, bt_bdaddr_t *bd_addr);
typedef void (* btrc_connection_state_callback) (bool state, bt_bdaddr_t *bd_addr);
typedef struct {
/** set to sizeof(BtRcCallbacks) */
size_t size;
btrc_remote_features_callback remote_features_cb;
btrc_get_play_status_callback get_play_status_cb;
btrc_list_player_app_attr_callback list_player_app_attr_cb;
btrc_list_player_app_values_callback list_player_app_values_cb;
btrc_get_player_app_value_callback get_player_app_value_cb;
btrc_get_player_app_attrs_text_callback get_player_app_attrs_text_cb;
btrc_get_player_app_values_text_callback get_player_app_values_text_cb;
btrc_set_player_app_value_callback set_player_app_value_cb;
btrc_get_element_attr_callback get_element_attr_cb;
btrc_register_notification_callback register_notification_cb;
btrc_volume_change_callback volume_change_cb;
btrc_passthrough_cmd_callback passthrough_cmd_cb;
btrc_get_folder_items_callback get_folderitems_cb;
btrc_set_addressed_player_callback set_addrplayer_cb;
btrc_set_browsed_player_callback set_browsed_player_cb;
btrc_change_path_callback change_path_cb;
btrc_play_item_callback play_item_cb;
btrc_get_item_attr_callback get_item_attr_cb;
btrc_connection_state_callback connection_state_cb;
} btrc_callbacks_t;
/** Represents the standard BT-RC AVRCP Target interface. */
typedef struct {
/** set to sizeof(BtRcInterface) */
size_t size;
/**
* Register the BtRc callbacks
*/
bt_status_t (*init)( btrc_callbacks_t* callbacks , int max_avrcp_connections);
/** Respose to GetPlayStatus request. Contains the current
** 1. Play status
** 2. Song duration/length
** 3. Song position
*/
bt_status_t (*get_play_status_rsp)( btrc_play_status_t play_status, uint32_t song_len,
uint32_t song_pos, bt_bdaddr_t *bd_addr);
/** Lists the support player application attributes (Shuffle/Repeat/...)
** num_attr: Specifies the number of attributes contained in the pointer p_attrs
*/
bt_status_t (*list_player_app_attr_rsp)( uint8_t num_attr, btrc_player_attr_t *p_attrs,
bt_bdaddr_t *bd_addr);
/** Lists the support player application attributes (Shuffle Off/On/Group)
** num_val: Specifies the number of values contained in the pointer p_vals
*/
bt_status_t (*list_player_app_value_rsp)( uint8_t num_val, uint8_t *p_vals,
bt_bdaddr_t *bd_addr);
/** Returns the current application attribute values for each of the specified attr_id */
bt_status_t (*get_player_app_value_rsp)( btrc_player_settings_t *p_vals,
bt_bdaddr_t *bd_addr);
/** Returns the application attributes text ("Shuffle"/"Repeat"/...)
** num_attr: Specifies the number of attributes' text contained in the pointer p_attrs
*/
bt_status_t (*get_player_app_attr_text_rsp)( int num_attr, btrc_player_setting_text_t *p_attrs,
bt_bdaddr_t *bd_addr);
/** Returns the application attributes text ("Shuffle"/"Repeat"/...)
** num_attr: Specifies the number of attribute values' text contained in the pointer p_vals
*/
bt_status_t (*get_player_app_value_text_rsp)( int num_val, btrc_player_setting_text_t *p_vals,
bt_bdaddr_t *bd_addr);
/** Returns the current songs' element attributes text ("Title"/"Album"/"Artist")
** num_attr: Specifies the number of attributes' text contained in the pointer p_attrs
*/
bt_status_t (*get_element_attr_rsp)( uint8_t num_attr, btrc_element_attr_val_t *p_attrs,
bt_bdaddr_t *bd_addr);
/** Response to set player attribute request ("Shuffle"/"Repeat")
** rsp_status: Status of setting the player attributes for the current media player
*/
bt_status_t (*set_player_app_value_rsp)(btrc_status_t rsp_status, bt_bdaddr_t *bd_addr);
/* Response to the register notification request (Play state change/track change/...).
** event_id: Refers to the event_id this notification change corresponds too
** type: Response type - interim/changed
** p_params: Based on the event_id, this parameter should be populated
*/
bt_status_t (*register_notification_rsp)(btrc_event_id_t event_id,
btrc_notification_type_t type,
btrc_register_notification_t *p_param,
bt_bdaddr_t *bd_addr);
/* AVRCP 1.4 enhancements */
/**Send current volume setting to remote side. Support limited to SetAbsoluteVolume
** This can be enhanced to support Relative Volume (AVRCP 1.0).
** With RelateVolume, we will send VOLUME_UP/VOLUME_DOWN opposed to absolute volume level
** volume: Should be in the range 0-127. bit7 is reseved and cannot be set
*/
bt_status_t (*set_volume)(uint8_t volume, bt_bdaddr_t *bd_addr);
bt_status_t (*get_folder_items_rsp) (btrc_folder_list_entries_t *p_param, bt_bdaddr_t *bd_addr);
bt_status_t (*set_addressed_player_rsp) (btrc_status_t status_code, bt_bdaddr_t *bd_addr);
bt_status_t (*set_browsed_player_rsp) (btrc_set_browsed_player_rsp_t *p_param,
bt_bdaddr_t *bd_addr);
bt_status_t (*change_path_rsp) (uint8_t status_code, uint32_t item_count,
bt_bdaddr_t *bd_addr);
bt_status_t (*play_item_rsp) (uint8_t status_code, bt_bdaddr_t *bd_addr);
bt_status_t (*get_item_attr_rsp)( uint8_t num_attr, btrc_element_attr_val_t *p_attrs,
bt_bdaddr_t *bd_addr);
bt_status_t (*is_device_active_in_handoff) (bt_bdaddr_t *bd_addr);
/** Closes the interface. */
void (*cleanup)( void );
} btrc_interface_t;
typedef void (* btrc_passthrough_rsp_callback) (int id, int key_state);
typedef void (* btrc_connection_state_callback) (bool state, bt_bdaddr_t *bd_addr);
typedef void (* btrc_ctrl_getrcfeatures_callback) (bt_bdaddr_t *bd_addr, int features);
typedef void (* btrc_ctrl_getcapability_rsp_callback) (bt_bdaddr_t *bd_addr, int cap_id,
uint32_t* supported_values, int num_supported, uint8_t rsp_type);
typedef void (* btrc_ctrl_listplayerappsettingattrib_rsp_callback) (bt_bdaddr_t *bd_addr,
uint8_t* supported_attribs, int num_attrib, uint8_t rsp_type);
typedef void (* btrc_ctrl_listplayerappsettingvalue_rsp_callback) (bt_bdaddr_t *bd_addr,
uint8_t* supported_val, uint8_t num_supported, uint8_t rsp_type);
typedef void (* btrc_ctrl_currentplayerappsetting_rsp_callback) (bt_bdaddr_t *bd_addr,uint8_t* supported_ids,
uint8_t* supported_val, uint8_t num_attrib, uint8_t rsp_type);
typedef void (* btrc_ctrl_setplayerapplicationsetting_rsp_callback) (bt_bdaddr_t *bd_addr,uint8_t rsp_type);
typedef void (* btrc_ctrl_notification_rsp_callback) (bt_bdaddr_t *bd_addr, uint8_t rsp_type,
int rsp_len, uint8_t* notification_rsp);
typedef void (* btrc_ctrl_getelementattrib_rsp_callback) (bt_bdaddr_t *bd_addr, uint8_t num_attributes,
int rsp_len, uint8_t* attrib_rsp, uint8_t rsp_type);
typedef void (* btrc_ctrl_getplaystatus_rsp_callback) (bt_bdaddr_t *bd_addr, int param_len, uint8_t* play_status_rsp
,uint8_t rsp_type);
typedef void (* btrc_ctrl_setabsvol_cmd_callback) (bt_bdaddr_t *bd_addr, uint8_t abs_vol);
typedef void (* btrc_ctrl_registernotification_abs_vol_callback) (bt_bdaddr_t *bd_addr);
/** BT-RC Controller callback structure. */
typedef struct {
/** set to sizeof(BtRcCallbacks) */
size_t size;
btrc_passthrough_rsp_callback passthrough_rsp_cb;
btrc_connection_state_callback connection_state_cb;
btrc_ctrl_getrcfeatures_callback getrcfeatures_cb;
btrc_ctrl_getcapability_rsp_callback getcap_rsp_cb;
btrc_ctrl_listplayerappsettingattrib_rsp_callback listplayerappsettingattrib_rsp_cb;
btrc_ctrl_listplayerappsettingvalue_rsp_callback listplayerappsettingvalue_rsp_cb;
btrc_ctrl_currentplayerappsetting_rsp_callback currentplayerappsetting_rsp_cb;
btrc_ctrl_setplayerapplicationsetting_rsp_callback setplayerappsetting_rsp_cb;
btrc_ctrl_notification_rsp_callback notification_rsp_cb;
btrc_ctrl_getelementattrib_rsp_callback getelementattrib_rsp_cb;
btrc_ctrl_getplaystatus_rsp_callback getplaystatus_rsp_cb;
btrc_ctrl_setabsvol_cmd_callback setabsvol_cmd_cb;
btrc_ctrl_registernotification_abs_vol_callback registernotification_absvol_cb;
} btrc_ctrl_callbacks_t;
/** Represents the standard BT-RC AVRCP Controller interface. */
typedef struct {
/** set to sizeof(BtRcInterface) */
size_t size;
/**
* Register the BtRc callbacks
*/
bt_status_t (*init)( btrc_ctrl_callbacks_t* callbacks );
/** send pass through command to target */
bt_status_t (*send_pass_through_cmd) ( bt_bdaddr_t *bd_addr, uint8_t key_code,
uint8_t key_state );
/** send get_cap command to target */
bt_status_t (*getcapabilities_cmd) (uint8_t cap_id);
/** send command to get supported player application settings to target */
bt_status_t (*list_player_app_setting_attrib_cmd) (void);
/** send command to get supported values of player application settings for a
* particular attribute to target */
bt_status_t (*list_player_app_setting_value_cmd) (uint8_t attrib_id);
/** send command to get current player attributes to target */
bt_status_t (*get_player_app_setting_cmd) (uint8_t num_attrib, uint8_t* attrib_ids);
/** send command to set player applicaiton setting attributes to target */
bt_status_t (*set_player_app_setting_cmd) (uint8_t num_attrib, uint8_t* attrib_ids, uint8_t* attrib_vals);
/** send command to register for supported notificaiton events to target */
bt_status_t (*register_notification_cmd) (uint8_t event_id, uint32_t event_value);
/** send command to get element attribute to target */
bt_status_t (*get_element_attribute_cmd) (uint8_t num_attribute, uint32_t attribute_id);
/** send command to get play status to target */
bt_status_t (*get_play_status_cmd) (void);
/** send rsp to set_abs_vol received from target */
bt_status_t (*send_abs_vol_rsp) (uint8_t abs_vol);
/** send notificaiton rsp for abs vol to target */
bt_status_t (*send_register_abs_vol_rsp) (uint8_t rsp_type, uint8_t abs_vol);
/** Closes the interface. */
void (*cleanup)( void );
} btrc_ctrl_interface_t;
__END_DECLS
#endif /* ANDROID_INCLUDE_BT_RC_H */
@@ -0,0 +1,150 @@
/*
* 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.
*/
#pragma once
#include "bluetooth.h"
#define SDP_OPP_SUPPORTED_FORMATS_MAX_LENGTH 15
__BEGIN_DECLS
/**
* These events are handled by the state machine
*/
typedef enum {
SDP_TYPE_RAW, // Used to carry raw SDP search data for unknown UUIDs
SDP_TYPE_MAP_MAS, // Message Access Profile - Server
SDP_TYPE_MAP_MNS, // Message Access Profile - Client (Notification Server)
SDP_TYPE_PBAP_PSE, // Phone Book Profile - Server
SDP_TYPE_PBAP_PCE, // Phone Book Profile - Client
SDP_TYPE_OPP_SERVER, // Object Push Profile
SDP_TYPE_SAP_SERVER // SIM Access Profile
} bluetooth_sdp_types;
typedef struct _bluetooth_sdp_hdr {
bluetooth_sdp_types type;
bt_uuid_t uuid;
uint32_t service_name_length;
char *service_name;
int32_t rfcomm_channel_number;
int32_t l2cap_psm;
int32_t profile_version;
} bluetooth_sdp_hdr;
/**
* Some signals need additional pointers, hence we introduce a
* generic way to handle these pointers.
*/
typedef struct _bluetooth_sdp_hdr_overlay {
bluetooth_sdp_types type;
bt_uuid_t uuid;
uint32_t service_name_length;
char *service_name;
int32_t rfcomm_channel_number;
int32_t l2cap_psm;
int32_t profile_version;
// User pointers, only used for some signals - see bluetooth_sdp_ops_record
int user1_ptr_len;
uint8_t *user1_ptr;
int user2_ptr_len;
uint8_t *user2_ptr;
} bluetooth_sdp_hdr_overlay;
typedef struct _bluetooth_sdp_mas_record {
bluetooth_sdp_hdr_overlay hdr;
uint32_t mas_instance_id;
uint32_t supported_features;
uint32_t supported_message_types;
} bluetooth_sdp_mas_record;
typedef struct _bluetooth_sdp_mns_record {
bluetooth_sdp_hdr_overlay hdr;
uint32_t supported_features;
} bluetooth_sdp_mns_record;
typedef struct _bluetooth_sdp_pse_record {
bluetooth_sdp_hdr_overlay hdr;
uint32_t supported_features;
uint32_t supported_repositories;
} bluetooth_sdp_pse_record;
typedef struct _bluetooth_sdp_pce_record {
bluetooth_sdp_hdr_overlay hdr;
} bluetooth_sdp_pce_record;
typedef struct _bluetooth_sdp_ops_record {
bluetooth_sdp_hdr_overlay hdr;
int supported_formats_list_len;
uint8_t supported_formats_list[SDP_OPP_SUPPORTED_FORMATS_MAX_LENGTH];
} bluetooth_sdp_ops_record;
typedef struct _bluetooth_sdp_sap_record {
bluetooth_sdp_hdr_overlay hdr;
} bluetooth_sdp_sap_record;
typedef union {
bluetooth_sdp_hdr_overlay hdr;
bluetooth_sdp_mas_record mas;
bluetooth_sdp_mns_record mns;
bluetooth_sdp_pse_record pse;
bluetooth_sdp_pce_record pce;
bluetooth_sdp_ops_record ops;
bluetooth_sdp_sap_record sap;
} bluetooth_sdp_record;
/** Callback for SDP search */
typedef void (*btsdp_search_callback)(bt_status_t status, bt_bdaddr_t *bd_addr, uint8_t* uuid, int num_records, bluetooth_sdp_record *records);
typedef struct {
/** Set to sizeof(btsdp_callbacks_t) */
size_t size;
btsdp_search_callback sdp_search_cb;
} btsdp_callbacks_t;
typedef struct {
/** Set to size of this struct */
size_t size;
/** Register BT SDP search callbacks */
bt_status_t (*init)(btsdp_callbacks_t *callbacks);
/** Unregister BT SDP */
bt_status_t (*deinit)();
/** Search for SDP records with specific uuid on remote device */
bt_status_t (*sdp_search)(bt_bdaddr_t *bd_addr, const uint8_t* uuid);
/**
* Use listen in the socket interface to create rfcomm and/or l2cap PSM channels,
* (without UUID and service_name and set the BTSOCK_FLAG_NO_SDP flag in flags).
* Then use createSdpRecord to create the SDP record associated with the rfcomm/l2cap channels.
*
* Returns a handle to the SDP record, which can be parsed to remove_sdp_record.
*
* record (in) The SDP record to create
* record_handle (out)The corresponding record handle will be written to this pointer.
*/
bt_status_t (*create_sdp_record)(bluetooth_sdp_record *record, int* record_handle);
/** Remove a SDP record created by createSdpRecord */
bt_status_t (*remove_sdp_record)(int sdp_handle);
} btsdp_interface_t;
__END_DECLS
@@ -0,0 +1,91 @@
/*
* Copyright (C) 2012 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.
*/
#pragma once
__BEGIN_DECLS
#define BTSOCK_FLAG_ENCRYPT 1
#define BTSOCK_FLAG_AUTH (1 << 1)
#define BTSOCK_FLAG_NO_SDP (1 << 2)
#define BTSOCK_FLAG_AUTH_MITM (1 << 3)
#define BTSOCK_FLAG_AUTH_16_DIGIT (1 << 4)
typedef enum {
BTSOCK_RFCOMM = 1,
BTSOCK_SCO = 2,
BTSOCK_L2CAP = 3
} btsock_type_t;
typedef enum {
BTSOCK_OPT_GET_MODEM_BITS = 1,
BTSOCK_OPT_SET_MODEM_BITS = 2,
BTSOCK_OPT_CLR_MODEM_BITS = 3,
} btsock_option_type_t;
/** Represents the standard BT SOCKET interface. */
typedef struct {
short size;
bt_bdaddr_t bd_addr;
int channel;
int status;
// The writer must make writes using a buffer of this maximum size
// to avoid loosing data. (L2CAP only)
unsigned short max_tx_packet_size;
// The reader must read using a buffer of at least this size to avoid
// loosing data. (L2CAP only)
unsigned short max_rx_packet_size;
} __attribute__((packed)) sock_connect_signal_t;
typedef struct {
/** set to size of this struct*/
size_t size;
/**
* Listen to a RFCOMM UUID or channel. It returns the socket fd from which
* btsock_connect_signal can be read out when a remote device connected.
* If neither a UUID nor a channel is provided, a channel will be allocated
* and a service record can be created providing the channel number to
* create_sdp_record(...) in bt_sdp.
*/
bt_status_t (*listen)(btsock_type_t type, const char* service_name,
const uint8_t* service_uuid, int channel, int* sock_fd, int flags);
/**
* Connect to a RFCOMM UUID channel of remote device, It returns the socket fd from which
* the btsock_connect_signal and a new socket fd to be accepted can be read out when connected
*/
bt_status_t (*connect)(const bt_bdaddr_t *bd_addr, btsock_type_t type, const uint8_t* uuid,
int channel, int* sock_fd, int flags);
/*
* get socket option of rfcomm channel socket.
*/
bt_status_t (*get_sock_opt)(btsock_type_t type, int channel, btsock_option_type_t option_name,
void *option_value, int *option_len);
/*
* set socket option of rfcomm channel socket.
*/
bt_status_t (*set_sock_opt)(btsock_type_t type, int channel, btsock_option_type_t option_name,
void *option_value, int option_len);
} btsock_interface_t;
__END_DECLS
@@ -0,0 +1,298 @@
/*
* Copyright (C) 2010-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_INCLUDE_CAMERA_H
#define ANDROID_INCLUDE_CAMERA_H
#include "camera_common.h"
/**
* Camera device HAL, initial version [ CAMERA_DEVICE_API_VERSION_1_0 ]
*
* DEPRECATED. New devices should use Camera HAL v3.2 or newer.
*
* Supports the android.hardware.Camera API, and the android.hardware.camera2
* API in legacy mode only.
*
* Camera devices that support this version of the HAL must return a value in
* the range HARDWARE_DEVICE_API_VERSION(0,0)-(1,FF) in
* camera_device_t.common.version. CAMERA_DEVICE_API_VERSION_1_0 is the
* recommended value.
*
* Camera modules that implement version 2.0 or higher of camera_module_t must
* also return the value of camera_device_t.common.version in
* camera_info_t.device_version.
*
* See camera_common.h for more details.
*/
__BEGIN_DECLS
struct camera_memory;
typedef void (*camera_release_memory)(struct camera_memory *mem);
typedef struct camera_memory {
void *data;
size_t size;
void *handle;
camera_release_memory release;
} camera_memory_t;
typedef camera_memory_t* (*camera_request_memory)(int fd, size_t buf_size, unsigned int num_bufs,
void *user);
typedef void (*camera_notify_callback)(int32_t msg_type,
int32_t ext1,
int32_t ext2,
void *user);
typedef void (*camera_data_callback)(int32_t msg_type,
const camera_memory_t *data, unsigned int index,
camera_frame_metadata_t *metadata, void *user);
typedef void (*camera_data_timestamp_callback)(int64_t timestamp,
int32_t msg_type,
const camera_memory_t *data, unsigned int index,
void *user);
#define HAL_CAMERA_PREVIEW_WINDOW_TAG 0xcafed00d
typedef struct preview_stream_ops {
int (*dequeue_buffer)(struct preview_stream_ops* w,
buffer_handle_t** buffer, int *stride);
int (*enqueue_buffer)(struct preview_stream_ops* w,
buffer_handle_t* buffer);
int (*cancel_buffer)(struct preview_stream_ops* w,
buffer_handle_t* buffer);
int (*set_buffer_count)(struct preview_stream_ops* w, int count);
int (*set_buffers_geometry)(struct preview_stream_ops* pw,
int w, int h, int format);
int (*set_crop)(struct preview_stream_ops *w,
int left, int top, int right, int bottom);
int (*set_usage)(struct preview_stream_ops* w, int usage);
int (*set_swap_interval)(struct preview_stream_ops *w, int interval);
int (*get_min_undequeued_buffer_count)(const struct preview_stream_ops *w,
int *count);
int (*lock_buffer)(struct preview_stream_ops* w,
buffer_handle_t* buffer);
// Timestamps are measured in nanoseconds, and must be comparable
// and monotonically increasing between two frames in the same
// preview stream. They do not need to be comparable between
// consecutive or parallel preview streams, cameras, or app runs.
int (*set_timestamp)(struct preview_stream_ops *w, int64_t timestamp);
} preview_stream_ops_t;
struct camera_device;
typedef struct camera_device_ops {
/** Set the ANativeWindow to which preview frames are sent */
int (*set_preview_window)(struct camera_device *,
struct preview_stream_ops *window);
/** Set the notification and data callbacks */
void (*set_callbacks)(struct camera_device *,
camera_notify_callback notify_cb,
camera_data_callback data_cb,
camera_data_timestamp_callback data_cb_timestamp,
camera_request_memory get_memory,
void *user);
/**
* The following three functions all take a msg_type, which is a bitmask of
* the messages defined in include/ui/Camera.h
*/
/**
* Enable a message, or set of messages.
*/
void (*enable_msg_type)(struct camera_device *, int32_t msg_type);
/**
* Disable a message, or a set of messages.
*
* Once received a call to disableMsgType(CAMERA_MSG_VIDEO_FRAME), camera
* HAL should not rely on its client to call releaseRecordingFrame() to
* release video recording frames sent out by the cameral HAL before and
* after the disableMsgType(CAMERA_MSG_VIDEO_FRAME) call. Camera HAL
* clients must not modify/access any video recording frame after calling
* disableMsgType(CAMERA_MSG_VIDEO_FRAME).
*/
void (*disable_msg_type)(struct camera_device *, int32_t msg_type);
/**
* Query whether a message, or a set of messages, is enabled. Note that
* this is operates as an AND, if any of the messages queried are off, this
* will return false.
*/
int (*msg_type_enabled)(struct camera_device *, int32_t msg_type);
/**
* Start preview mode.
*/
int (*start_preview)(struct camera_device *);
/**
* Stop a previously started preview.
*/
void (*stop_preview)(struct camera_device *);
/**
* Returns true if preview is enabled.
*/
int (*preview_enabled)(struct camera_device *);
/**
* Request the camera HAL to store meta data or real YUV data in the video
* buffers sent out via CAMERA_MSG_VIDEO_FRAME for a recording session. If
* it is not called, the default camera HAL behavior is to store real YUV
* data in the video buffers.
*
* This method should be called before startRecording() in order to be
* effective.
*
* If meta data is stored in the video buffers, it is up to the receiver of
* the video buffers to interpret the contents and to find the actual frame
* data with the help of the meta data in the buffer. How this is done is
* outside of the scope of this method.
*
* Some camera HALs may not support storing meta data in the video buffers,
* but all camera HALs should support storing real YUV data in the video
* buffers. If the camera HAL does not support storing the meta data in the
* video buffers when it is requested to do do, INVALID_OPERATION must be
* returned. It is very useful for the camera HAL to pass meta data rather
* than the actual frame data directly to the video encoder, since the
* amount of the uncompressed frame data can be very large if video size is
* large.
*
* @param enable if true to instruct the camera HAL to store
* meta data in the video buffers; false to instruct
* the camera HAL to store real YUV data in the video
* buffers.
*
* @return OK on success.
*/
int (*store_meta_data_in_buffers)(struct camera_device *, int enable);
/**
* Start record mode. When a record image is available, a
* CAMERA_MSG_VIDEO_FRAME message is sent with the corresponding
* frame. Every record frame must be released by a camera HAL client via
* releaseRecordingFrame() before the client calls
* disableMsgType(CAMERA_MSG_VIDEO_FRAME). After the client calls
* disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is the camera HAL's
* responsibility to manage the life-cycle of the video recording frames,
* and the client must not modify/access any video recording frames.
*/
int (*start_recording)(struct camera_device *);
/**
* Stop a previously started recording.
*/
void (*stop_recording)(struct camera_device *);
/**
* Returns true if recording is enabled.
*/
int (*recording_enabled)(struct camera_device *);
/**
* Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME.
*
* It is camera HAL client's responsibility to release video recording
* frames sent out by the camera HAL before the camera HAL receives a call
* to disableMsgType(CAMERA_MSG_VIDEO_FRAME). After it receives the call to
* disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is the camera HAL's
* responsibility to manage the life-cycle of the video recording frames.
*/
void (*release_recording_frame)(struct camera_device *,
const void *opaque);
/**
* Start auto focus, the notification callback routine is called with
* CAMERA_MSG_FOCUS once when focusing is complete. autoFocus() will be
* called again if another auto focus is needed.
*/
int (*auto_focus)(struct camera_device *);
/**
* Cancels auto-focus function. If the auto-focus is still in progress,
* this function will cancel it. Whether the auto-focus is in progress or
* not, this function will return the focus position to the default. If
* the camera does not support auto-focus, this is a no-op.
*/
int (*cancel_auto_focus)(struct camera_device *);
/**
* Take a picture.
*/
int (*take_picture)(struct camera_device *);
/**
* Cancel a picture that was started with takePicture. Calling this method
* when no picture is being taken is a no-op.
*/
int (*cancel_picture)(struct camera_device *);
/**
* Set the camera parameters. This returns BAD_VALUE if any parameter is
* invalid or not supported.
*/
int (*set_parameters)(struct camera_device *, const char *parms);
/** Retrieve the camera parameters. The buffer returned by the camera HAL
must be returned back to it with put_parameters, if put_parameters
is not NULL.
*/
char *(*get_parameters)(struct camera_device *);
/** The camera HAL uses its own memory to pass us the parameters when we
call get_parameters. Use this function to return the memory back to
the camera HAL, if put_parameters is not NULL. If put_parameters
is NULL, then you have to use free() to release the memory.
*/
void (*put_parameters)(struct camera_device *, char *);
/**
* Send command to camera driver.
*/
int (*send_command)(struct camera_device *,
int32_t cmd, int32_t arg1, int32_t arg2);
/**
* Release the hardware resources owned by this object. Note that this is
* *not* done in the destructor.
*/
void (*release)(struct camera_device *);
/**
* Dump state of the camera hardware
*/
int (*dump)(struct camera_device *, int fd);
} camera_device_ops_t;
typedef struct camera_device {
/**
* camera_device.common.version must be in the range
* HARDWARE_DEVICE_API_VERSION(0,0)-(1,FF). CAMERA_DEVICE_API_VERSION_1_0 is
* recommended.
*/
hw_device_t common;
camera_device_ops_t *ops;
void *priv;
} camera_device_t;
__END_DECLS
#endif /* #ifdef ANDROID_INCLUDE_CAMERA_H */
@@ -0,0 +1,839 @@
/*
* Copyright (C) 2012 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_CAMERA2_H
#define ANDROID_INCLUDE_CAMERA2_H
#include "camera_common.h"
#include "system/camera_metadata.h"
/**
* Camera device HAL 2.1 [ CAMERA_DEVICE_API_VERSION_2_0, CAMERA_DEVICE_API_VERSION_2_1 ]
*
* DEPRECATED. New devices should use Camera HAL v3.2 or newer.
*
* Supports the android.hardware.Camera API, and the android.hardware.camera2
* API in legacy mode only.
*
* Camera devices that support this version of the HAL must return
* CAMERA_DEVICE_API_VERSION_2_1 in camera_device_t.common.version and in
* camera_info_t.device_version (from camera_module_t.get_camera_info).
*
* Camera modules that may contain version 2.x devices must implement at least
* version 2.0 of the camera module interface (as defined by
* camera_module_t.common.module_api_version).
*
* See camera_common.h for more versioning details.
*
* Version history:
*
* 2.0: CAMERA_DEVICE_API_VERSION_2_0. Initial release (Android 4.2):
* - Sufficient for implementing existing android.hardware.Camera API.
* - Allows for ZSL queue in camera service layer
* - Not tested for any new features such manual capture control,
* Bayer RAW capture, reprocessing of RAW data.
*
* 2.1: CAMERA_DEVICE_API_VERSION_2_1. Support per-device static metadata:
* - Add get_instance_metadata() method to retrieve metadata that is fixed
* after device open, but may be variable between open() calls.
*/
__BEGIN_DECLS
struct camera2_device;
/**********************************************************************
*
* Input/output stream buffer queue interface definitions
*
*/
/**
* Output image stream queue interface. A set of these methods is provided to
* the HAL device in allocate_stream(), and are used to interact with the
* gralloc buffer queue for that stream. They may not be called until after
* allocate_stream returns.
*/
typedef struct camera2_stream_ops {
/**
* Get a buffer to fill from the queue. The size and format of the buffer
* are fixed for a given stream (defined in allocate_stream), and the stride
* should be queried from the platform gralloc module. The gralloc buffer
* will have been allocated based on the usage flags provided by
* allocate_stream, and will be locked for use.
*/
int (*dequeue_buffer)(const struct camera2_stream_ops* w,
buffer_handle_t** buffer);
/**
* Push a filled buffer to the stream to be used by the consumer.
*
* The timestamp represents the time at start of exposure of the first row
* of the image; it must be from a monotonic clock, and is measured in
* nanoseconds. The timestamps do not need to be comparable between
* different cameras, or consecutive instances of the same camera. However,
* they must be comparable between streams from the same camera. If one
* capture produces buffers for multiple streams, each stream must have the
* same timestamp for that buffer, and that timestamp must match the
* timestamp in the output frame metadata.
*/
int (*enqueue_buffer)(const struct camera2_stream_ops* w,
int64_t timestamp,
buffer_handle_t* buffer);
/**
* Return a buffer to the queue without marking it as filled.
*/
int (*cancel_buffer)(const struct camera2_stream_ops* w,
buffer_handle_t* buffer);
/**
* Set the crop window for subsequently enqueued buffers. The parameters are
* measured in pixels relative to the buffer width and height.
*/
int (*set_crop)(const struct camera2_stream_ops *w,
int left, int top, int right, int bottom);
} camera2_stream_ops_t;
/**
* Temporary definition during transition.
*
* These formats will be removed and replaced with
* HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED. To maximize forward compatibility,
* HAL implementations are strongly recommended to treat FORMAT_OPAQUE and
* FORMAT_ZSL as equivalent to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, and
* return HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED in the format_actual output
* parameter of allocate_stream, allowing the gralloc module to select the
* specific format based on the usage flags from the camera and the stream
* consumer.
*/
enum {
CAMERA2_HAL_PIXEL_FORMAT_OPAQUE = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
CAMERA2_HAL_PIXEL_FORMAT_ZSL = -1
};
/**
* Transport header for compressed JPEG buffers in output streams.
*
* To capture JPEG images, a stream is created using the pixel format
* HAL_PIXEL_FORMAT_BLOB, and the static metadata field android.jpeg.maxSize is
* used as the buffer size. Since compressed JPEG images are of variable size,
* the HAL needs to include the final size of the compressed image using this
* structure inside the output stream buffer. The JPEG blob ID field must be set
* to CAMERA2_JPEG_BLOB_ID.
*
* Transport header should be at the end of the JPEG output stream buffer. That
* means the jpeg_blob_id must start at byte[android.jpeg.maxSize -
* sizeof(camera2_jpeg_blob)]. Any HAL using this transport header must
* account for it in android.jpeg.maxSize. The JPEG data itself starts at
* byte[0] and should be jpeg_size bytes long.
*/
typedef struct camera2_jpeg_blob {
uint16_t jpeg_blob_id;
uint32_t jpeg_size;
};
enum {
CAMERA2_JPEG_BLOB_ID = 0x00FF
};
/**
* Input reprocess stream queue management. A set of these methods is provided
* to the HAL device in allocate_reprocess_stream(); they are used to interact
* with the reprocess stream's input gralloc buffer queue.
*/
typedef struct camera2_stream_in_ops {
/**
* Get the next buffer of image data to reprocess. The width, height, and
* format of the buffer is fixed in allocate_reprocess_stream(), and the
* stride and other details should be queried from the platform gralloc
* module as needed. The buffer will already be locked for use.
*/
int (*acquire_buffer)(const struct camera2_stream_in_ops *w,
buffer_handle_t** buffer);
/**
* Return a used buffer to the buffer queue for reuse.
*/
int (*release_buffer)(const struct camera2_stream_in_ops *w,
buffer_handle_t* buffer);
} camera2_stream_in_ops_t;
/**********************************************************************
*
* Metadata queue management, used for requests sent to HAL module, and for
* frames produced by the HAL.
*
*/
enum {
CAMERA2_REQUEST_QUEUE_IS_BOTTOMLESS = -1
};
/**
* Request input queue protocol:
*
* The framework holds the queue and its contents. At start, the queue is empty.
*
* 1. When the first metadata buffer is placed into the queue, the framework
* signals the device by calling notify_request_queue_not_empty().
*
* 2. After receiving notify_request_queue_not_empty, the device must call
* dequeue() once it's ready to handle the next buffer.
*
* 3. Once the device has processed a buffer, and is ready for the next buffer,
* it must call dequeue() again instead of waiting for a notification. If
* there are no more buffers available, dequeue() will return NULL. After
* this point, when a buffer becomes available, the framework must call
* notify_request_queue_not_empty() again. If the device receives a NULL
* return from dequeue, it does not need to query the queue again until a
* notify_request_queue_not_empty() call is received from the source.
*
* 4. If the device calls buffer_count() and receives 0, this does not mean that
* the framework will provide a notify_request_queue_not_empty() call. The
* framework will only provide such a notification after the device has
* received a NULL from dequeue, or on initial startup.
*
* 5. The dequeue() call in response to notify_request_queue_not_empty() may be
* on the same thread as the notify_request_queue_not_empty() call, and may
* be performed from within the notify call.
*
* 6. All dequeued request buffers must be returned to the framework by calling
* free_request, including when errors occur, a device flush is requested, or
* when the device is shutting down.
*/
typedef struct camera2_request_queue_src_ops {
/**
* Get the count of request buffers pending in the queue. May return
* CAMERA2_REQUEST_QUEUE_IS_BOTTOMLESS if a repeating request (stream
* request) is currently configured. Calling this method has no effect on
* whether the notify_request_queue_not_empty() method will be called by the
* framework.
*/
int (*request_count)(const struct camera2_request_queue_src_ops *q);
/**
* Get a metadata buffer from the framework. Returns OK if there is no
* error. If the queue is empty, returns NULL in buffer. In that case, the
* device must wait for a notify_request_queue_not_empty() message before
* attempting to dequeue again. Buffers obtained in this way must be
* returned to the framework with free_request().
*/
int (*dequeue_request)(const struct camera2_request_queue_src_ops *q,
camera_metadata_t **buffer);
/**
* Return a metadata buffer to the framework once it has been used, or if
* an error or shutdown occurs.
*/
int (*free_request)(const struct camera2_request_queue_src_ops *q,
camera_metadata_t *old_buffer);
} camera2_request_queue_src_ops_t;
/**
* Frame output queue protocol:
*
* The framework holds the queue and its contents. At start, the queue is empty.
*
* 1. When the device is ready to fill an output metadata frame, it must dequeue
* a metadata buffer of the required size.
*
* 2. It should then fill the metadata buffer, and place it on the frame queue
* using enqueue_frame. The framework takes ownership of the frame.
*
* 3. In case of an error, a request to flush the pipeline, or shutdown, the
* device must return any affected dequeued frames to the framework by
* calling cancel_frame.
*/
typedef struct camera2_frame_queue_dst_ops {
/**
* Get an empty metadata buffer to fill from the framework. The new metadata
* buffer will have room for entries number of metadata entries, plus
* data_bytes worth of extra storage. Frames dequeued here must be returned
* to the framework with either cancel_frame or enqueue_frame.
*/
int (*dequeue_frame)(const struct camera2_frame_queue_dst_ops *q,
size_t entries, size_t data_bytes,
camera_metadata_t **buffer);
/**
* Return a dequeued metadata buffer to the framework for reuse; do not mark it as
* filled. Use when encountering errors, or flushing the internal request queue.
*/
int (*cancel_frame)(const struct camera2_frame_queue_dst_ops *q,
camera_metadata_t *buffer);
/**
* Place a completed metadata frame on the frame output queue.
*/
int (*enqueue_frame)(const struct camera2_frame_queue_dst_ops *q,
camera_metadata_t *buffer);
} camera2_frame_queue_dst_ops_t;
/**********************************************************************
*
* Notification callback and message definition, and trigger definitions
*
*/
/**
* Asynchronous notification callback from the HAL, fired for various
* reasons. Only for information independent of frame capture, or that require
* specific timing. The user pointer must be the same one that was passed to the
* device in set_notify_callback().
*/
typedef void (*camera2_notify_callback)(int32_t msg_type,
int32_t ext1,
int32_t ext2,
int32_t ext3,
void *user);
/**
* Possible message types for camera2_notify_callback
*/
enum {
/**
* An error has occurred. Argument ext1 contains the error code, and
* ext2 and ext3 contain any error-specific information.
*/
CAMERA2_MSG_ERROR = 0x0001,
/**
* The exposure of a given request has begun. Argument ext1 contains the
* frame number, and ext2 and ext3 contain the low-order and high-order
* bytes of the timestamp for when exposure began.
* (timestamp = (ext3 << 32 | ext2))
*/
CAMERA2_MSG_SHUTTER = 0x0010,
/**
* The autofocus routine has changed state. Argument ext1 contains the new
* state; the values are the same as those for the metadata field
* android.control.afState. Ext2 contains the latest trigger ID passed to
* trigger_action(CAMERA2_TRIGGER_AUTOFOCUS) or
* trigger_action(CAMERA2_TRIGGER_CANCEL_AUTOFOCUS), or 0 if trigger has not
* been called with either of those actions.
*/
CAMERA2_MSG_AUTOFOCUS = 0x0020,
/**
* The autoexposure routine has changed state. Argument ext1 contains the
* new state; the values are the same as those for the metadata field
* android.control.aeState. Ext2 contains the latest trigger ID value passed to
* trigger_action(CAMERA2_TRIGGER_PRECAPTURE_METERING), or 0 if that method
* has not been called.
*/
CAMERA2_MSG_AUTOEXPOSURE = 0x0021,
/**
* The auto-whitebalance routine has changed state. Argument ext1 contains
* the new state; the values are the same as those for the metadata field
* android.control.awbState. Ext2 contains the latest trigger ID passed to
* trigger_action(CAMERA2_TRIGGER_PRECAPTURE_METERING), or 0 if that method
* has not been called.
*/
CAMERA2_MSG_AUTOWB = 0x0022
};
/**
* Error codes for CAMERA_MSG_ERROR
*/
enum {
/**
* A serious failure occured. Camera device may not work without reboot, and
* no further frames or buffer streams will be produced by the
* device. Device should be treated as closed.
*/
CAMERA2_MSG_ERROR_HARDWARE = 0x0001,
/**
* A serious failure occured. No further frames or buffer streams will be
* produced by the device. Device should be treated as closed. The client
* must reopen the device to use it again.
*/
CAMERA2_MSG_ERROR_DEVICE,
/**
* An error has occurred in processing a request. No output (metadata or
* buffers) will be produced for this request. ext2 contains the frame
* number of the request. Subsequent requests are unaffected, and the device
* remains operational.
*/
CAMERA2_MSG_ERROR_REQUEST,
/**
* An error has occurred in producing an output frame metadata buffer for a
* request, but image buffers for it will still be available. Subsequent
* requests are unaffected, and the device remains operational. ext2
* contains the frame number of the request.
*/
CAMERA2_MSG_ERROR_FRAME,
/**
* An error has occurred in placing an output buffer into a stream for a
* request. The frame metadata and other buffers may still be
* available. Subsequent requests are unaffected, and the device remains
* operational. ext2 contains the frame number of the request, and ext3
* contains the stream id.
*/
CAMERA2_MSG_ERROR_STREAM,
/**
* Number of error types
*/
CAMERA2_MSG_NUM_ERRORS
};
/**
* Possible trigger ids for trigger_action()
*/
enum {
/**
* Trigger an autofocus cycle. The effect of the trigger depends on the
* autofocus mode in effect when the trigger is received, which is the mode
* listed in the latest capture request to be dequeued by the HAL. If the
* mode is OFF, EDOF, or FIXED, the trigger has no effect. In AUTO, MACRO,
* or CONTINUOUS_* modes, see below for the expected behavior. The state of
* the autofocus cycle can be tracked in android.control.afMode and the
* corresponding notifications.
*
**
* In AUTO or MACRO mode, the AF state transitions (and notifications)
* when calling with trigger ID = N with the previous ID being K are:
*
* Initial state Transitions
* INACTIVE (K) -> ACTIVE_SCAN (N) -> AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
* AF_FOCUSED (K) -> ACTIVE_SCAN (N) -> AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
* AF_NOT_FOCUSED (K) -> ACTIVE_SCAN (N) -> AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
* ACTIVE_SCAN (K) -> AF_FOCUSED(N) or AF_NOT_FOCUSED(N)
* PASSIVE_SCAN (K) Not used in AUTO/MACRO mode
* PASSIVE_FOCUSED (K) Not used in AUTO/MACRO mode
*
**
* In CONTINUOUS_PICTURE mode, triggering AF must lock the AF to the current
* lens position and transition the AF state to either AF_FOCUSED or
* NOT_FOCUSED. If a passive scan is underway, that scan must complete and
* then lock the lens position and change AF state. TRIGGER_CANCEL_AUTOFOCUS
* will allow the AF to restart its operation.
*
* Initial state Transitions
* INACTIVE (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
* PASSIVE_FOCUSED (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
* PASSIVE_SCAN (K) -> AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
* AF_FOCUSED (K) no effect except to change next notification ID to N
* AF_NOT_FOCUSED (K) no effect except to change next notification ID to N
*
**
* In CONTINUOUS_VIDEO mode, triggering AF must lock the AF to the current
* lens position and transition the AF state to either AF_FOCUSED or
* NOT_FOCUSED. If a passive scan is underway, it must immediately halt, in
* contrast with CONTINUOUS_PICTURE mode. TRIGGER_CANCEL_AUTOFOCUS will
* allow the AF to restart its operation.
*
* Initial state Transitions
* INACTIVE (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
* PASSIVE_FOCUSED (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
* PASSIVE_SCAN (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
* AF_FOCUSED (K) no effect except to change next notification ID to N
* AF_NOT_FOCUSED (K) no effect except to change next notification ID to N
*
* Ext1 is an ID that must be returned in subsequent auto-focus state change
* notifications through camera2_notify_callback() and stored in
* android.control.afTriggerId.
*/
CAMERA2_TRIGGER_AUTOFOCUS = 0x0001,
/**
* Send a cancel message to the autofocus algorithm. The effect of the
* cancellation depends on the autofocus mode in effect when the trigger is
* received, which is the mode listed in the latest capture request to be
* dequeued by the HAL. If the AF mode is OFF or EDOF, the cancel has no
* effect. For other modes, the lens should return to its default position,
* any current autofocus scan must be canceled, and the AF state should be
* set to INACTIVE.
*
* The state of the autofocus cycle can be tracked in android.control.afMode
* and the corresponding notification. Continuous autofocus modes may resume
* focusing operations thereafter exactly as if the camera had just been set
* to a continuous AF mode.
*
* Ext1 is an ID that must be returned in subsequent auto-focus state change
* notifications through camera2_notify_callback() and stored in
* android.control.afTriggerId.
*/
CAMERA2_TRIGGER_CANCEL_AUTOFOCUS,
/**
* Trigger a pre-capture metering cycle, which may include firing the flash
* to determine proper capture parameters. Typically, this trigger would be
* fired for a half-depress of a camera shutter key, or before a snapshot
* capture in general. The state of the metering cycle can be tracked in
* android.control.aeMode and the corresponding notification. If the
* auto-exposure mode is OFF, the trigger does nothing.
*
* Ext1 is an ID that must be returned in subsequent
* auto-exposure/auto-white balance state change notifications through
* camera2_notify_callback() and stored in android.control.aePrecaptureId.
*/
CAMERA2_TRIGGER_PRECAPTURE_METERING
};
/**
* Possible template types for construct_default_request()
*/
enum {
/**
* Standard camera preview operation with 3A on auto.
*/
CAMERA2_TEMPLATE_PREVIEW = 1,
/**
* Standard camera high-quality still capture with 3A and flash on auto.
*/
CAMERA2_TEMPLATE_STILL_CAPTURE,
/**
* Standard video recording plus preview with 3A on auto, torch off.
*/
CAMERA2_TEMPLATE_VIDEO_RECORD,
/**
* High-quality still capture while recording video. Application will
* include preview, video record, and full-resolution YUV or JPEG streams in
* request. Must not cause stuttering on video stream. 3A on auto.
*/
CAMERA2_TEMPLATE_VIDEO_SNAPSHOT,
/**
* Zero-shutter-lag mode. Application will request preview and
* full-resolution data for each frame, and reprocess it to JPEG when a
* still image is requested by user. Settings should provide highest-quality
* full-resolution images without compromising preview frame rate. 3A on
* auto.
*/
CAMERA2_TEMPLATE_ZERO_SHUTTER_LAG,
/* Total number of templates */
CAMERA2_TEMPLATE_COUNT
};
/**********************************************************************
*
* Camera device operations
*
*/
typedef struct camera2_device_ops {
/**********************************************************************
* Request and frame queue setup and management methods
*/
/**
* Pass in input request queue interface methods.
*/
int (*set_request_queue_src_ops)(const struct camera2_device *,
const camera2_request_queue_src_ops_t *request_src_ops);
/**
* Notify device that the request queue is no longer empty. Must only be
* called when the first buffer is added a new queue, or after the source
* has returned NULL in response to a dequeue call.
*/
int (*notify_request_queue_not_empty)(const struct camera2_device *);
/**
* Pass in output frame queue interface methods
*/
int (*set_frame_queue_dst_ops)(const struct camera2_device *,
const camera2_frame_queue_dst_ops_t *frame_dst_ops);
/**
* Number of camera requests being processed by the device at the moment
* (captures/reprocesses that have had their request dequeued, but have not
* yet been enqueued onto output pipeline(s) ). No streams may be released
* by the framework until the in-progress count is 0.
*/
int (*get_in_progress_count)(const struct camera2_device *);
/**
* Flush all in-progress captures. This includes all dequeued requests
* (regular or reprocessing) that have not yet placed any outputs into a
* stream or the frame queue. Partially completed captures must be completed
* normally. No new requests may be dequeued from the request queue until
* the flush completes.
*/
int (*flush_captures_in_progress)(const struct camera2_device *);
/**
* Create a filled-in default request for standard camera use cases.
*
* The device must return a complete request that is configured to meet the
* requested use case, which must be one of the CAMERA2_TEMPLATE_*
* enums. All request control fields must be included, except for
* android.request.outputStreams.
*
* The metadata buffer returned must be allocated with
* allocate_camera_metadata. The framework takes ownership of the buffer.
*/
int (*construct_default_request)(const struct camera2_device *,
int request_template,
camera_metadata_t **request);
/**********************************************************************
* Stream management
*/
/**
* allocate_stream:
*
* Allocate a new output stream for use, defined by the output buffer width,
* height, target, and possibly the pixel format. Returns the new stream's
* ID, gralloc usage flags, minimum queue buffer count, and possibly the
* pixel format, on success. Error conditions:
*
* - Requesting a width/height/format combination not listed as
* supported by the sensor's static characteristics
*
* - Asking for too many streams of a given format type (2 bayer raw
* streams, for example).
*
* Input parameters:
*
* - width, height, format: Specification for the buffers to be sent through
* this stream. Format is a value from the HAL_PIXEL_FORMAT_* list. If
* HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED is used, then the platform
* gralloc module will select a format based on the usage flags provided
* by the camera HAL and the consumer of the stream. The camera HAL should
* inspect the buffers handed to it in the register_stream_buffers call to
* obtain the implementation-specific format if necessary.
*
* - stream_ops: A structure of function pointers for obtaining and queuing
* up buffers for this stream. The underlying stream will be configured
* based on the usage and max_buffers outputs. The methods in this
* structure may not be called until after allocate_stream returns.
*
* Output parameters:
*
* - stream_id: An unsigned integer identifying this stream. This value is
* used in incoming requests to identify the stream, and in releasing the
* stream.
*
* - usage: The gralloc usage mask needed by the HAL device for producing
* the requested type of data. This is used in allocating new gralloc
* buffers for the stream buffer queue.
*
* - max_buffers: The maximum number of buffers the HAL device may need to
* have dequeued at the same time. The device may not dequeue more buffers
* than this value at the same time.
*
*/
int (*allocate_stream)(
const struct camera2_device *,
// inputs
uint32_t width,
uint32_t height,
int format,
const camera2_stream_ops_t *stream_ops,
// outputs
uint32_t *stream_id,
uint32_t *format_actual, // IGNORED, will be removed
uint32_t *usage,
uint32_t *max_buffers);
/**
* Register buffers for a given stream. This is called after a successful
* allocate_stream call, and before the first request referencing the stream
* is enqueued. This method is intended to allow the HAL device to map or
* otherwise prepare the buffers for later use. num_buffers is guaranteed to
* be at least max_buffers (from allocate_stream), but may be larger. The
* buffers will already be locked for use. At the end of the call, all the
* buffers must be ready to be returned to the queue. If the stream format
* was set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, the camera HAL should
* inspect the passed-in buffers here to determine any platform-private
* pixel format information.
*/
int (*register_stream_buffers)(
const struct camera2_device *,
uint32_t stream_id,
int num_buffers,
buffer_handle_t *buffers);
/**
* Release a stream. Returns an error if called when get_in_progress_count
* is non-zero, or if the stream id is invalid.
*/
int (*release_stream)(
const struct camera2_device *,
uint32_t stream_id);
/**
* allocate_reprocess_stream:
*
* Allocate a new input stream for use, defined by the output buffer width,
* height, and the pixel format. Returns the new stream's ID, gralloc usage
* flags, and required simultaneously acquirable buffer count, on
* success. Error conditions:
*
* - Requesting a width/height/format combination not listed as
* supported by the sensor's static characteristics
*
* - Asking for too many reprocessing streams to be configured at once.
*
* Input parameters:
*
* - width, height, format: Specification for the buffers to be sent through
* this stream. Format must be a value from the HAL_PIXEL_FORMAT_* list.
*
* - reprocess_stream_ops: A structure of function pointers for acquiring
* and releasing buffers for this stream. The underlying stream will be
* configured based on the usage and max_buffers outputs.
*
* Output parameters:
*
* - stream_id: An unsigned integer identifying this stream. This value is
* used in incoming requests to identify the stream, and in releasing the
* stream. These ids are numbered separately from the input stream ids.
*
* - consumer_usage: The gralloc usage mask needed by the HAL device for
* consuming the requested type of data. This is used in allocating new
* gralloc buffers for the stream buffer queue.
*
* - max_buffers: The maximum number of buffers the HAL device may need to
* have acquired at the same time. The device may not have more buffers
* acquired at the same time than this value.
*
*/
int (*allocate_reprocess_stream)(const struct camera2_device *,
uint32_t width,
uint32_t height,
uint32_t format,
const camera2_stream_in_ops_t *reprocess_stream_ops,
// outputs
uint32_t *stream_id,
uint32_t *consumer_usage,
uint32_t *max_buffers);
/**
* allocate_reprocess_stream_from_stream:
*
* Allocate a new input stream for use, which will use the buffers allocated
* for an existing output stream. That is, after the HAL enqueues a buffer
* onto the output stream, it may see that same buffer handed to it from
* this input reprocessing stream. After the HAL releases the buffer back to
* the reprocessing stream, it will be returned to the output queue for
* reuse.
*
* Error conditions:
*
* - Using an output stream of unsuitable size/format for the basis of the
* reprocessing stream.
*
* - Attempting to allocatee too many reprocessing streams at once.
*
* Input parameters:
*
* - output_stream_id: The ID of an existing output stream which has
* a size and format suitable for reprocessing.
*
* - reprocess_stream_ops: A structure of function pointers for acquiring
* and releasing buffers for this stream. The underlying stream will use
* the same graphics buffer handles as the output stream uses.
*
* Output parameters:
*
* - stream_id: An unsigned integer identifying this stream. This value is
* used in incoming requests to identify the stream, and in releasing the
* stream. These ids are numbered separately from the input stream ids.
*
* The HAL client must always release the reprocessing stream before it
* releases the output stream it is based on.
*
*/
int (*allocate_reprocess_stream_from_stream)(const struct camera2_device *,
uint32_t output_stream_id,
const camera2_stream_in_ops_t *reprocess_stream_ops,
// outputs
uint32_t *stream_id);
/**
* Release a reprocessing stream. Returns an error if called when
* get_in_progress_count is non-zero, or if the stream id is not
* valid.
*/
int (*release_reprocess_stream)(
const struct camera2_device *,
uint32_t stream_id);
/**********************************************************************
* Miscellaneous methods
*/
/**
* Trigger asynchronous activity. This is used for triggering special
* behaviors of the camera 3A routines when they are in use. See the
* documentation for CAMERA2_TRIGGER_* above for details of the trigger ids
* and their arguments.
*/
int (*trigger_action)(const struct camera2_device *,
uint32_t trigger_id,
int32_t ext1,
int32_t ext2);
/**
* Notification callback setup
*/
int (*set_notify_callback)(const struct camera2_device *,
camera2_notify_callback notify_cb,
void *user);
/**
* Get methods to query for vendor extension metadata tag infomation. May
* set ops to NULL if no vendor extension tags are defined.
*/
int (*get_metadata_vendor_tag_ops)(const struct camera2_device*,
vendor_tag_query_ops_t **ops);
/**
* Dump state of the camera hardware
*/
int (*dump)(const struct camera2_device *, int fd);
/**
* Get device-instance-specific metadata. This metadata must be constant for
* a single instance of the camera device, but may be different between
* open() calls. The returned camera_metadata pointer must be valid until
* the device close() method is called.
*
* Version information:
*
* CAMERA_DEVICE_API_VERSION_2_0:
*
* Not available. Framework may not access this function pointer.
*
* CAMERA_DEVICE_API_VERSION_2_1:
*
* Valid. Can be called by the framework.
*
*/
int (*get_instance_metadata)(const struct camera2_device *,
camera_metadata **instance_metadata);
} camera2_device_ops_t;
/**********************************************************************
*
* Camera device definition
*
*/
typedef struct camera2_device {
/**
* common.version must equal CAMERA_DEVICE_API_VERSION_2_0 to identify
* this device as implementing version 2.0 of the camera device HAL.
*/
hw_device_t common;
camera2_device_ops_t *ops;
void *priv;
} camera2_device_t;
__END_DECLS
#endif /* #ifdef ANDROID_INCLUDE_CAMERA2_H */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,916 @@
/*
* Copyright (C) 2012 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.
*/
// FIXME: add well-defined names for cameras
#ifndef ANDROID_INCLUDE_CAMERA_COMMON_H
#define ANDROID_INCLUDE_CAMERA_COMMON_H
#include <stdint.h>
#include <stdbool.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <cutils/native_handle.h>
#include <system/camera.h>
#include <system/camera_vendor_tags.h>
#include <hardware/hardware.h>
#include <hardware/gralloc.h>
__BEGIN_DECLS
/**
* The id of this module
*/
#define CAMERA_HARDWARE_MODULE_ID "camera"
/**
* Module versioning information for the Camera hardware module, based on
* camera_module_t.common.module_api_version. The two most significant hex
* digits represent the major version, and the two least significant represent
* the minor version.
*
*******************************************************************************
* Versions: 0.X - 1.X [CAMERA_MODULE_API_VERSION_1_0]
*
* Camera modules that report these version numbers implement the initial
* camera module HAL interface. All camera devices openable through this
* module support only version 1 of the camera device HAL. The device_version
* and static_camera_characteristics fields of camera_info are not valid. Only
* the android.hardware.Camera API can be supported by this module and its
* devices.
*
*******************************************************************************
* Version: 2.0 [CAMERA_MODULE_API_VERSION_2_0]
*
* Camera modules that report this version number implement the second version
* of the camera module HAL interface. Camera devices openable through this
* module may support either version 1.0 or version 2.0 of the camera device
* HAL interface. The device_version field of camera_info is always valid; the
* static_camera_characteristics field of camera_info is valid if the
* device_version field is 2.0 or higher.
*
*******************************************************************************
* Version: 2.1 [CAMERA_MODULE_API_VERSION_2_1]
*
* This camera module version adds support for asynchronous callbacks to the
* framework from the camera HAL module, which is used to notify the framework
* about changes to the camera module state. Modules that provide a valid
* set_callbacks() method must report at least this version number.
*
*******************************************************************************
* Version: 2.2 [CAMERA_MODULE_API_VERSION_2_2]
*
* This camera module version adds vendor tag support from the module, and
* deprecates the old vendor_tag_query_ops that were previously only
* accessible with a device open.
*
*******************************************************************************
* Version: 2.3 [CAMERA_MODULE_API_VERSION_2_3]
*
* This camera module version adds open legacy camera HAL device support.
* Framework can use it to open the camera device as lower device HAL version
* HAL device if the same device can support multiple device API versions.
* The standard hardware module open call (common.methods->open) continues
* to open the camera device with the latest supported version, which is
* also the version listed in camera_info_t.device_version.
*
*******************************************************************************
* Version: 2.4 [CAMERA_MODULE_API_VERSION_2_4]
*
* This camera module version adds below API changes:
*
* 1. Torch mode support. The framework can use it to turn on torch mode for
* any camera device that has a flash unit, without opening a camera device. The
* camera device has a higher priority accessing the flash unit than the camera
* module; opening a camera device will turn off the torch if it had been enabled
* through the module interface. When there are any resource conflicts, such as
* open() is called to open a camera device, the camera HAL module must notify the
* framework through the torch mode status callback that the torch mode has been
* turned off.
*
* 2. External camera (e.g. USB hot-plug camera) support. The API updates specify that
* the camera static info is only available when camera is connected and ready to
* use for external hot-plug cameras. Calls to get static info will be invalid
* calls when camera status is not CAMERA_DEVICE_STATUS_PRESENT. The frameworks
* will only count on device status change callbacks to manage the available external
* camera list.
*
* 3. Camera arbitration hints. This module version adds support for explicitly
* indicating the number of camera devices that can be simultaneously opened and used.
* To specify valid combinations of devices, the resource_cost and conflicting_devices
* fields should always be set in the camera_info structure returned by the
* get_camera_info call.
*
* 4. Module initialization method. This will be called by the camera service
* right after the HAL module is loaded, to allow for one-time initialization
* of the HAL. It is called before any other module methods are invoked.
*/
/**
* Predefined macros for currently-defined version numbers
*/
/**
* All module versions <= HARDWARE_MODULE_API_VERSION(1, 0xFF) must be treated
* as CAMERA_MODULE_API_VERSION_1_0
*/
#define CAMERA_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
#define CAMERA_MODULE_API_VERSION_2_0 HARDWARE_MODULE_API_VERSION(2, 0)
#define CAMERA_MODULE_API_VERSION_2_1 HARDWARE_MODULE_API_VERSION(2, 1)
#define CAMERA_MODULE_API_VERSION_2_2 HARDWARE_MODULE_API_VERSION(2, 2)
#define CAMERA_MODULE_API_VERSION_2_3 HARDWARE_MODULE_API_VERSION(2, 3)
#define CAMERA_MODULE_API_VERSION_2_4 HARDWARE_MODULE_API_VERSION(2, 4)
#define CAMERA_MODULE_API_VERSION_CURRENT CAMERA_MODULE_API_VERSION_2_4
/**
* All device versions <= HARDWARE_DEVICE_API_VERSION(1, 0xFF) must be treated
* as CAMERA_DEVICE_API_VERSION_1_0
*/
#define CAMERA_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
#define CAMERA_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0)
#define CAMERA_DEVICE_API_VERSION_2_1 HARDWARE_DEVICE_API_VERSION(2, 1)
#define CAMERA_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0)
#define CAMERA_DEVICE_API_VERSION_3_1 HARDWARE_DEVICE_API_VERSION(3, 1)
#define CAMERA_DEVICE_API_VERSION_3_2 HARDWARE_DEVICE_API_VERSION(3, 2)
#define CAMERA_DEVICE_API_VERSION_3_3 HARDWARE_DEVICE_API_VERSION(3, 3)
// Device version 3.3 is current, older HAL camera device versions are not
// recommended for new devices.
#define CAMERA_DEVICE_API_VERSION_CURRENT CAMERA_DEVICE_API_VERSION_3_3
/**
* Defined in /system/media/camera/include/system/camera_metadata.h
*/
typedef struct camera_metadata camera_metadata_t;
typedef struct camera_info {
/**
* The direction that the camera faces to. See system/core/include/system/camera.h
* for camera facing definitions.
*
* Version information (based on camera_module_t.common.module_api_version):
*
* CAMERA_MODULE_API_VERSION_2_3 or lower:
*
* It should be CAMERA_FACING_BACK or CAMERA_FACING_FRONT.
*
* CAMERA_MODULE_API_VERSION_2_4 or higher:
*
* It should be CAMERA_FACING_BACK, CAMERA_FACING_FRONT or
* CAMERA_FACING_EXTERNAL.
*/
int facing;
/**
* The orientation of the camera image. The value is the angle that the
* camera image needs to be rotated clockwise so it shows correctly on the
* display in its natural orientation. It should be 0, 90, 180, or 270.
*
* For example, suppose a device has a naturally tall screen. The
* back-facing camera sensor is mounted in landscape. You are looking at the
* screen. If the top side of the camera sensor is aligned with the right
* edge of the screen in natural orientation, the value should be 90. If the
* top side of a front-facing camera sensor is aligned with the right of the
* screen, the value should be 270.
*
* Version information (based on camera_module_t.common.module_api_version):
*
* CAMERA_MODULE_API_VERSION_2_3 or lower:
*
* Valid in all camera_module versions.
*
* CAMERA_MODULE_API_VERSION_2_4 or higher:
*
* Valid if camera facing is CAMERA_FACING_BACK or CAMERA_FACING_FRONT,
* not valid if camera facing is CAMERA_FACING_EXTERNAL.
*/
int orientation;
/**
* The value of camera_device_t.common.version.
*
* Version information (based on camera_module_t.common.module_api_version):
*
* CAMERA_MODULE_API_VERSION_1_0:
*
* Not valid. Can be assumed to be CAMERA_DEVICE_API_VERSION_1_0. Do
* not read this field.
*
* CAMERA_MODULE_API_VERSION_2_0 or higher:
*
* Always valid
*
*/
uint32_t device_version;
/**
* The camera's fixed characteristics, which include all static camera metadata
* specified in system/media/camera/docs/docs.html. This should be a sorted metadata
* buffer, and may not be modified or freed by the caller. The pointer should remain
* valid for the lifetime of the camera module, and values in it may not
* change after it is returned by get_camera_info().
*
* Version information (based on camera_module_t.common.module_api_version):
*
* CAMERA_MODULE_API_VERSION_1_0:
*
* Not valid. Extra characteristics are not available. Do not read this
* field.
*
* CAMERA_MODULE_API_VERSION_2_0 or higher:
*
* Valid if device_version >= CAMERA_DEVICE_API_VERSION_2_0. Do not read
* otherwise.
*
*/
const camera_metadata_t *static_camera_characteristics;
/**
* The total resource "cost" of using this camera, represented as an integer
* value in the range [0, 100] where 100 represents total usage of the shared
* resource that is the limiting bottleneck of the camera subsystem. This may
* be a very rough estimate, and is used as a hint to the camera service to
* determine when to disallow multiple applications from simultaneously
* opening different cameras advertised by the camera service.
*
* The camera service must be able to simultaneously open and use any
* combination of camera devices exposed by the HAL where the sum of
* the resource costs of these cameras is <= 100. For determining cost,
* each camera device must be assumed to be configured and operating at
* the maximally resource-consuming framerate and stream size settings
* available in the configuration settings exposed for that device through
* the camera metadata.
*
* The camera service may still attempt to simultaneously open combinations
* of camera devices with a total resource cost > 100. This may succeed or
* fail. If this succeeds, combinations of configurations that are not
* supported due to resource constraints from having multiple open devices
* should fail during the configure calls. If the total resource cost is
* <= 100, open and configure should never fail for any stream configuration
* settings or other device capabilities that would normally succeed for a
* device when it is the only open camera device.
*
* This field will be used to determine whether background applications are
* allowed to use this camera device while other applications are using other
* camera devices. Note: multiple applications will never be allowed by the
* camera service to simultaneously open the same camera device.
*
* Example use cases:
*
* Ex. 1: Camera Device 0 = Back Camera
* Camera Device 1 = Front Camera
* - Using both camera devices causes a large framerate slowdown due to
* limited ISP bandwidth.
*
* Configuration:
*
* Camera Device 0 - resource_cost = 51
* conflicting_devices = null
* Camera Device 1 - resource_cost = 51
* conflicting_devices = null
*
* Result:
*
* Since the sum of the resource costs is > 100, if a higher-priority
* application has either device open, no lower-priority applications will be
* allowed by the camera service to open either device. If a lower-priority
* application is using a device that a higher-priority subsequently attempts
* to open, the lower-priority application will be forced to disconnect the
* the device.
*
* If the highest-priority application chooses, it may still attempt to open
* both devices (since these devices are not listed as conflicting in the
* conflicting_devices fields), but usage of these devices may fail in the
* open or configure calls.
*
* Ex. 2: Camera Device 0 = Left Back Camera
* Camera Device 1 = Right Back Camera
* Camera Device 2 = Combined stereo camera using both right and left
* back camera sensors used by devices 0, and 1
* Camera Device 3 = Front Camera
* - Due to do hardware constraints, up to two cameras may be open at once. The
* combined stereo camera may never be used at the same time as either of the
* two back camera devices (device 0, 1), and typically requires too much
* bandwidth to use at the same time as the front camera (device 3).
*
* Configuration:
*
* Camera Device 0 - resource_cost = 50
* conflicting_devices = { 2 }
* Camera Device 1 - resource_cost = 50
* conflicting_devices = { 2 }
* Camera Device 2 - resource_cost = 100
* conflicting_devices = { 0, 1 }
* Camera Device 3 - resource_cost = 50
* conflicting_devices = null
*
* Result:
*
* Based on the conflicting_devices fields, the camera service guarantees that
* the following sets of open devices will never be allowed: { 1, 2 }, { 0, 2 }.
*
* Based on the resource_cost fields, if a high-priority foreground application
* is using camera device 0, a background application would be allowed to open
* camera device 1 or 3 (but would be forced to disconnect it again if the
* foreground application opened another device).
*
* The highest priority application may still attempt to simultaneously open
* devices 0, 2, and 3, but the HAL may fail in open or configure calls for
* this combination.
*
* Ex. 3: Camera Device 0 = Back Camera
* Camera Device 1 = Front Camera
* Camera Device 2 = Low-power Front Camera that uses the same
* sensor as device 1, but only exposes image stream
* resolutions that can be used in low-power mode
* - Using both front cameras (device 1, 2) at the same time is impossible due
* a shared physical sensor. Using the back and "high-power" front camera
* (device 1) may be impossible for some stream configurations due to hardware
* limitations, but the "low-power" front camera option may always be used as
* it has special dedicated hardware.
*
* Configuration:
*
* Camera Device 0 - resource_cost = 100
* conflicting_devices = null
* Camera Device 1 - resource_cost = 100
* conflicting_devices = { 2 }
* Camera Device 2 - resource_cost = 0
* conflicting_devices = { 1 }
* Result:
*
* Based on the conflicting_devices fields, the camera service guarantees that
* the following sets of open devices will never be allowed: { 1, 2 }.
*
* Based on the resource_cost fields, only the highest priority application
* may attempt to open both device 0 and 1 at the same time. If a higher-priority
* application is not using device 1 or 2, a low-priority background application
* may open device 2 (but will be forced to disconnect it if a higher-priority
* application subsequently opens device 1 or 2).
*
* Version information (based on camera_module_t.common.module_api_version):
*
* CAMERA_MODULE_API_VERSION_2_3 or lower:
*
* Not valid. Can be assumed to be 100. Do not read this field.
*
* CAMERA_MODULE_API_VERSION_2_4 or higher:
*
* Always valid.
*/
int resource_cost;
/**
* An array of camera device IDs represented as NULL-terminated strings
* indicating other devices that cannot be simultaneously opened while this
* camera device is in use.
*
* This field is intended to be used to indicate that this camera device
* is a composite of several other camera devices, or otherwise has
* hardware dependencies that prohibit simultaneous usage. If there are no
* dependencies, a NULL may be returned in this field to indicate this.
*
* The camera service will never simultaneously open any of the devices
* in this list while this camera device is open.
*
* The strings pointed to in this field will not be cleaned up by the camera
* service, and must remain while this device is plugged in.
*
* Version information (based on camera_module_t.common.module_api_version):
*
* CAMERA_MODULE_API_VERSION_2_3 or lower:
*
* Not valid. Can be assumed to be NULL. Do not read this field.
*
* CAMERA_MODULE_API_VERSION_2_4 or higher:
*
* Always valid.
*/
char** conflicting_devices;
/**
* The length of the array given in the conflicting_devices field.
*
* Version information (based on camera_module_t.common.module_api_version):
*
* CAMERA_MODULE_API_VERSION_2_3 or lower:
*
* Not valid. Can be assumed to be 0. Do not read this field.
*
* CAMERA_MODULE_API_VERSION_2_4 or higher:
*
* Always valid.
*/
size_t conflicting_devices_length;
} camera_info_t;
/**
* camera_device_status_t:
*
* The current status of the camera device, as provided by the HAL through the
* camera_module_callbacks.camera_device_status_change() call.
*
* At module load time, the framework will assume all camera devices are in the
* CAMERA_DEVICE_STATUS_PRESENT state. The HAL should invoke
* camera_module_callbacks::camera_device_status_change to inform the framework
* of any initially NOT_PRESENT devices.
*
* Allowed transitions:
* PRESENT -> NOT_PRESENT
* NOT_PRESENT -> ENUMERATING
* NOT_PRESENT -> PRESENT
* ENUMERATING -> PRESENT
* ENUMERATING -> NOT_PRESENT
*/
typedef enum camera_device_status {
/**
* The camera device is not currently connected, and opening it will return
* failure.
*
* Version information (based on camera_module_t.common.module_api_version):
*
* CAMERA_MODULE_API_VERSION_2_3 or lower:
*
* Calls to get_camera_info must still succeed, and provide the same information
* it would if the camera were connected.
*
* CAMERA_MODULE_API_VERSION_2_4:
*
* The camera device at this status must return -EINVAL for get_camera_info call,
* as the device is not connected.
*/
CAMERA_DEVICE_STATUS_NOT_PRESENT = 0,
/**
* The camera device is connected, and opening it will succeed.
*
* CAMERA_MODULE_API_VERSION_2_3 or lower:
*
* The information returned by get_camera_info cannot change due to this status
* change. By default, the framework will assume all devices are in this state.
*
* CAMERA_MODULE_API_VERSION_2_4:
*
* The information returned by get_camera_info will become valid after a device's
* status changes to this. By default, the framework will assume all devices are in
* this state.
*/
CAMERA_DEVICE_STATUS_PRESENT = 1,
/**
* The camera device is connected, but it is undergoing an enumeration and
* so opening the device will return -EBUSY.
*
* CAMERA_MODULE_API_VERSION_2_3 or lower:
*
* Calls to get_camera_info must still succeed, as if the camera was in the
* PRESENT status.
*
* CAMERA_MODULE_API_VERSION_2_4:
*
* The camera device at this status must return -EINVAL for get_camera_info for call,
* as the device is not ready.
*/
CAMERA_DEVICE_STATUS_ENUMERATING = 2,
} camera_device_status_t;
/**
* torch_mode_status_t:
*
* The current status of the torch mode, as provided by the HAL through the
* camera_module_callbacks.torch_mode_status_change() call.
*
* The torch mode status of a camera device is applicable only when the camera
* device is present. The framework will not call set_torch_mode() to turn on
* torch mode of a camera device if the camera device is not present. At module
* load time, the framework will assume torch modes are in the
* TORCH_MODE_STATUS_AVAILABLE_OFF state if the camera device is present and
* android.flash.info.available is reported as true via get_camera_info() call.
*
* The behaviors of the camera HAL module that the framework expects in the
* following situations when a camera device's status changes:
* 1. A previously-disconnected camera device becomes connected.
* After camera_module_callbacks::camera_device_status_change() is invoked
* to inform the framework that the camera device is present, the framework
* will assume the camera device's torch mode is in
* TORCH_MODE_STATUS_AVAILABLE_OFF state. The camera HAL module does not need
* to invoke camera_module_callbacks::torch_mode_status_change() unless the
* flash unit is unavailable to use by set_torch_mode().
*
* 2. A previously-connected camera becomes disconnected.
* After camera_module_callbacks::camera_device_status_change() is invoked
* to inform the framework that the camera device is not present, the
* framework will not call set_torch_mode() for the disconnected camera
* device until its flash unit becomes available again. The camera HAL
* module does not need to invoke
* camera_module_callbacks::torch_mode_status_change() separately to inform
* that the flash unit has become unavailable.
*
* 3. open() is called to open a camera device.
* The camera HAL module must invoke
* camera_module_callbacks::torch_mode_status_change() for all flash units
* that have entered TORCH_MODE_STATUS_NOT_AVAILABLE state and can not be
* turned on by calling set_torch_mode() anymore due to this open() call.
* open() must not trigger TORCH_MODE_STATUS_AVAILABLE_OFF before
* TORCH_MODE_STATUS_NOT_AVAILABLE for all flash units that have become
* unavailable.
*
* 4. close() is called to close a camera device.
* The camera HAL module must invoke
* camera_module_callbacks::torch_mode_status_change() for all flash units
* that have entered TORCH_MODE_STATUS_AVAILABLE_OFF state and can be turned
* on by calling set_torch_mode() again because of enough resources freed
* up by this close() call.
*
* Note that the framework calling set_torch_mode() successfully must trigger
* TORCH_MODE_STATUS_AVAILABLE_OFF or TORCH_MODE_STATUS_AVAILABLE_ON callback
* for the given camera device. Additionally it must trigger
* TORCH_MODE_STATUS_AVAILABLE_OFF callbacks for other previously-on torch
* modes if HAL cannot keep multiple torch modes on simultaneously.
*/
typedef enum torch_mode_status {
/**
* The flash unit is no longer available and the torch mode can not be
* turned on by calling set_torch_mode(). If the torch mode is on, it
* will be turned off by HAL before HAL calls torch_mode_status_change().
*/
TORCH_MODE_STATUS_NOT_AVAILABLE = 0,
/**
* A torch mode has become off and available to be turned on via
* set_torch_mode(). This may happen in the following
* cases:
* 1. After the resources to turn on the torch mode have become available.
* 2. After set_torch_mode() is called to turn off the torch mode.
* 3. After the framework turned on the torch mode of some other camera
* device and HAL had to turn off the torch modes of any camera devices
* that were previously on.
*/
TORCH_MODE_STATUS_AVAILABLE_OFF = 1,
/**
* A torch mode has become on and available to be turned off via
* set_torch_mode(). This can happen only after set_torch_mode() is called
* to turn on the torch mode.
*/
TORCH_MODE_STATUS_AVAILABLE_ON = 2,
} torch_mode_status_t;
/**
* Callback functions for the camera HAL module to use to inform the framework
* of changes to the camera subsystem.
*
* Version information (based on camera_module_t.common.module_api_version):
*
* Each callback is called only by HAL modules implementing the indicated
* version or higher of the HAL module API interface.
*
* CAMERA_MODULE_API_VERSION_2_1:
* camera_device_status_change()
*
* CAMERA_MODULE_API_VERSION_2_4:
* torch_mode_status_change()
*/
typedef struct camera_module_callbacks {
/**
* camera_device_status_change:
*
* Callback to the framework to indicate that the state of a specific camera
* device has changed. At module load time, the framework will assume all
* camera devices are in the CAMERA_DEVICE_STATUS_PRESENT state. The HAL
* must call this method to inform the framework of any initially
* NOT_PRESENT devices.
*
* This callback is added for CAMERA_MODULE_API_VERSION_2_1.
*
* camera_module_callbacks: The instance of camera_module_callbacks_t passed
* to the module with set_callbacks.
*
* camera_id: The ID of the camera device that has a new status.
*
* new_status: The new status code, one of the camera_device_status_t enums,
* or a platform-specific status.
*
*/
void (*camera_device_status_change)(const struct camera_module_callbacks*,
int camera_id,
int new_status);
/**
* torch_mode_status_change:
*
* Callback to the framework to indicate that the state of the torch mode
* of the flash unit associated with a specific camera device has changed.
* At module load time, the framework will assume the torch modes are in
* the TORCH_MODE_STATUS_AVAILABLE_OFF state if android.flash.info.available
* is reported as true via get_camera_info() call.
*
* This callback is added for CAMERA_MODULE_API_VERSION_2_4.
*
* camera_module_callbacks: The instance of camera_module_callbacks_t
* passed to the module with set_callbacks.
*
* camera_id: The ID of camera device whose flash unit has a new torch mode
* status.
*
* new_status: The new status code, one of the torch_mode_status_t enums.
*/
void (*torch_mode_status_change)(const struct camera_module_callbacks*,
const char* camera_id,
int new_status);
} camera_module_callbacks_t;
typedef struct camera_module {
/**
* Common methods of the camera module. This *must* be the first member of
* camera_module as users of this structure will cast a hw_module_t to
* camera_module pointer in contexts where it's known the hw_module_t
* references a camera_module.
*
* The return values for common.methods->open for camera_module are:
*
* 0: On a successful open of the camera device.
*
* -ENODEV: The camera device cannot be opened due to an internal
* error.
*
* -EINVAL: The input arguments are invalid, i.e. the id is invalid,
* and/or the module is invalid.
*
* -EBUSY: The camera device was already opened for this camera id
* (by using this method or open_legacy),
* regardless of the device HAL version it was opened as.
*
* -EUSERS: The maximal number of camera devices that can be
* opened concurrently were opened already, either by
* this method or the open_legacy method.
*
* All other return values from common.methods->open will be treated as
* -ENODEV.
*/
hw_module_t common;
/**
* get_number_of_cameras:
*
* Returns the number of camera devices accessible through the camera
* module. The camera devices are numbered 0 through N-1, where N is the
* value returned by this call. The name of the camera device for open() is
* simply the number converted to a string. That is, "0" for camera ID 0,
* "1" for camera ID 1.
*
* Version information (based on camera_module_t.common.module_api_version):
*
* CAMERA_MODULE_API_VERSION_2_3 or lower:
*
* The value here must be static, and cannot change after the first call
* to this method.
*
* CAMERA_MODULE_API_VERSION_2_4 or higher:
*
* The value here must be static, and must count only built-in cameras,
* which have CAMERA_FACING_BACK or CAMERA_FACING_FRONT camera facing values
* (camera_info.facing). The HAL must not include the external cameras
* (camera_info.facing == CAMERA_FACING_EXTERNAL) into the return value
* of this call. Frameworks will use camera_device_status_change callback
* to manage number of external cameras.
*/
int (*get_number_of_cameras)(void);
/**
* get_camera_info:
*
* Return the static camera information for a given camera device. This
* information may not change for a camera device.
*
* Return values:
*
* 0: On a successful operation
*
* -ENODEV: The information cannot be provided due to an internal
* error.
*
* -EINVAL: The input arguments are invalid, i.e. the id is invalid,
* and/or the module is invalid.
*
* Version information (based on camera_module_t.common.module_api_version):
*
* CAMERA_MODULE_API_VERSION_2_4 or higher:
*
* When a camera is disconnected, its camera id becomes invalid. Calling this
* this method with this invalid camera id will get -EINVAL and NULL camera
* static metadata (camera_info.static_camera_characteristics).
*/
int (*get_camera_info)(int camera_id, struct camera_info *info);
/**
* set_callbacks:
*
* Provide callback function pointers to the HAL module to inform framework
* of asynchronous camera module events. The framework will call this
* function once after initial camera HAL module load, after the
* get_number_of_cameras() method is called for the first time, and before
* any other calls to the module.
*
* Version information (based on camera_module_t.common.module_api_version):
*
* CAMERA_MODULE_API_VERSION_1_0, CAMERA_MODULE_API_VERSION_2_0:
*
* Not provided by HAL module. Framework may not call this function.
*
* CAMERA_MODULE_API_VERSION_2_1:
*
* Valid to be called by the framework.
*
* Return values:
*
* 0: On a successful operation
*
* -ENODEV: The operation cannot be completed due to an internal
* error.
*
* -EINVAL: The input arguments are invalid, i.e. the callbacks are
* null
*/
int (*set_callbacks)(const camera_module_callbacks_t *callbacks);
/**
* get_vendor_tag_ops:
*
* Get methods to query for vendor extension metadata tag information. The
* HAL should fill in all the vendor tag operation methods, or leave ops
* unchanged if no vendor tags are defined.
*
* The vendor_tag_ops structure used here is defined in:
* system/media/camera/include/system/vendor_tags.h
*
* Version information (based on camera_module_t.common.module_api_version):
*
* CAMERA_MODULE_API_VERSION_1_x/2_0/2_1:
* Not provided by HAL module. Framework may not call this function.
*
* CAMERA_MODULE_API_VERSION_2_2:
* Valid to be called by the framework.
*/
void (*get_vendor_tag_ops)(vendor_tag_ops_t* ops);
/**
* open_legacy:
*
* Open a specific legacy camera HAL device if multiple device HAL API
* versions are supported by this camera HAL module. For example, if the
* camera module supports both CAMERA_DEVICE_API_VERSION_1_0 and
* CAMERA_DEVICE_API_VERSION_3_2 device API for the same camera id,
* framework can call this function to open the camera device as
* CAMERA_DEVICE_API_VERSION_1_0 device.
*
* This is an optional method. A Camera HAL module does not need to support
* more than one device HAL version per device, and such modules may return
* -ENOSYS for all calls to this method. For all older HAL device API
* versions that are not supported, it may return -EOPNOTSUPP. When above
* cases occur, The normal open() method (common.methods->open) will be
* used by the framework instead.
*
* Version information (based on camera_module_t.common.module_api_version):
*
* CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2:
* Not provided by HAL module. Framework will not call this function.
*
* CAMERA_MODULE_API_VERSION_2_3:
* Valid to be called by the framework.
*
* Return values:
*
* 0: On a successful open of the camera device.
*
* -ENOSYS This method is not supported.
*
* -EOPNOTSUPP: The requested HAL version is not supported by this method.
*
* -EINVAL: The input arguments are invalid, i.e. the id is invalid,
* and/or the module is invalid.
*
* -EBUSY: The camera device was already opened for this camera id
* (by using this method or common.methods->open method),
* regardless of the device HAL version it was opened as.
*
* -EUSERS: The maximal number of camera devices that can be
* opened concurrently were opened already, either by
* this method or common.methods->open method.
*/
int (*open_legacy)(const struct hw_module_t* module, const char* id,
uint32_t halVersion, struct hw_device_t** device);
/**
* set_torch_mode:
*
* Turn on or off the torch mode of the flash unit associated with a given
* camera ID. If the operation is successful, HAL must notify the framework
* torch state by invoking
* camera_module_callbacks.torch_mode_status_change() with the new state.
*
* The camera device has a higher priority accessing the flash unit. When
* there are any resource conflicts, such as open() is called to open a
* camera device, HAL module must notify the framework through
* camera_module_callbacks.torch_mode_status_change() that the
* torch mode has been turned off and the torch mode state has become
* TORCH_MODE_STATUS_NOT_AVAILABLE. When resources to turn on torch mode
* become available again, HAL module must notify the framework through
* camera_module_callbacks.torch_mode_status_change() that the torch mode
* state has become TORCH_MODE_STATUS_AVAILABLE_OFF for set_torch_mode() to
* be called.
*
* When the framework calls set_torch_mode() to turn on the torch mode of a
* flash unit, if HAL cannot keep multiple torch modes on simultaneously,
* HAL should turn off the torch mode that was turned on by
* a previous set_torch_mode() call and notify the framework that the torch
* mode state of that flash unit has become TORCH_MODE_STATUS_AVAILABLE_OFF.
*
* Version information (based on camera_module_t.common.module_api_version):
*
* CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2/2_3:
* Not provided by HAL module. Framework will not call this function.
*
* CAMERA_MODULE_API_VERSION_2_4:
* Valid to be called by the framework.
*
* Return values:
*
* 0: On a successful operation.
*
* -ENOSYS: The camera device does not support this operation. It is
* returned if and only if android.flash.info.available is
* false.
*
* -EBUSY: The camera device is already in use.
*
* -EUSERS: The resources needed to turn on the torch mode are not
* available, typically because other camera devices are
* holding the resources to make using the flash unit not
* possible.
*
* -EINVAL: camera_id is invalid.
*
*/
int (*set_torch_mode)(const char* camera_id, bool enabled);
/**
* init:
*
* This method is called by the camera service before any other methods
* are invoked, right after the camera HAL library has been successfully
* loaded. It may be left as NULL by the HAL module, if no initialization
* in needed.
*
* It can be used by HAL implementations to perform initialization and
* other one-time operations.
*
* Version information (based on camera_module_t.common.module_api_version):
*
* CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2/2_3:
* Not provided by HAL module. Framework will not call this function.
*
* CAMERA_MODULE_API_VERSION_2_4:
* If not NULL, will always be called by the framework once after the HAL
* module is loaded, before any other HAL module method is called.
*
* Return values:
*
* 0: On a successful operation.
*
* -ENODEV: Initialization cannot be completed due to an internal
* error. The HAL must be assumed to be in a nonfunctional
* state.
*
*/
int (*init)();
/* reserved for future use */
void* reserved[5];
} camera_module_t;
__END_DECLS
#endif /* ANDROID_INCLUDE_CAMERA_COMMON_H */
@@ -0,0 +1,92 @@
/*
* Copyright (C) 2013 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_CONSUMERIR_H
#define ANDROID_INCLUDE_HARDWARE_CONSUMERIR_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <hardware/hardware.h>
#include <hardware/hwcomposer_defs.h>
#define CONSUMERIR_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
#define CONSUMERIR_HARDWARE_MODULE_ID "consumerir"
#define CONSUMERIR_TRANSMITTER "transmitter"
typedef struct consumerir_freq_range {
int min;
int max;
} consumerir_freq_range_t;
typedef struct consumerir_module {
/**
* Common methods of the consumer IR module. This *must* be the first member of
* consumerir_module as users of this structure will cast a hw_module_t to
* consumerir_module pointer in contexts where it's known the hw_module_t references a
* consumerir_module.
*/
struct hw_module_t common;
} consumerir_module_t;
typedef struct consumerir_device {
/**
* Common methods of the consumer IR device. This *must* be the first member of
* consumerir_device as users of this structure will cast a hw_device_t to
* consumerir_device pointer in contexts where it's known the hw_device_t references a
* consumerir_device.
*/
struct hw_device_t common;
/*
* (*transmit)() is called to by the ConsumerIrService to send an IR pattern
* at a given carrier_freq.
*
* The pattern is alternating series of carrier on and off periods measured in
* microseconds. The carrier should be turned off at the end of a transmit
* even if there are and odd number of entries in the pattern array.
*
* This call should return when the transmit is complete or encounters an error.
*
* returns: 0 on success. A negative error code on error.
*/
int (*transmit)(struct consumerir_device *dev, int carrier_freq,
const int pattern[], int pattern_len);
/*
* (*get_num_carrier_freqs)() is called by the ConsumerIrService to get the
* number of carrier freqs to allocate space for, which is then filled by
* a subsequent call to (*get_carrier_freqs)().
*
* returns: the number of ranges on success. A negative error code on error.
*/
int (*get_num_carrier_freqs)(struct consumerir_device *dev);
/*
* (*get_carrier_freqs)() is called by the ConsumerIrService to enumerate
* which frequencies the IR transmitter supports. The HAL implementation
* should fill an array of consumerir_freq_range structs with the
* appropriate values for the transmitter, up to len elements.
*
* returns: the number of ranges on success. A negative error code on error.
*/
int (*get_carrier_freqs)(struct consumerir_device *dev,
size_t len, consumerir_freq_range_t *ranges);
/* Reserved for future use. Must be NULL. */
void* reserved[8 - 3];
} consumerir_device_t;
#endif /* ANDROID_INCLUDE_HARDWARE_CONSUMERIR_H */
@@ -0,0 +1,67 @@
/* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ANDROID_INCLUDE_DISPLAY_DEFS_H
#define ANDROID_INCLUDE_DISPLAY_DEFS_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <hardware/hwcomposer.h>
__BEGIN_DECLS
/* Will need to update below enums if hwcomposer_defs.h is updated */
/* Extended events for hwc_methods::eventControl() */
enum {
HWC_EVENT_ORIENTATION = HWC_EVENT_VSYNC + 1
};
/* Extended hwc_layer_t::compositionType values */
enum {
/* this layer will be handled in the HWC, using a blit engine */
HWC_BLIT = 0xFF
};
/* Extended hwc_layer_t::flags values
* Flags are set by SurfaceFlinger and read by the HAL
*/
enum {
/*
* HWC_SCREENSHOT_ANIMATOR_LAYER is set by surfaceflinger to indicate
* that this layer is a screenshot animating layer. HWC uses this
* info to disable rotation animation on External Display
*/
HWC_SCREENSHOT_ANIMATOR_LAYER = 0x00000004
};
__END_DECLS
#endif /* ANDROID_INCLUDE_DISPLAY_DEFS_H*/
@@ -0,0 +1,173 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_FB_INTERFACE_H
#define ANDROID_FB_INTERFACE_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <cutils/native_handle.h>
#include <hardware/hardware.h>
__BEGIN_DECLS
#define GRALLOC_HARDWARE_FB0 "fb0"
/*****************************************************************************/
/*****************************************************************************/
typedef struct framebuffer_device_t {
/**
* Common methods of the framebuffer device. This *must* be the first member of
* framebuffer_device_t as users of this structure will cast a hw_device_t to
* framebuffer_device_t pointer in contexts where it's known the hw_device_t references a
* framebuffer_device_t.
*/
struct hw_device_t common;
/* flags describing some attributes of the framebuffer */
const uint32_t flags;
/* dimensions of the framebuffer in pixels */
const uint32_t width;
const uint32_t height;
/* frambuffer stride in pixels */
const int stride;
/* framebuffer pixel format */
const int format;
/* resolution of the framebuffer's display panel in pixel per inch*/
const float xdpi;
const float ydpi;
/* framebuffer's display panel refresh rate in frames per second */
const float fps;
/* min swap interval supported by this framebuffer */
const int minSwapInterval;
/* max swap interval supported by this framebuffer */
const int maxSwapInterval;
/* Number of framebuffers supported*/
const int numFramebuffers;
int reserved[7];
/*
* requests a specific swap-interval (same definition than EGL)
*
* Returns 0 on success or -errno on error.
*/
int (*setSwapInterval)(struct framebuffer_device_t* window,
int interval);
/*
* This hook is OPTIONAL.
*
* It is non NULL If the framebuffer driver supports "update-on-demand"
* and the given rectangle is the area of the screen that gets
* updated during (*post)().
*
* This is useful on devices that are able to DMA only a portion of
* the screen to the display panel, upon demand -- as opposed to
* constantly refreshing the panel 60 times per second, for instance.
*
* Only the area defined by this rectangle is guaranteed to be valid, that
* is, the driver is not allowed to post anything outside of this
* rectangle.
*
* The rectangle evaluated during (*post)() and specifies which area
* of the buffer passed in (*post)() shall to be posted.
*
* return -EINVAL if width or height <=0, or if left or top < 0
*/
int (*setUpdateRect)(struct framebuffer_device_t* window,
int left, int top, int width, int height);
/*
* Post <buffer> to the display (display it on the screen)
* The buffer must have been allocated with the
* GRALLOC_USAGE_HW_FB usage flag.
* buffer must be the same width and height as the display and must NOT
* be locked.
*
* The buffer is shown during the next VSYNC.
*
* If the same buffer is posted again (possibly after some other buffer),
* post() will block until the the first post is completed.
*
* Internally, post() is expected to lock the buffer so that a
* subsequent call to gralloc_module_t::(*lock)() with USAGE_RENDER or
* USAGE_*_WRITE will block until it is safe; that is typically once this
* buffer is shown and another buffer has been posted.
*
* Returns 0 on success or -errno on error.
*/
int (*post)(struct framebuffer_device_t* dev, buffer_handle_t buffer);
/*
* The (*compositionComplete)() method must be called after the
* compositor has finished issuing GL commands for client buffers.
*/
int (*compositionComplete)(struct framebuffer_device_t* dev);
/*
* This hook is OPTIONAL.
*
* If non NULL it will be caused by SurfaceFlinger on dumpsys
*/
void (*dump)(struct framebuffer_device_t* dev, char *buff, int buff_len);
/*
* (*enableScreen)() is used to either blank (enable=0) or
* unblank (enable=1) the screen this framebuffer is attached to.
*
* Returns 0 on success or -errno on error.
*/
int (*enableScreen)(struct framebuffer_device_t* dev, int enable);
void* reserved_proc[6];
} framebuffer_device_t;
/** convenience API for opening and closing a supported device */
static inline int framebuffer_open(const struct hw_module_t* module,
struct framebuffer_device_t** device) {
return module->methods->open(module,
GRALLOC_HARDWARE_FB0, (struct hw_device_t**)device);
}
static inline int framebuffer_close(struct framebuffer_device_t* device) {
return device->common.close(&device->common);
}
__END_DECLS
#endif // ANDROID_FB_INTERFACE_H
@@ -0,0 +1,266 @@
/*
* 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_INCLUDE_HARDWARE_FINGERPRINT_H
#define ANDROID_INCLUDE_HARDWARE_FINGERPRINT_H
#include <hardware/hw_auth_token.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 {
FINGERPRINT_ERROR = -1,
FINGERPRINT_ACQUIRED = 1,
FINGERPRINT_TEMPLATE_ENROLLING = 3,
FINGERPRINT_TEMPLATE_REMOVED = 4,
FINGERPRINT_AUTHENTICATED = 5
} fingerprint_msg_type_t;
/*
* Fingerprint errors are meant to tell the framework to terminate the current operation and ask
* for the user to correct the situation. These will almost always result in messaging and user
* interaction to correct the problem.
*
* For example, FINGERPRINT_ERROR_CANCELED should follow any acquisition message that results in
* a situation where the current operation can't continue without user interaction. For example,
* if the sensor is dirty during enrollment and no further enrollment progress can be made,
* send FINGERPRINT_ACQUIRED_IMAGER_DIRTY followed by FINGERPRINT_ERROR_CANCELED.
*/
typedef enum fingerprint_error {
FINGERPRINT_ERROR_HW_UNAVAILABLE = 1, /* The hardware has an error that can't be resolved. */
FINGERPRINT_ERROR_UNABLE_TO_PROCESS = 2, /* Bad data; operation can't continue */
FINGERPRINT_ERROR_TIMEOUT = 3, /* The operation has timed out waiting for user input. */
FINGERPRINT_ERROR_NO_SPACE = 4, /* No space available to store a template */
FINGERPRINT_ERROR_CANCELED = 5, /* The current operation can't proceed. See above. */
FINGERPRINT_ERROR_UNABLE_TO_REMOVE = 6, /* fingerprint with given id can't be removed */
FINGERPRINT_ERROR_VENDOR_BASE = 1000 /* vendor-specific error messages start here */
} fingerprint_error_t;
/*
* Fingerprint acquisition info is meant as feedback for the current operation. Anything but
* FINGERPRINT_ACQUIRED_GOOD will be shown to the user as feedback on how to take action on the
* current operation. For example, FINGERPRINT_ACQUIRED_IMAGER_DIRTY can be used to tell the user
* to clean the sensor. If this will cause the current operation to fail, an additional
* FINGERPRINT_ERROR_CANCELED can be sent to stop the operation in progress (e.g. enrollment).
* In general, these messages will result in a "Try again" message.
*/
typedef enum fingerprint_acquired_info {
FINGERPRINT_ACQUIRED_GOOD = 0,
FINGERPRINT_ACQUIRED_PARTIAL = 1, /* sensor needs more data, i.e. longer swipe. */
FINGERPRINT_ACQUIRED_INSUFFICIENT = 2, /* image doesn't contain enough detail for recognition*/
FINGERPRINT_ACQUIRED_IMAGER_DIRTY = 3, /* sensor needs to be cleaned */
FINGERPRINT_ACQUIRED_TOO_SLOW = 4, /* mostly swipe-type sensors; not enough data collected */
FINGERPRINT_ACQUIRED_TOO_FAST = 5, /* for swipe and area sensors; tell user to slow down*/
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;
typedef struct fingerprint_enroll {
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). */
uint32_t samples_remaining;
uint64_t msg; /* Vendor specific message. Used for user guidance */
} fingerprint_enroll_t;
typedef struct fingerprint_removed {
fingerprint_finger_id_t finger;
} fingerprint_removed_t;
typedef struct fingerprint_acquired {
fingerprint_acquired_info_t acquired_info; /* information about the image */
} fingerprint_acquired_t;
typedef struct fingerprint_authenticated {
fingerprint_finger_id_t finger;
hw_auth_token_t hat;
} fingerprint_authenticated_t;
typedef struct fingerprint_msg {
fingerprint_msg_type_t type;
union {
fingerprint_error_t error;
fingerprint_enroll_t enroll;
fingerprint_removed_t removed;
fingerprint_acquired_t acquired;
fingerprint_authenticated_t authenticated;
} data;
} fingerprint_msg_t;
/* Callback function type */
typedef void (*fingerprint_notify_t)(const fingerprint_msg_t *msg);
/* Synchronous operation */
typedef struct fingerprint_device {
/**
* Common methods of the fingerprint device. This *must* be the first member
* of fingerprint_device as users of this structure will cast a hw_device_t
* to fingerprint_device pointer in contexts where it's known
* the hw_device_t references a fingerprint_device.
*/
struct hw_device_t common;
/*
* Client provided callback function to receive notifications.
* Do not set by hand, use the function above instead.
*/
fingerprint_notify_t notify;
/*
* Set notification callback:
* Registers a user function that would receive notifications from the HAL
* The call will block if the HAL state machine is in busy state until HAL
* leaves the busy state.
*
* Function return: 0 if callback function is successfuly registered
* or a negative number in case of error, generally from the errno.h set.
*/
int (*set_notify)(struct fingerprint_device *dev, fingerprint_notify_t notify);
/*
* Fingerprint pre-enroll enroll request:
* Generates a unique token to upper layers to indicate the start of an enrollment transaction.
* This token will be wrapped by security for verification and passed to enroll() for
* verification before enrollment will be allowed. This is to ensure adding a new fingerprint
* template was preceded by some kind of credential confirmation (e.g. device password).
*
* Function return: 0 if function failed
* otherwise, a uint64_t of token
*/
uint64_t (*pre_enroll)(struct fingerprint_device *dev);
/*
* Fingerprint enroll request:
* Switches the HAL state machine to collect and store a new fingerprint
* template. Switches back as soon as enroll is complete
* (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
* or a negative number in case of error, generally from the errno.h set.
* A notify() function may be called indicating the error condition.
*/
int (*enroll)(struct fingerprint_device *dev, const hw_auth_token_t *hat,
uint32_t gid, uint32_t timeout_sec);
/*
* Finishes the enroll operation and invalidates the pre_enroll() generated challenge.
* This will be called at the end of a multi-finger enrollment session to indicate
* that no more fingers will be added.
*
* Function return: 0 if the request is accepted
* or a negative number in case of error, generally from the errno.h set.
*/
int (*post_enroll)(struct fingerprint_device *dev);
/*
* get_authenticator_id:
* Returns a token associated with the current fingerprint set. This value will
* change whenever a new fingerprint is enrolled, thus creating a new fingerprint
* set.
*
* Function return: current authenticator id or 0 if function failed.
*/
uint64_t (*get_authenticator_id)(struct fingerprint_device *dev);
/*
* Cancel pending enroll or authenticate, sending FINGERPRINT_ERROR_CANCELED
* to all running clients. Switches the HAL state machine back to the idle state.
* Unlike enroll_done() doesn't invalidate the pre_enroll() challenge.
*
* Function return: 0 if cancel request is accepted
* or a negative number in case of error, generally from the errno.h set.
*/
int (*cancel)(struct fingerprint_device *dev);
/*
* Enumerate all the fingerprint templates found in the directory set by
* set_active_group()
* This is a synchronous call. The function takes:
* - A pointer to an array of fingerprint_finger_id_t.
* - The size of the array provided, in fingerprint_finger_id_t elements.
* Max_size is a bi-directional parameter and returns the actual number
* of elements copied to the caller supplied array.
* In the absence of errors the function returns the total number of templates
* in the user directory.
* If the caller has no good guess on the size of the array he should call this
* function witn *max_size == 0 and use the return value for the array allocation.
* The caller of this function has a complete list of the templates when *max_size
* is the same as the function return.
*
* Function return: Total number of fingerprint templates in the current storage directory.
* or a negative number in case of error, generally from the errno.h set.
*/
int (*enumerate)(struct fingerprint_device *dev, fingerprint_finger_id_t *results,
uint32_t *max_size);
/*
* Fingerprint remove request:
* Deletes a fingerprint template.
* Works only within a path set by set_active_group().
* notify() will be called with details on the template deleted.
* fingerprint_msg.type == FINGERPRINT_TEMPLATE_REMOVED and
* fingerprint_msg.data.removed.id indicating the template id removed.
*
* Function return: 0 if fingerprint template(s) can be successfully deleted
* or a negative number in case of error, generally from the errno.h set.
*/
int (*remove)(struct fingerprint_device *dev, uint32_t gid, uint32_t fid);
/*
* Restricts the HAL operation to a set of fingerprints belonging to a
* group provided.
* The caller must provide a path to a storage location within the user's
* data directory.
*
* Function return: 0 on success
* or a negative number in case of error, generally from the errno.h set.
*/
int (*set_active_group)(struct fingerprint_device *dev, uint32_t gid,
const char *store_path);
/*
* Authenticates an operation identifed by operation_id
*
* Function return: 0 on success
* or a negative number in case of error, generally from the errno.h set.
*/
int (*authenticate)(struct fingerprint_device *dev, uint64_t operation_id, uint32_t gid);
/* Reserved for backward binary compatibility */
void *reserved[4];
} fingerprint_device_t;
typedef struct fingerprint_module {
/**
* Common methods of the fingerprint module. This *must* be the first member
* of fingerprint_module as users of this structure will cast a hw_module_t
* to fingerprint_module pointer in contexts where it's known
* the hw_module_t references a fingerprint_module.
*/
struct hw_module_t common;
} fingerprint_module_t;
#endif /* ANDROID_INCLUDE_HARDWARE_FINGERPRINT_H */
@@ -0,0 +1,825 @@
/*
* Copyright (C) 2013 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_FUSED_LOCATION_H
#define ANDROID_INCLUDE_HARDWARE_FUSED_LOCATION_H
#include <hardware/hardware.h>
/**
* This header file defines the interface of the Fused Location Provider.
* Fused Location Provider is designed to fuse data from various sources
* like GPS, Wifi, Cell, Sensors, Bluetooth etc to provide a fused location to the
* upper layers. The advantage of doing fusion in hardware is power savings.
* The goal is to do this without waking up the AP to get additional data.
* The software implementation of FLP will decide when to use
* the hardware fused location. Other location features like geofencing will
* also be implemented using fusion in hardware.
*/
__BEGIN_DECLS
#define FLP_HEADER_VERSION 1
#define FLP_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
#define FLP_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION_2(0, 1, FLP_HEADER_VERSION)
/**
* The id of this module
*/
#define FUSED_LOCATION_HARDWARE_MODULE_ID "flp"
/**
* Name for the FLP location interface
*/
#define FLP_LOCATION_INTERFACE "flp_location"
/**
* Name for the FLP location interface
*/
#define FLP_DIAGNOSTIC_INTERFACE "flp_diagnostic"
/**
* Name for the FLP_Geofencing interface.
*/
#define FLP_GEOFENCING_INTERFACE "flp_geofencing"
/**
* Name for the FLP_device context interface.
*/
#define FLP_DEVICE_CONTEXT_INTERFACE "flp_device_context"
/**
* Constants to indicate the various subsystems
* that will be used.
*/
#define FLP_TECH_MASK_GNSS (1U<<0)
#define FLP_TECH_MASK_WIFI (1U<<1)
#define FLP_TECH_MASK_SENSORS (1U<<2)
#define FLP_TECH_MASK_CELL (1U<<3)
#define FLP_TECH_MASK_BLUETOOTH (1U<<4)
/**
* Set when your implementation can produce GNNS-derived locations,
* for use with flp_capabilities_callback.
*
* GNNS is a required capability for a particular feature to be used
* (batching or geofencing). If not supported that particular feature
* won't be used by the upper layer.
*/
#define CAPABILITY_GNSS (1U<<0)
/**
* Set when your implementation can produce WiFi-derived locations, for
* use with flp_capabilities_callback.
*/
#define CAPABILITY_WIFI (1U<<1)
/**
* Set when your implementation can produce cell-derived locations, for
* use with flp_capabilities_callback.
*/
#define CAPABILITY_CELL (1U<<3)
/**
* Status to return in flp_status_callback when your implementation transitions
* from being unsuccessful in determining location to being successful.
*/
#define FLP_STATUS_LOCATION_AVAILABLE 0
/**
* Status to return in flp_status_callback when your implementation transitions
* from being successful in determining location to being unsuccessful.
*/
#define FLP_STATUS_LOCATION_UNAVAILABLE 1
/**
* This constant is used with the batched locations
* APIs. Batching is mandatory when FLP implementation
* is supported. If the flag is set, the hardware implementation
* will wake up the application processor when the FIFO is full,
* If the flag is not set, the hardware implementation will drop
* the oldest data when the FIFO is full.
*/
#define FLP_BATCH_WAKEUP_ON_FIFO_FULL 0x0000001
/**
* While batching, the implementation should not call the
* flp_location_callback on every location fix. However,
* sometimes in high power mode, the system might need
* a location callback every single time the location
* fix has been obtained. This flag controls that option.
* Its the responsibility of the upper layers (caller) to switch
* it off, if it knows that the AP might go to sleep.
* When this bit is on amidst a batching session, batching should
* continue while location fixes are reported in real time.
*/
#define FLP_BATCH_CALLBACK_ON_LOCATION_FIX 0x0000002
/** Flags to indicate which values are valid in a FlpLocation. */
typedef uint16_t FlpLocationFlags;
// IMPORTANT: Note that the following values must match
// constants in the corresponding java file.
/** FlpLocation has valid latitude and longitude. */
#define FLP_LOCATION_HAS_LAT_LONG (1U<<0)
/** FlpLocation has valid altitude. */
#define FLP_LOCATION_HAS_ALTITUDE (1U<<1)
/** FlpLocation has valid speed. */
#define FLP_LOCATION_HAS_SPEED (1U<<2)
/** FlpLocation has valid bearing. */
#define FLP_LOCATION_HAS_BEARING (1U<<4)
/** FlpLocation has valid accuracy. */
#define FLP_LOCATION_HAS_ACCURACY (1U<<8)
typedef int64_t FlpUtcTime;
/** Represents a location. */
typedef struct {
/** set to sizeof(FlpLocation) */
size_t size;
/** Flags associated with the location object. */
FlpLocationFlags flags;
/** Represents latitude in degrees. */
double latitude;
/** Represents longitude in degrees. */
double longitude;
/**
* Represents altitude in meters above the WGS 84 reference
* ellipsoid. */
double altitude;
/** Represents speed in meters per second. */
float speed;
/** Represents heading in degrees. */
float bearing;
/** Represents expected accuracy in meters. */
float accuracy;
/** Timestamp for the location fix. */
FlpUtcTime timestamp;
/** Sources used, will be Bitwise OR of the FLP_TECH_MASK bits. */
uint32_t sources_used;
} FlpLocation;
typedef enum {
ASSOCIATE_JVM,
DISASSOCIATE_JVM,
} ThreadEvent;
/**
* Callback with location information.
* Can only be called from a thread associated to JVM using set_thread_event_cb.
* Parameters:
* num_locations is the number of batched locations available.
* location is the pointer to an array of pointers to location objects.
*/
typedef void (*flp_location_callback)(int32_t num_locations, FlpLocation** location);
/**
* Callback utility for acquiring a wakelock.
* This can be used to prevent the CPU from suspending while handling FLP events.
*/
typedef void (*flp_acquire_wakelock)();
/**
* Callback utility for releasing the FLP wakelock.
*/
typedef void (*flp_release_wakelock)();
/**
* Callback for associating a thread that can call into the Java framework code.
* This must be used to initialize any threads that report events up to the framework.
* Return value:
* FLP_RESULT_SUCCESS on success.
* FLP_RESULT_ERROR if the association failed in the current thread.
*/
typedef int (*flp_set_thread_event)(ThreadEvent event);
/**
* Callback for technologies supported by this implementation.
*
* Parameters: capabilities is a bitmask of FLP_CAPABILITY_* values describing
* which features your implementation supports. You should support
* CAPABILITY_GNSS at a minimum for your implementation to be utilized. You can
* return 0 in FlpGeofenceCallbacks to indicate you don't support geofencing,
* or 0 in FlpCallbacks to indicate you don't support location batching.
*/
typedef void (*flp_capabilities_callback)(int capabilities);
/**
* Callback with status information on the ability to compute location.
* To avoid waking up the application processor you should only send
* changes in status (you shouldn't call this method twice in a row
* with the same status value). As a guideline you should not call this
* more frequently then the requested batch period set with period_ns
* in FlpBatchOptions. For example if period_ns is set to 5 minutes and
* the status changes many times in that interval, you should only report
* one status change every 5 minutes.
*
* Parameters:
* status is one of FLP_STATUS_LOCATION_AVAILABLE
* or FLP_STATUS_LOCATION_UNAVAILABLE.
*/
typedef void (*flp_status_callback)(int32_t status);
/** FLP callback structure. */
typedef struct {
/** set to sizeof(FlpCallbacks) */
size_t size;
flp_location_callback location_cb;
flp_acquire_wakelock acquire_wakelock_cb;
flp_release_wakelock release_wakelock_cb;
flp_set_thread_event set_thread_event_cb;
flp_capabilities_callback flp_capabilities_cb;
flp_status_callback flp_status_cb;
} FlpCallbacks;
/** Options with the batching FLP APIs */
typedef struct {
/**
* Maximum power in mW that the underlying implementation
* can use for this batching call.
* If max_power_allocation_mW is 0, only fixes that are generated
* at no additional cost of power shall be reported.
*/
double max_power_allocation_mW;
/** Bitwise OR of the FLP_TECH_MASKS to use */
uint32_t sources_to_use;
/**
* FLP_BATCH_WAKEUP_ON_FIFO_FULL - If set the hardware
* will wake up the AP when the buffer is full. If not set, the
* hardware will drop the oldest location object.
*
* FLP_BATCH_CALLBACK_ON_LOCATION_FIX - If set the location
* callback will be called every time there is a location fix.
* Its the responsibility of the upper layers (caller) to switch
* it off, if it knows that the AP might go to sleep. When this
* bit is on amidst a batching session, batching should continue
* while location fixes are reported in real time.
*
* Other flags to be bitwised ORed in the future.
*/
uint32_t flags;
/**
* Frequency with which location needs to be batched in nano
* seconds.
*/
int64_t period_ns;
/**
* The smallest displacement between reported locations in meters.
*
* If set to 0, then you should report locations at the requested
* interval even if the device is stationary. If positive, you
* can use this parameter as a hint to save power (e.g. throttling
* location period if the user hasn't traveled close to the displacement
* threshold). Even small positive values can be interpreted to mean
* that you don't have to compute location when the device is stationary.
*
* There is no need to filter location delivery based on this parameter.
* Locations can be delivered even if they have a displacement smaller than
* requested. This parameter can safely be ignored at the cost of potential
* power savings.
*/
float smallest_displacement_meters;
} FlpBatchOptions;
#define FLP_RESULT_SUCCESS 0
#define FLP_RESULT_ERROR -1
#define FLP_RESULT_INSUFFICIENT_MEMORY -2
#define FLP_RESULT_TOO_MANY_GEOFENCES -3
#define FLP_RESULT_ID_EXISTS -4
#define FLP_RESULT_ID_UNKNOWN -5
#define FLP_RESULT_INVALID_GEOFENCE_TRANSITION -6
/**
* Represents the standard FLP interface.
*/
typedef struct {
/**
* set to sizeof(FlpLocationInterface)
*/
size_t size;
/**
* Opens the interface and provides the callback routines
* to the implementation of this interface. Once called you should respond
* by calling the flp_capabilities_callback in FlpCallbacks to
* specify the capabilities that your implementation supports.
*/
int (*init)(FlpCallbacks* callbacks );
/**
* Return the batch size (in number of FlpLocation objects)
* available in the hardware. Note, different HW implementations
* may have different sample sizes. This shall return number
* of samples defined in the format of FlpLocation.
* This will be used by the upper layer, to decide on the batching
* interval and whether the AP should be woken up or not.
*/
int (*get_batch_size)();
/**
* Start batching locations. This API is primarily used when the AP is
* asleep and the device can batch locations in the hardware.
* flp_location_callback is used to return the locations. When the buffer
* is full and FLP_BATCH_WAKEUP_ON_FIFO_FULL is used, the AP is woken up.
* When the buffer is full and FLP_BATCH_WAKEUP_ON_FIFO_FULL is not set,
* the oldest location object is dropped. In this case the AP will not be
* woken up. The upper layer will use get_batched_location
* API to explicitly ask for the location.
* If FLP_BATCH_CALLBACK_ON_LOCATION_FIX is set, the implementation
* will call the flp_location_callback every single time there is a location
* fix. This overrides FLP_BATCH_WAKEUP_ON_FIFO_FULL flag setting.
* It's the responsibility of the upper layers (caller) to switch
* it off, if it knows that the AP might go to sleep. This is useful
* for nagivational applications when the system is in high power mode.
* Parameters:
* id - Id for the request.
* options - See FlpBatchOptions struct definition.
* Return value:
* FLP_RESULT_SUCCESS on success, FLP_RESULT_INSUFFICIENT_MEMORY,
* FLP_RESULT_ID_EXISTS, FLP_RESULT_ERROR on failure.
*/
int (*start_batching)(int id, FlpBatchOptions* options);
/**
* Update FlpBatchOptions associated with a batching request.
* When a batching operation is in progress and a batching option
* such as FLP_BATCH_WAKEUP_ON_FIFO_FULL needs to be updated, this API
* will be used. For instance, this can happen when the AP is awake and
* the maps application is being used.
* Parameters:
* id - Id of an existing batch request.
* new_options - Updated FlpBatchOptions
* Return value:
* FLP_RESULT_SUCCESS on success, FLP_RESULT_ID_UNKNOWN,
* FLP_RESULT_ERROR on error.
*/
int (*update_batching_options)(int id, FlpBatchOptions* new_options);
/**
* Stop batching.
* Parameters:
* id - Id for the request.
* Return Value:
* FLP_RESULT_SUCCESS on success, FLP_RESULT_ID_UNKNOWN or
* FLP_RESULT_ERROR on failure.
*/
int (*stop_batching)(int id);
/**
* Closes the interface. If any batch operations are in progress,
* they should be stopped.
*/
void (*cleanup)();
/**
* Get the fused location that was batched.
* flp_location_callback is used to return the location. The location object
* is dropped from the buffer only when the buffer is full. Do not remove it
* from the buffer just because it has been returned using the callback.
* In other words, when there is no new location object, two calls to
* get_batched_location(1) should return the same location object.
* Parameters:
* last_n_locations - Number of locations to get. This can be one or many.
* If the last_n_locations is 1, you get the latest location known to the
* hardware.
*/
void (*get_batched_location)(int last_n_locations);
/**
* Injects current location from another location provider
* latitude and longitude are measured in degrees
* expected accuracy is measured in meters
* Parameters:
* location - The location object being injected.
* Return value: FLP_RESULT_SUCCESS or FLP_RESULT_ERROR.
*/
int (*inject_location)(FlpLocation* location);
/**
* Get a pointer to extension information.
*/
const void* (*get_extension)(const char* name);
/**
* Retrieve all batched locations currently stored and clear the buffer.
* flp_location_callback MUST be called in response, even if there are
* no locations to flush (in which case num_locations should be 0).
* Subsequent calls to get_batched_location or flush_batched_locations
* should not return any of the locations returned in this call.
*/
void (*flush_batched_locations)();
} FlpLocationInterface;
struct flp_device_t {
struct hw_device_t common;
/**
* Get a handle to the FLP Interface.
*/
const FlpLocationInterface* (*get_flp_interface)(struct flp_device_t* dev);
};
/**
* Callback for reports diagnostic data into the Java framework code.
*/
typedef void (*report_data)(char* data, int length);
/**
* FLP diagnostic callback structure.
* Currently, not used - but this for future extension.
*/
typedef struct {
/** set to sizeof(FlpDiagnosticCallbacks) */
size_t size;
flp_set_thread_event set_thread_event_cb;
/** reports diagnostic data into the Java framework code */
report_data data_cb;
} FlpDiagnosticCallbacks;
/** Extended interface for diagnostic support. */
typedef struct {
/** set to sizeof(FlpDiagnosticInterface) */
size_t size;
/**
* Opens the diagnostic interface and provides the callback routines
* to the implemenation of this interface.
*/
void (*init)(FlpDiagnosticCallbacks* callbacks);
/**
* Injects diagnostic data into the FLP subsystem.
* Return 0 on success, -1 on error.
**/
int (*inject_data)(char* data, int length );
} FlpDiagnosticInterface;
/**
* Context setting information.
* All these settings shall be injected to FLP HAL at FLP init time.
* Following that, only the changed setting need to be re-injected
* upon changes.
*/
#define FLP_DEVICE_CONTEXT_GPS_ENABLED (1U<<0)
#define FLP_DEVICE_CONTEXT_AGPS_ENABLED (1U<<1)
#define FLP_DEVICE_CONTEXT_NETWORK_POSITIONING_ENABLED (1U<<2)
#define FLP_DEVICE_CONTEXT_WIFI_CONNECTIVITY_ENABLED (1U<<3)
#define FLP_DEVICE_CONTEXT_WIFI_POSITIONING_ENABLED (1U<<4)
#define FLP_DEVICE_CONTEXT_HW_NETWORK_POSITIONING_ENABLED (1U<<5)
#define FLP_DEVICE_CONTEXT_AIRPLANE_MODE_ON (1U<<6)
#define FLP_DEVICE_CONTEXT_DATA_ENABLED (1U<<7)
#define FLP_DEVICE_CONTEXT_ROAMING_ENABLED (1U<<8)
#define FLP_DEVICE_CONTEXT_CURRENTLY_ROAMING (1U<<9)
#define FLP_DEVICE_CONTEXT_SENSOR_ENABLED (1U<<10)
#define FLP_DEVICE_CONTEXT_BLUETOOTH_ENABLED (1U<<11)
#define FLP_DEVICE_CONTEXT_CHARGER_ON (1U<<12)
/** Extended interface for device context support. */
typedef struct {
/** set to sizeof(FlpDeviceContextInterface) */
size_t size;
/**
* Injects debug data into the FLP subsystem.
* Return 0 on success, -1 on error.
**/
int (*inject_device_context)(uint32_t enabledMask);
} FlpDeviceContextInterface;
/**
* There are 3 states associated with a Geofence: Inside, Outside, Unknown.
* There are 3 transitions: ENTERED, EXITED, UNCERTAIN.
*
* An example state diagram with confidence level: 95% and Unknown time limit
* set as 30 secs is shown below. (confidence level and Unknown time limit are
* explained latter)
* ____________________________
* | Unknown (30 secs) |
* """"""""""""""""""""""""""""
* ^ | | ^
* UNCERTAIN| |ENTERED EXITED| |UNCERTAIN
* | v v |
* ________ EXITED _________
* | Inside | -----------> | Outside |
* | | <----------- | |
* """""""" ENTERED """""""""
*
* Inside state: We are 95% confident that the user is inside the geofence.
* Outside state: We are 95% confident that the user is outside the geofence
* Unknown state: Rest of the time.
*
* The Unknown state is better explained with an example:
*
* __________
* | c|
* | ___ | _______
* | |a| | | b |
* | """ | """""""
* | |
* """"""""""
* In the diagram above, "a" and "b" are 2 geofences and "c" is the accuracy
* circle reported by the FLP subsystem. Now with regard to "b", the system is
* confident that the user is outside. But with regard to "a" is not confident
* whether it is inside or outside the geofence. If the accuracy remains the
* same for a sufficient period of time, the UNCERTAIN transition would be
* triggered with the state set to Unknown. If the accuracy improves later, an
* appropriate transition should be triggered. This "sufficient period of time"
* is defined by the parameter in the add_geofence_area API.
* In other words, Unknown state can be interpreted as a state in which the
* FLP subsystem isn't confident enough that the user is either inside or
* outside the Geofence. It moves to Unknown state only after the expiry of the
* timeout.
*
* The geofence callback needs to be triggered for the ENTERED and EXITED
* transitions, when the FLP system is confident that the user has entered
* (Inside state) or exited (Outside state) the Geofence. An implementation
* which uses a value of 95% as the confidence is recommended. The callback
* should be triggered only for the transitions requested by the
* add_geofence_area call.
*
* Even though the diagram and explanation talks about states and transitions,
* the callee is only interested in the transistions. The states are mentioned
* here for illustrative purposes.
*
* Startup Scenario: When the device boots up, if an application adds geofences,
* and then we get an accurate FLP location fix, it needs to trigger the
* appropriate (ENTERED or EXITED) transition for every Geofence it knows about.
* By default, all the Geofences will be in the Unknown state.
*
* When the FLP system is unavailable, flp_geofence_status_callback should be
* called to inform the upper layers of the same. Similarly, when it becomes
* available the callback should be called. This is a global state while the
* UNKNOWN transition described above is per geofence.
*
*/
#define FLP_GEOFENCE_TRANSITION_ENTERED (1L<<0)
#define FLP_GEOFENCE_TRANSITION_EXITED (1L<<1)
#define FLP_GEOFENCE_TRANSITION_UNCERTAIN (1L<<2)
#define FLP_GEOFENCE_MONITOR_STATUS_UNAVAILABLE (1L<<0)
#define FLP_GEOFENCE_MONITOR_STATUS_AVAILABLE (1L<<1)
/**
* The callback associated with the geofence.
* Parameters:
* geofence_id - The id associated with the add_geofence_area.
* location - The current location as determined by the FLP subsystem.
* transition - Can be one of FLP_GEOFENCE_TRANSITION_ENTERED, FLP_GEOFENCE_TRANSITION_EXITED,
* FLP_GEOFENCE_TRANSITION_UNCERTAIN.
* timestamp - Timestamp when the transition was detected; -1 if not available.
* sources_used - Bitwise OR of FLP_TECH_MASK flags indicating which
* subsystems were used.
*
* The callback should only be called when the caller is interested in that
* particular transition. For instance, if the caller is interested only in
* ENTERED transition, then the callback should NOT be called with the EXITED
* transition.
*
* IMPORTANT: If a transition is triggered resulting in this callback, the
* subsystem will wake up the application processor, if its in suspend state.
*/
typedef void (*flp_geofence_transition_callback) (int32_t geofence_id, FlpLocation* location,
int32_t transition, FlpUtcTime timestamp, uint32_t sources_used);
/**
* The callback associated with the availablity of one the sources used for geofence
* monitoring by the FLP sub-system For example, if the GPS system determines that it cannot
* monitor geofences because of lack of reliability or unavailability of the GPS signals,
* it will call this callback with FLP_GEOFENCE_MONITOR_STATUS_UNAVAILABLE parameter and the
* source set to FLP_TECH_MASK_GNSS.
*
* Parameters:
* status - FLP_GEOFENCE_MONITOR_STATUS_UNAVAILABLE or FLP_GEOFENCE_MONITOR_STATUS_AVAILABLE.
* source - One of the FLP_TECH_MASKS
* last_location - Last known location.
*/
typedef void (*flp_geofence_monitor_status_callback) (int32_t status, uint32_t source,
FlpLocation* last_location);
/**
* The callback associated with the add_geofence call.
*
* Parameter:
* geofence_id - Id of the geofence.
* result - FLP_RESULT_SUCCESS
* FLP_RESULT_ERROR_TOO_MANY_GEOFENCES - geofence limit has been reached.
* FLP_RESULT_ID_EXISTS - geofence with id already exists
* FLP_RESULT_INVALID_GEOFENCE_TRANSITION - the monitorTransition contains an
* invalid transition
* FLP_RESULT_ERROR - for other errors.
*/
typedef void (*flp_geofence_add_callback) (int32_t geofence_id, int32_t result);
/**
* The callback associated with the remove_geofence call.
*
* Parameter:
* geofence_id - Id of the geofence.
* result - FLP_RESULT_SUCCESS
* FLP_RESULT_ID_UNKNOWN - for invalid id
* FLP_RESULT_ERROR for others.
*/
typedef void (*flp_geofence_remove_callback) (int32_t geofence_id, int32_t result);
/**
* The callback associated with the pause_geofence call.
*
* Parameter:
* geofence_id - Id of the geofence.
* result - FLP_RESULT_SUCCESS
* FLP_RESULT__ID_UNKNOWN - for invalid id
* FLP_RESULT_INVALID_TRANSITION -
* when monitor_transitions is invalid
* FLP_RESULT_ERROR for others.
*/
typedef void (*flp_geofence_pause_callback) (int32_t geofence_id, int32_t result);
/**
* The callback associated with the resume_geofence call.
*
* Parameter:
* geofence_id - Id of the geofence.
* result - FLP_RESULT_SUCCESS
* FLP_RESULT_ID_UNKNOWN - for invalid id
* FLP_RESULT_ERROR for others.
*/
typedef void (*flp_geofence_resume_callback) (int32_t geofence_id, int32_t result);
typedef struct {
/** set to sizeof(FlpGeofenceCallbacks) */
size_t size;
flp_geofence_transition_callback geofence_transition_callback;
flp_geofence_monitor_status_callback geofence_status_callback;
flp_geofence_add_callback geofence_add_callback;
flp_geofence_remove_callback geofence_remove_callback;
flp_geofence_pause_callback geofence_pause_callback;
flp_geofence_resume_callback geofence_resume_callback;
flp_set_thread_event set_thread_event_cb;
flp_capabilities_callback flp_capabilities_cb;
} FlpGeofenceCallbacks;
/** Type of geofence */
typedef enum {
TYPE_CIRCLE = 0,
} GeofenceType;
/** Circular geofence is represented by lat / long / radius */
typedef struct {
double latitude;
double longitude;
double radius_m;
} GeofenceCircle;
/** Represents the type of geofence and data */
typedef struct {
GeofenceType type;
union {
GeofenceCircle circle;
} geofence;
} GeofenceData;
/** Geofence Options */
typedef struct {
/**
* The current state of the geofence. For example, if
* the system already knows that the user is inside the geofence,
* this will be set to FLP_GEOFENCE_TRANSITION_ENTERED. In most cases, it
* will be FLP_GEOFENCE_TRANSITION_UNCERTAIN. */
int last_transition;
/**
* Transitions to monitor. Bitwise OR of
* FLP_GEOFENCE_TRANSITION_ENTERED, FLP_GEOFENCE_TRANSITION_EXITED and
* FLP_GEOFENCE_TRANSITION_UNCERTAIN.
*/
int monitor_transitions;
/**
* Defines the best-effort description
* of how soon should the callback be called when the transition
* associated with the Geofence is triggered. For instance, if set
* to 1000 millseconds with FLP_GEOFENCE_TRANSITION_ENTERED, the callback
* should be called 1000 milliseconds within entering the geofence.
* This parameter is defined in milliseconds.
* NOTE: This is not to be confused with the rate that the GPS is
* polled at. It is acceptable to dynamically vary the rate of
* sampling the GPS for power-saving reasons; thus the rate of
* sampling may be faster or slower than this.
*/
int notification_responsivenes_ms;
/**
* The time limit after which the UNCERTAIN transition
* should be triggered. This paramter is defined in milliseconds.
*/
int unknown_timer_ms;
/**
* The sources to use for monitoring geofences. Its a BITWISE-OR
* of FLP_TECH_MASK flags.
*/
uint32_t sources_to_use;
} GeofenceOptions;
/** Geofence struct */
typedef struct {
int32_t geofence_id;
GeofenceData* data;
GeofenceOptions* options;
} Geofence;
/** Extended interface for FLP_Geofencing support */
typedef struct {
/** set to sizeof(FlpGeofencingInterface) */
size_t size;
/**
* Opens the geofence interface and provides the callback routines
* to the implemenation of this interface. Once called you should respond
* by calling the flp_capabilities_callback in FlpGeofenceCallbacks to
* specify the capabilities that your implementation supports.
*/
void (*init)( FlpGeofenceCallbacks* callbacks );
/**
* Add a list of geofences.
* Parameters:
* number_of_geofences - The number of geofences that needed to be added.
* geofences - Pointer to array of pointers to Geofence structure.
*/
void (*add_geofences) (int32_t number_of_geofences, Geofence** geofences);
/**
* Pause monitoring a particular geofence.
* Parameters:
* geofence_id - The id for the geofence.
*/
void (*pause_geofence) (int32_t geofence_id);
/**
* Resume monitoring a particular geofence.
* Parameters:
* geofence_id - The id for the geofence.
* monitor_transitions - Which transitions to monitor. Bitwise OR of
* FLP_GEOFENCE_TRANSITION_ENTERED, FLP_GEOFENCE_TRANSITION_EXITED and
* FLP_GEOFENCE_TRANSITION_UNCERTAIN.
* This supersedes the value associated provided in the
* add_geofence_area call.
*/
void (*resume_geofence) (int32_t geofence_id, int monitor_transitions);
/**
* Modify a particular geofence option.
* Parameters:
* geofence_id - The id for the geofence.
* options - Various options associated with the geofence. See
* GeofenceOptions structure for details.
*/
void (*modify_geofence_option) (int32_t geofence_id, GeofenceOptions* options);
/**
* Remove a list of geofences. After the function returns, no notifications
* should be sent.
* Parameter:
* number_of_geofences - The number of geofences that needed to be added.
* geofence_id - Pointer to array of geofence_ids to be removed.
*/
void (*remove_geofences) (int32_t number_of_geofences, int32_t* geofence_id);
} FlpGeofencingInterface;
__END_DECLS
#endif /* ANDROID_INCLUDE_HARDWARE_FLP_H */
@@ -0,0 +1,190 @@
/*
* 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.
*
* Parameters:
* - dev: pointer to gatekeeper_device acquired via calls to gatekeeper_open
* - uid: the Android user identifier
*
* - current_password_handle: the currently enrolled password handle the user
* wants to replace. May be null if there's no currently enrolled password.
* - current_password_handle_length: the length in bytes of the buffer pointed
* at by current_password_handle. Must be 0 if current_password_handle is NULL.
*
* - current_password: the user's current password in plain text. If presented,
* it MUST verify against current_password_handle.
* - current_password_length: the size in bytes of the buffer pointed at by
* current_password. Must be 0 if the current_password is NULL.
*
* - desired_password: the new password the user wishes to enroll in plain-text.
* Cannot be NULL.
* - desired_password_length: the length in bytes of the buffer pointed at by
* desired_password.
*
* - enrolled_password_handle: on success, a buffer will be allocated with the
* new password handle referencing the password provided in desired_password.
* This buffer can be used on subsequent calls to enroll or verify.
* The caller is responsible for deallocating this buffer via a call to delete[]
* - enrolled_password_handle_length: pointer to the length in bytes of the buffer allocated
* by this function and pointed to by *enrolled_password_handle_length.
*
* Returns:
* - 0 on success
* - An error code < 0 on failure, or
* - A timeout value T > 0 if the call should not be re-attempted until T milliseconds
* have elapsed.
*
* 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, uint32_t current_password_handle_length,
const uint8_t *current_password, uint32_t current_password_length,
const uint8_t *desired_password, uint32_t desired_password_length,
uint8_t **enrolled_password_handle, uint32_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.
*
* Parameters:
* - dev: pointer to gatekeeper_device acquired via calls to gatekeeper_open
* - uid: the Android user identifier
*
* - challenge: An optional challenge to authenticate against, or 0. Used when a separate
* authenticator requests password verification, or for transactional
* password authentication.
*
* - enrolled_password_handle: the currently enrolled password handle that the
* user wishes to verify against.
* - enrolled_password_handle_length: the length in bytes of the buffer pointed
* to by enrolled_password_handle
*
* - provided_password: the plaintext password to be verified against the
* enrolled_password_handle
* - provided_password_length: the length in bytes of the buffer pointed to by
* provided_password
*
* - auth_token: on success, a buffer containing the authentication token
* resulting from this verification is assigned to *auth_token. The caller
* is responsible for deallocating this memory via a call to delete[]
* - auth_token_length: on success, the length in bytes of the authentication
* token assigned to *auth_token will be assigned to *auth_token_length
*
* - request_reenroll: a request to the upper layers to re-enroll the verified
* password due to a version change. Not set if verification fails.
*
* Returns:
* - 0 on success
* - An error code < 0 on failure, or
* - A timeout value T > 0 if the call should not be re-attempted until T milliseconds
* have elapsed.
* On error, auth token will not be allocated
*/
int (*verify)(const struct gatekeeper_device *dev, uint32_t uid, uint64_t challenge,
const uint8_t *enrolled_password_handle, uint32_t enrolled_password_handle_length,
const uint8_t *provided_password, uint32_t provided_password_length,
uint8_t **auth_token, uint32_t *auth_token_length, bool *request_reenroll);
/*
* Deletes the enrolled_password_handle associated wth the uid. Once deleted
* the user cannot be verified anymore.
* This function is optional and should be set to NULL if it is not implemented.
*
* Parameters
* - dev: pointer to gatekeeper_device acquired via calls to gatekeeper_open
* - uid: the Android user identifier
*
* Returns:
* - 0 on success
* - An error code < 0 on failure
*/
int (*delete_user)(const struct gatekeeper_device *dev, uint32_t uid);
/*
* Deletes all the enrolled_password_handles for all uid's. Once called,
* no users will be enrolled on the device.
* This function is optional and should be set to NULL if it is not implemented.
*
* Parameters
* - dev: pointer to gatekeeper_device acquired via calls to gatekeeper_open
*
* Returns:
* - 0 on success
* - An error code < 0 on failure
*/
int (*delete_all_users)(const struct gatekeeper_device *dev);
};
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
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,401 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_GRALLOC_INTERFACE_H
#define ANDROID_GRALLOC_INTERFACE_H
#include <system/window.h>
#include <system/graphics.h>
#include <hardware/hardware.h>
#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <cutils/native_handle.h>
#include <hardware/hardware.h>
#include <hardware/fb.h>
__BEGIN_DECLS
/**
* Module versioning information for the Gralloc hardware module, based on
* gralloc_module_t.common.module_api_version.
*
* Version History:
*
* GRALLOC_MODULE_API_VERSION_0_1:
* Initial Gralloc hardware module API.
*
* GRALLOC_MODULE_API_VERSION_0_2:
* Add support for flexible YCbCr format with (*lock_ycbcr)() method.
*
* GRALLOC_MODULE_API_VERSION_0_3:
* Add support for fence passing to/from lock/unlock.
*/
#define GRALLOC_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
#define GRALLOC_MODULE_API_VERSION_0_2 HARDWARE_MODULE_API_VERSION(0, 2)
#define GRALLOC_MODULE_API_VERSION_0_3 HARDWARE_MODULE_API_VERSION(0, 3)
#define GRALLOC_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION(0, 1)
/**
* The id of this module
*/
#define GRALLOC_HARDWARE_MODULE_ID "gralloc"
/**
* Name of the graphics device to open
*/
#define GRALLOC_HARDWARE_GPU0 "gpu0"
enum {
/* buffer is never read in software */
GRALLOC_USAGE_SW_READ_NEVER = 0x00000000,
/* buffer is rarely read in software */
GRALLOC_USAGE_SW_READ_RARELY = 0x00000002,
/* buffer is often read in software */
GRALLOC_USAGE_SW_READ_OFTEN = 0x00000003,
/* mask for the software read values */
GRALLOC_USAGE_SW_READ_MASK = 0x0000000F,
/* buffer is never written in software */
GRALLOC_USAGE_SW_WRITE_NEVER = 0x00000000,
/* buffer is rarely written in software */
GRALLOC_USAGE_SW_WRITE_RARELY = 0x00000020,
/* buffer is often written in software */
GRALLOC_USAGE_SW_WRITE_OFTEN = 0x00000030,
/* mask for the software write values */
GRALLOC_USAGE_SW_WRITE_MASK = 0x000000F0,
/* buffer will be used as an OpenGL ES texture */
GRALLOC_USAGE_HW_TEXTURE = 0x00000100,
/* buffer will be used as an OpenGL ES render target */
GRALLOC_USAGE_HW_RENDER = 0x00000200,
/* buffer will be used by the 2D hardware blitter */
GRALLOC_USAGE_HW_2D = 0x00000400,
/* buffer will be used by the HWComposer HAL module */
GRALLOC_USAGE_HW_COMPOSER = 0x00000800,
/* buffer will be used with the framebuffer device */
GRALLOC_USAGE_HW_FB = 0x00001000,
/* buffer should be displayed full-screen on an external display when
* possible */
GRALLOC_USAGE_EXTERNAL_DISP = 0x00002000,
/* Must have a hardware-protected path to external display sink for
* this buffer. If a hardware-protected path is not available, then
* either don't composite only this buffer (preferred) to the
* external sink, or (less desirable) do not route the entire
* composition to the external sink. */
GRALLOC_USAGE_PROTECTED = 0x00004000,
/* buffer may be used as a cursor */
GRALLOC_USAGE_CURSOR = 0x00008000,
/* buffer will be used with the HW video encoder */
GRALLOC_USAGE_HW_VIDEO_ENCODER = 0x00010000,
/* buffer will be written by the HW camera pipeline */
GRALLOC_USAGE_HW_CAMERA_WRITE = 0x00020000,
/* buffer will be read by the HW camera pipeline */
GRALLOC_USAGE_HW_CAMERA_READ = 0x00040000,
/* buffer will be used as part of zero-shutter-lag queue */
GRALLOC_USAGE_HW_CAMERA_ZSL = 0x00060000,
/* mask for the camera access values */
GRALLOC_USAGE_HW_CAMERA_MASK = 0x00060000,
/* mask for the software usage bit-mask */
GRALLOC_USAGE_HW_MASK = 0x00071F00,
/* buffer will be used as a RenderScript Allocation */
GRALLOC_USAGE_RENDERSCRIPT = 0x00100000,
/* Set by the consumer to indicate to the producer that they may attach a
* buffer that they did not detach from the BufferQueue. Will be filtered
* out by GRALLOC_USAGE_ALLOC_MASK, so gralloc modules will not need to
* handle this flag. */
GRALLOC_USAGE_FOREIGN_BUFFERS = 0x00200000,
/* Mask of all flags which could be passed to a gralloc module for buffer
* allocation. Any flags not in this mask do not need to be handled by
* gralloc modules. */
GRALLOC_USAGE_ALLOC_MASK = ~(GRALLOC_USAGE_FOREIGN_BUFFERS),
/* implementation-specific private usage flags */
GRALLOC_USAGE_PRIVATE_0 = 0x10000000,
GRALLOC_USAGE_PRIVATE_1 = 0x20000000,
GRALLOC_USAGE_PRIVATE_2 = 0x40000000,
GRALLOC_USAGE_PRIVATE_3 = 0x80000000,
GRALLOC_USAGE_PRIVATE_MASK = 0xF0000000,
#ifdef EXYNOS4_ENHANCEMENTS
/* SAMSUNG */
GRALLOC_USAGE_PRIVATE_NONECACHE = 0x00800000,
GRALLOC_USAGE_HW_FIMC1 = 0x01000000,
GRALLOC_USAGE_HW_ION = 0x02000000,
GRALLOC_USAGE_YUV_ADDR = 0x04000000,
GRALLOC_USAGE_CAMERA = 0x08000000,
/* SEC Private usage , for Overlay path at HWC */
GRALLOC_USAGE_HWC_HWOVERLAY = 0x20000000,
#endif
};
/*****************************************************************************/
/**
* 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.
*/
typedef struct gralloc_module_t {
struct hw_module_t common;
/*
* (*registerBuffer)() must be called before a buffer_handle_t that has not
* been created with (*alloc_device_t::alloc)() can be used.
*
* This is intended to be used with buffer_handle_t's that have been
* received in this process through IPC.
*
* This function checks that the handle is indeed a valid one and prepares
* it for use with (*lock)() and (*unlock)().
*
* It is not necessary to call (*registerBuffer)() on a handle created
* with (*alloc_device_t::alloc)().
*
* returns an error if this buffer_handle_t is not valid.
*/
int (*registerBuffer)(struct gralloc_module_t const* module,
buffer_handle_t handle);
/*
* (*unregisterBuffer)() is called once this handle is no longer needed in
* this process. After this call, it is an error to call (*lock)(),
* (*unlock)(), or (*registerBuffer)().
*
* This function doesn't close or free the handle itself; this is done
* by other means, usually through libcutils's native_handle_close() and
* native_handle_free().
*
* It is an error to call (*unregisterBuffer)() on a buffer that wasn't
* explicitly registered first.
*/
int (*unregisterBuffer)(struct gralloc_module_t const* module,
buffer_handle_t handle);
/*
* The (*lock)() method is called before a buffer is accessed for the
* specified usage. This call may block, for instance if the h/w needs
* to finish rendering or if CPU caches need to be synchronized.
*
* The caller promises to modify only pixels in the area specified
* by (l,t,w,h).
*
* The content of the buffer outside of the specified area is NOT modified
* by this call.
*
* If usage specifies GRALLOC_USAGE_SW_*, vaddr is filled with the address
* of the buffer in virtual memory.
*
* Note calling (*lock)() on HAL_PIXEL_FORMAT_YCbCr_*_888 buffers will fail
* and return -EINVAL. These buffers must be locked with (*lock_ycbcr)()
* instead.
*
* THREADING CONSIDERATIONS:
*
* It is legal for several different threads to lock a buffer from
* read access, none of the threads are blocked.
*
* However, locking a buffer simultaneously for write or read/write is
* undefined, but:
* - shall not result in termination of the process
* - shall not block the caller
* It is acceptable to return an error or to leave the buffer's content
* into an indeterminate state.
*
* If the buffer was created with a usage mask incompatible with the
* requested usage flags here, -EINVAL is returned.
*
*/
int (*lock)(struct gralloc_module_t const* module,
buffer_handle_t handle, int usage,
int l, int t, int w, int h,
void** vaddr);
/*
* The (*unlock)() method must be called after all changes to the buffer
* are completed.
*/
int (*unlock)(struct gralloc_module_t const* module,
buffer_handle_t handle);
#ifdef EXYNOS4_ENHANCEMENTS
int (*getphys) (struct gralloc_module_t const* module,
buffer_handle_t handle, void** paddr);
#endif
/* reserved for future use */
int (*perform)(struct gralloc_module_t const* module,
int operation, ... );
/*
* The (*lock_ycbcr)() method is like the (*lock)() method, with the
* difference that it fills a struct ycbcr with a description of the buffer
* layout, and zeroes out the reserved fields.
*
* If the buffer format is not compatible with a flexible YUV format (e.g.
* the buffer layout cannot be represented with the ycbcr struct), it
* will return -EINVAL.
*
* This method must work on buffers with HAL_PIXEL_FORMAT_YCbCr_*_888
* if supported by the device, as well as with any other format that is
* requested by the multimedia codecs when they are configured with a
* flexible-YUV-compatible color-format with android native buffers.
*
* Note that this method may also be called on buffers of other formats,
* including non-YUV formats.
*
* Added in GRALLOC_MODULE_API_VERSION_0_2.
*/
int (*lock_ycbcr)(struct gralloc_module_t const* module,
buffer_handle_t handle, int usage,
int l, int t, int w, int h,
struct android_ycbcr *ycbcr);
/*
* The (*lockAsync)() method is like the (*lock)() method except
* that the buffer's sync fence object is passed into the lock
* call instead of requiring the caller to wait for completion.
*
* The gralloc implementation takes ownership of the fenceFd and
* is responsible for closing it when no longer needed.
*
* Added in GRALLOC_MODULE_API_VERSION_0_3.
*/
int (*lockAsync)(struct gralloc_module_t const* module,
buffer_handle_t handle, int usage,
int l, int t, int w, int h,
void** vaddr, int fenceFd);
/*
* The (*unlockAsync)() method is like the (*unlock)() method
* except that a buffer sync fence object is returned from the
* lock call, representing the completion of any pending work
* performed by the gralloc implementation.
*
* The caller takes ownership of the fenceFd and is responsible
* for closing it when no longer needed.
*
* Added in GRALLOC_MODULE_API_VERSION_0_3.
*/
int (*unlockAsync)(struct gralloc_module_t const* module,
buffer_handle_t handle, int* fenceFd);
/*
* The (*lockAsync_ycbcr)() method is like the (*lock_ycbcr)()
* method except that the buffer's sync fence object is passed
* into the lock call instead of requiring the caller to wait for
* completion.
*
* The gralloc implementation takes ownership of the fenceFd and
* is responsible for closing it when no longer needed.
*
* Added in GRALLOC_MODULE_API_VERSION_0_3.
*/
int (*lockAsync_ycbcr)(struct gralloc_module_t const* module,
buffer_handle_t handle, int usage,
int l, int t, int w, int h,
struct android_ycbcr *ycbcr, int fenceFd);
/* reserved for future use */
void* reserved_proc[3];
} gralloc_module_t;
/*****************************************************************************/
/**
* Every device data structure must begin with hw_device_t
* followed by module specific public methods and attributes.
*/
typedef struct alloc_device_t {
struct hw_device_t common;
/*
* (*alloc)() Allocates a buffer in graphic memory with the requested
* parameters and returns a buffer_handle_t and the stride in pixels to
* allow the implementation to satisfy hardware constraints on the width
* of a pixmap (eg: it may have to be multiple of 8 pixels).
* The CALLER TAKES OWNERSHIP of the buffer_handle_t.
*
* If format is HAL_PIXEL_FORMAT_YCbCr_420_888, the returned stride must be
* 0, since the actual strides are available from the android_ycbcr
* structure.
*
* Returns 0 on success or -errno on error.
*/
int (*alloc)(struct alloc_device_t* dev,
int w, int h, int format, int usage,
buffer_handle_t* handle, int* stride);
/*
* (*free)() Frees a previously allocated buffer.
* Behavior is undefined if the buffer is still mapped in any process,
* but shall not result in termination of the program or security breaches
* (allowing a process to get access to another process' buffers).
* THIS FUNCTION TAKES OWNERSHIP of the buffer_handle_t which becomes
* invalid after the call.
*
* Returns 0 on success or -errno on error.
*/
int (*free)(struct alloc_device_t* dev,
buffer_handle_t handle);
/* This hook is OPTIONAL.
*
* If non NULL it will be caused by SurfaceFlinger on dumpsys
*/
void (*dump)(struct alloc_device_t *dev, char *buff, int buff_len);
void* reserved_proc[7];
} alloc_device_t;
/** convenience API for opening and closing a supported device */
static inline int gralloc_open(const struct hw_module_t* module,
struct alloc_device_t** device) {
return module->methods->open(module,
GRALLOC_HARDWARE_GPU0, (struct hw_device_t**)device);
}
static inline int gralloc_close(struct alloc_device_t* device) {
return device->common.close(&device->common);
}
__END_DECLS
#endif // ANDROID_GRALLOC_INTERFACE_H
@@ -0,0 +1,238 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_INCLUDE_HARDWARE_HARDWARE_H
#define ANDROID_INCLUDE_HARDWARE_HARDWARE_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <cutils/native_handle.h>
#include <system/graphics.h>
__BEGIN_DECLS
/*
* Value for the hw_module_t.tag field
*/
#define MAKE_TAG_CONSTANT(A,B,C,D) (((A) << 24) | ((B) << 16) | ((C) << 8) | (D))
#define HARDWARE_MODULE_TAG MAKE_TAG_CONSTANT('H', 'W', 'M', 'T')
#define HARDWARE_DEVICE_TAG MAKE_TAG_CONSTANT('H', 'W', 'D', 'T')
#define HARDWARE_MAKE_API_VERSION(maj,min) \
((((maj) & 0xff) << 8) | ((min) & 0xff))
#define HARDWARE_MAKE_API_VERSION_2(maj,min,hdr) \
((((maj) & 0xff) << 24) | (((min) & 0xff) << 16) | ((hdr) & 0xffff))
#define HARDWARE_API_VERSION_2_MAJ_MIN_MASK 0xffff0000
#define HARDWARE_API_VERSION_2_HEADER_MASK 0x0000ffff
/*
* The current HAL API version.
*
* All module implementations must set the hw_module_t.hal_api_version field
* to this value when declaring the module with HAL_MODULE_INFO_SYM.
*
* Note that previous implementations have always set this field to 0.
* Therefore, libhardware HAL API will always consider versions 0.0 and 1.0
* to be 100% binary compatible.
*
*/
#define HARDWARE_HAL_API_VERSION HARDWARE_MAKE_API_VERSION(1, 0)
/*
* Helper macros for module implementors.
*
* The derived modules should provide convenience macros for supported
* versions so that implementations can explicitly specify module/device
* versions at definition time.
*
* Use this macro to set the hw_module_t.module_api_version field.
*/
#define HARDWARE_MODULE_API_VERSION(maj,min) HARDWARE_MAKE_API_VERSION(maj,min)
#define HARDWARE_MODULE_API_VERSION_2(maj,min,hdr) HARDWARE_MAKE_API_VERSION_2(maj,min,hdr)
/*
* Use this macro to set the hw_device_t.version field
*/
#define HARDWARE_DEVICE_API_VERSION(maj,min) HARDWARE_MAKE_API_VERSION(maj,min)
#define HARDWARE_DEVICE_API_VERSION_2(maj,min,hdr) HARDWARE_MAKE_API_VERSION_2(maj,min,hdr)
struct hw_module_t;
struct hw_module_methods_t;
struct hw_device_t;
/**
* 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.
*/
typedef struct hw_module_t {
/** tag must be initialized to HARDWARE_MODULE_TAG */
uint32_t tag;
/**
* The API version of the implemented module. The module owner is
* responsible for updating the version when a module interface has
* changed.
*
* The derived modules such as gralloc and audio own and manage this field.
* The module user must interpret the version field to decide whether or
* not to inter-operate with the supplied module implementation.
* For example, SurfaceFlinger is responsible for making sure that
* it knows how to manage different versions of the gralloc-module API,
* and AudioFlinger must know how to do the same for audio-module API.
*
* The module API version should include a major and a minor component.
* For example, version 1.0 could be represented as 0x0100. This format
* implies that versions 0x0100-0x01ff are all API-compatible.
*
* In the future, libhardware will expose a hw_get_module_version()
* (or equivalent) function that will take minimum/maximum supported
* versions as arguments and would be able to reject modules with
* versions outside of the supplied range.
*/
uint16_t module_api_version;
#define version_major module_api_version
/**
* version_major/version_minor defines are supplied here for temporary
* source code compatibility. They will be removed in the next version.
* ALL clients must convert to the new version format.
*/
/**
* The API version of the HAL module interface. This is meant to
* version the hw_module_t, hw_module_methods_t, and hw_device_t
* structures and definitions.
*
* The HAL interface owns this field. Module users/implementations
* must NOT rely on this value for version information.
*
* Presently, 0 is the only valid value.
*/
uint16_t hal_api_version;
#define version_minor hal_api_version
/** Identifier of module */
const char *id;
/** Name of this module */
const char *name;
/** Author/owner/implementor of the module */
const char *author;
/** Modules methods */
struct hw_module_methods_t* methods;
/** module's dso */
void* dso;
#ifdef __LP64__
uint64_t reserved[32-7];
#else
/** padding to 128 bytes, reserved for future use */
uint32_t reserved[32-7];
#endif
} hw_module_t;
typedef struct hw_module_methods_t {
/** Open a specific device */
int (*open)(const struct hw_module_t* module, const char* id,
struct hw_device_t** device);
} hw_module_methods_t;
/**
* Every device data structure must begin with hw_device_t
* followed by module specific public methods and attributes.
*/
typedef struct hw_device_t {
/** tag must be initialized to HARDWARE_DEVICE_TAG */
uint32_t tag;
/**
* Version of the module-specific device API. This value is used by
* the derived-module user to manage different device implementations.
*
* The module user is responsible for checking the module_api_version
* and device version fields to ensure that the user is capable of
* communicating with the specific module implementation.
*
* One module can support multiple devices with different versions. This
* can be useful when a device interface changes in an incompatible way
* but it is still necessary to support older implementations at the same
* time. One such example is the Camera 2.0 API.
*
* This field is interpreted by the module user and is ignored by the
* HAL interface itself.
*/
uint32_t version;
/** reference to the module this device belongs to */
struct hw_module_t* module;
/** padding reserved for future use */
#ifdef __LP64__
uint64_t reserved[12];
#else
uint32_t reserved[12];
#endif
/** Close this device */
int (*close)(struct hw_device_t* device);
} hw_device_t;
/**
* Name of the hal_module_info
*/
#define HAL_MODULE_INFO_SYM HMI
/**
* Name of the hal_module_info as a string
*/
#define HAL_MODULE_INFO_SYM_AS_STR "HMI"
/**
* Get the module info associated with a module by id.
*
* @return: 0 == success, <0 == error and *module == NULL
*/
int hw_get_module(const char *id, const struct hw_module_t **module);
/**
* Get the module info associated with a module instance by class 'class_id'
* and instance 'inst'.
*
* Some modules types necessitate multiple instances. For example audio supports
* multiple concurrent interfaces and thus 'audio' is the module class
* and 'primary' or 'a2dp' are module interfaces. This implies that the files
* providing these modules would be named audio.primary.<variant>.so and
* audio.a2dp.<variant>.so
*
* @return: 0 == success, <0 == error and *module == NULL
*/
int hw_get_module_by_class(const char *class_id, const char *inst,
const struct hw_module_t **module);
__END_DECLS
#endif /* ANDROID_INCLUDE_HARDWARE_HARDWARE_H */
@@ -0,0 +1,429 @@
/*
* 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_INCLUDE_HARDWARE_HDMI_CEC_H
#define ANDROID_INCLUDE_HARDWARE_HDMI_CEC_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <hardware/hardware.h>
__BEGIN_DECLS
#define HDMI_CEC_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
#define HDMI_CEC_MODULE_API_VERSION_CURRENT HDMI_MODULE_API_VERSION_1_0
#define HDMI_CEC_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
#define HDMI_CEC_DEVICE_API_VERSION_CURRENT HDMI_DEVICE_API_VERSION_1_0
#define HDMI_CEC_HARDWARE_MODULE_ID "hdmi_cec"
#define HDMI_CEC_HARDWARE_INTERFACE "hdmi_cec_hw_if"
typedef enum cec_device_type {
CEC_DEVICE_INACTIVE = -1,
CEC_DEVICE_TV = 0,
CEC_DEVICE_RECORDER = 1,
CEC_DEVICE_RESERVED = 2,
CEC_DEVICE_TUNER = 3,
CEC_DEVICE_PLAYBACK = 4,
CEC_DEVICE_AUDIO_SYSTEM = 5,
CEC_DEVICE_MAX = CEC_DEVICE_AUDIO_SYSTEM
} cec_device_type_t;
typedef enum cec_logical_address {
CEC_ADDR_TV = 0,
CEC_ADDR_RECORDER_1 = 1,
CEC_ADDR_RECORDER_2 = 2,
CEC_ADDR_TUNER_1 = 3,
CEC_ADDR_PLAYBACK_1 = 4,
CEC_ADDR_AUDIO_SYSTEM = 5,
CEC_ADDR_TUNER_2 = 6,
CEC_ADDR_TUNER_3 = 7,
CEC_ADDR_PLAYBACK_2 = 8,
CEC_ADDR_RECORDER_3 = 9,
CEC_ADDR_TUNER_4 = 10,
CEC_ADDR_PLAYBACK_3 = 11,
CEC_ADDR_RESERVED_1 = 12,
CEC_ADDR_RESERVED_2 = 13,
CEC_ADDR_FREE_USE = 14,
CEC_ADDR_UNREGISTERED = 15,
CEC_ADDR_BROADCAST = 15
} cec_logical_address_t;
/*
* HDMI CEC messages
*/
enum cec_message_type {
CEC_MESSAGE_FEATURE_ABORT = 0x00,
CEC_MESSAGE_IMAGE_VIEW_ON = 0x04,
CEC_MESSAGE_TUNER_STEP_INCREMENT = 0x05,
CEC_MESSAGE_TUNER_STEP_DECREMENT = 0x06,
CEC_MESSAGE_TUNER_DEVICE_STATUS = 0x07,
CEC_MESSAGE_GIVE_TUNER_DEVICE_STATUS = 0x08,
CEC_MESSAGE_RECORD_ON = 0x09,
CEC_MESSAGE_RECORD_STATUS = 0x0A,
CEC_MESSAGE_RECORD_OFF = 0x0B,
CEC_MESSAGE_TEXT_VIEW_ON = 0x0D,
CEC_MESSAGE_RECORD_TV_SCREEN = 0x0F,
CEC_MESSAGE_GIVE_DECK_STATUS = 0x1A,
CEC_MESSAGE_DECK_STATUS = 0x1B,
CEC_MESSAGE_SET_MENU_LANGUAGE = 0x32,
CEC_MESSAGE_CLEAR_ANALOG_TIMER = 0x33,
CEC_MESSAGE_SET_ANALOG_TIMER = 0x34,
CEC_MESSAGE_TIMER_STATUS = 0x35,
CEC_MESSAGE_STANDBY = 0x36,
CEC_MESSAGE_PLAY = 0x41,
CEC_MESSAGE_DECK_CONTROL = 0x42,
CEC_MESSAGE_TIMER_CLEARED_STATUS = 0x043,
CEC_MESSAGE_USER_CONTROL_PRESSED = 0x44,
CEC_MESSAGE_USER_CONTROL_RELEASED = 0x45,
CEC_MESSAGE_GIVE_OSD_NAME = 0x46,
CEC_MESSAGE_SET_OSD_NAME = 0x47,
CEC_MESSAGE_SET_OSD_STRING = 0x64,
CEC_MESSAGE_SET_TIMER_PROGRAM_TITLE = 0x67,
CEC_MESSAGE_SYSTEM_AUDIO_MODE_REQUEST = 0x70,
CEC_MESSAGE_GIVE_AUDIO_STATUS = 0x71,
CEC_MESSAGE_SET_SYSTEM_AUDIO_MODE = 0x72,
CEC_MESSAGE_REPORT_AUDIO_STATUS = 0x7A,
CEC_MESSAGE_GIVE_SYSTEM_AUDIO_MODE_STATUS = 0x7D,
CEC_MESSAGE_SYSTEM_AUDIO_MODE_STATUS = 0x7E,
CEC_MESSAGE_ROUTING_CHANGE = 0x80,
CEC_MESSAGE_ROUTING_INFORMATION = 0x81,
CEC_MESSAGE_ACTIVE_SOURCE = 0x82,
CEC_MESSAGE_GIVE_PHYSICAL_ADDRESS = 0x83,
CEC_MESSAGE_REPORT_PHYSICAL_ADDRESS = 0x84,
CEC_MESSAGE_REQUEST_ACTIVE_SOURCE = 0x85,
CEC_MESSAGE_SET_STREAM_PATH = 0x86,
CEC_MESSAGE_DEVICE_VENDOR_ID = 0x87,
CEC_MESSAGE_VENDOR_COMMAND = 0x89,
CEC_MESSAGE_VENDOR_REMOTE_BUTTON_DOWN = 0x8A,
CEC_MESSAGE_VENDOR_REMOTE_BUTTON_UP = 0x8B,
CEC_MESSAGE_GIVE_DEVICE_VENDOR_ID = 0x8C,
CEC_MESSAGE_MENU_REQUEST = 0x8D,
CEC_MESSAGE_MENU_STATUS = 0x8E,
CEC_MESSAGE_GIVE_DEVICE_POWER_STATUS = 0x8F,
CEC_MESSAGE_REPORT_POWER_STATUS = 0x90,
CEC_MESSAGE_GET_MENU_LANGUAGE = 0x91,
CEC_MESSAGE_SELECT_ANALOG_SERVICE = 0x92,
CEC_MESSAGE_SELECT_DIGITAL_SERVICE = 0x93,
CEC_MESSAGE_SET_DIGITAL_TIMER = 0x97,
CEC_MESSAGE_CLEAR_DIGITAL_TIMER = 0x99,
CEC_MESSAGE_SET_AUDIO_RATE = 0x9A,
CEC_MESSAGE_INACTIVE_SOURCE = 0x9D,
CEC_MESSAGE_CEC_VERSION = 0x9E,
CEC_MESSAGE_GET_CEC_VERSION = 0x9F,
CEC_MESSAGE_VENDOR_COMMAND_WITH_ID = 0xA0,
CEC_MESSAGE_CLEAR_EXTERNAL_TIMER = 0xA1,
CEC_MESSAGE_SET_EXTERNAL_TIMER = 0xA2,
CEC_MESSAGE_INITIATE_ARC = 0xC0,
CEC_MESSAGE_REPORT_ARC_INITIATED = 0xC1,
CEC_MESSAGE_REPORT_ARC_TERMINATED = 0xC2,
CEC_MESSAGE_REQUEST_ARC_INITIATION = 0xC3,
CEC_MESSAGE_REQUEST_ARC_TERMINATION = 0xC4,
CEC_MESSAGE_TERMINATE_ARC = 0xC5,
CEC_MESSAGE_ABORT = 0xFF
};
/*
* Operand description [Abort Reason]
*/
enum abort_reason {
ABORT_UNRECOGNIZED_MODE = 0,
ABORT_NOT_IN_CORRECT_MODE = 1,
ABORT_CANNOT_PROVIDE_SOURCE = 2,
ABORT_INVALID_OPERAND = 3,
ABORT_REFUSED = 4,
ABORT_UNABLE_TO_DETERMINE = 5
};
/*
* HDMI event type. used for hdmi_event_t.
*/
enum {
HDMI_EVENT_CEC_MESSAGE = 1,
HDMI_EVENT_HOT_PLUG = 2,
};
/*
* HDMI hotplug event type. Used when the event
* type is HDMI_EVENT_HOT_PLUG.
*/
enum {
HDMI_NOT_CONNECTED = 0,
HDMI_CONNECTED = 1
};
/*
* error code used for send_message.
*/
enum {
HDMI_RESULT_SUCCESS = 0,
HDMI_RESULT_NACK = 1, /* not acknowledged */
HDMI_RESULT_BUSY = 2, /* bus is busy */
HDMI_RESULT_FAIL = 3,
};
/*
* HDMI port type.
*/
typedef enum hdmi_port_type {
HDMI_INPUT = 0,
HDMI_OUTPUT = 1
} hdmi_port_type_t;
/*
* Flags used for set_option()
*/
enum {
/* When set to false, HAL does not wake up the system upon receiving
* <Image View On> or <Text View On>. Used when user changes the TV
* settings to disable the auto TV on functionality.
* True by default.
*/
HDMI_OPTION_WAKEUP = 1,
/* When set to false, all the CEC commands are discarded. Used when
* user changes the TV settings to disable CEC functionality.
* True by default.
*/
HDMI_OPTION_ENABLE_CEC = 2,
/* Setting this flag to false means Android system will stop handling
* CEC service and yield the control over to the microprocessor that is
* powered on through the standby mode. When set to true, the system
* will gain the control over, hence telling the microprocessor to stop
* handling the cec commands. This is called when system goes
* in and out of standby mode to notify the microprocessor that it should
* start/stop handling CEC commands on behalf of the system.
* False by default.
*/
HDMI_OPTION_SYSTEM_CEC_CONTROL = 3,
/* Option 4 not used */
/* Passes the updated language information of Android system.
* Contains 3-byte ASCII code as defined in ISO/FDIS 639-2. Can be
* used for HAL to respond to <Get Menu Language> while in standby mode.
* English(eng), for example, is converted to 0x656e67.
*/
HDMI_OPTION_SET_LANG = 5,
};
/*
* Maximum length in bytes of cec message body (exclude header block),
* should not exceed 16 (spec CEC 6 Frame Description)
*/
#define CEC_MESSAGE_BODY_MAX_LENGTH 16
typedef struct cec_message {
/* logical address of sender */
cec_logical_address_t initiator;
/* logical address of receiver */
cec_logical_address_t destination;
/* Length in bytes of body, range [0, CEC_MESSAGE_BODY_MAX_LENGTH] */
size_t length;
unsigned char body[CEC_MESSAGE_BODY_MAX_LENGTH];
} cec_message_t;
typedef struct hotplug_event {
/*
* true if the cable is connected; otherwise false.
*/
int connected;
int port_id;
} hotplug_event_t;
typedef struct tx_status_event {
int status;
int opcode; /* CEC opcode */
} tx_status_event_t;
/*
* HDMI event generated from HAL.
*/
typedef struct hdmi_event {
int type;
struct hdmi_cec_device* dev;
union {
cec_message_t cec;
hotplug_event_t hotplug;
};
} hdmi_event_t;
/*
* HDMI port descriptor
*/
typedef struct hdmi_port_info {
hdmi_port_type_t type;
// Port ID should start from 1 which corresponds to HDMI "port 1".
int port_id;
int cec_supported;
int arc_supported;
uint16_t physical_address;
} hdmi_port_info_t;
/*
* Callback function type that will be called by HAL implementation.
* Services can not close/open the device in the callback.
*/
typedef void (*event_callback_t)(const hdmi_event_t* event, void* arg);
typedef struct hdmi_cec_module {
/**
* Common methods of the HDMI CEC module. This *must* be the first member of
* hdmi_cec_module as users of this structure will cast a hw_module_t to hdmi_cec_module
* pointer in contexts where it's known the hw_module_t references a hdmi_cec_module.
*/
struct hw_module_t common;
} hdmi_module_t;
/*
* HDMI-CEC HAL interface definition.
*/
typedef struct hdmi_cec_device {
/**
* Common methods of the HDMI CEC device. This *must* be the first member of
* hdmi_cec_device as users of this structure will cast a hw_device_t to hdmi_cec_device
* pointer in contexts where it's known the hw_device_t references a hdmi_cec_device.
*/
struct hw_device_t common;
/*
* (*add_logical_address)() passes the logical address that will be used
* in this system.
*
* HAL may use it to configure the hardware so that the CEC commands addressed
* the given logical address can be filtered in. This method can be called
* as many times as necessary in order to support multiple logical devices.
* addr should be in the range of valid logical addresses for the call
* to succeed.
*
* Returns 0 on success or -errno on error.
*/
int (*add_logical_address)(const struct hdmi_cec_device* dev, cec_logical_address_t addr);
/*
* (*clear_logical_address)() tells HAL to reset all the logical addresses.
*
* It is used when the system doesn't need to process CEC command any more,
* hence to tell HAL to stop receiving commands from the CEC bus, and change
* the state back to the beginning.
*/
void (*clear_logical_address)(const struct hdmi_cec_device* dev);
/*
* (*get_physical_address)() returns the CEC physical address. The
* address is written to addr.
*
* The physical address depends on the topology of the network formed
* by connected HDMI devices. It is therefore likely to change if the cable
* is plugged off and on again. It is advised to call get_physical_address
* to get the updated address when hot plug event takes place.
*
* Returns 0 on success or -errno on error.
*/
int (*get_physical_address)(const struct hdmi_cec_device* dev, uint16_t* addr);
/*
* (*send_message)() transmits HDMI-CEC message to other HDMI device.
*
* The method should be designed to return in a certain amount of time not
* hanging forever, which can happen if CEC signal line is pulled low for
* some reason. HAL implementation should take the situation into account
* so as not to wait forever for the message to get sent out.
*
* It should try retransmission at least once as specified in the standard.
*
* Returns error code. See HDMI_RESULT_SUCCESS, HDMI_RESULT_NACK, and
* HDMI_RESULT_BUSY.
*/
int (*send_message)(const struct hdmi_cec_device* dev, const cec_message_t*);
/*
* (*register_event_callback)() registers a callback that HDMI-CEC HAL
* can later use for incoming CEC messages or internal HDMI events.
* When calling from C++, use the argument arg to pass the calling object.
* It will be passed back when the callback is invoked so that the context
* can be retrieved.
*/
void (*register_event_callback)(const struct hdmi_cec_device* dev,
event_callback_t callback, void* arg);
/*
* (*get_version)() returns the CEC version supported by underlying hardware.
*/
void (*get_version)(const struct hdmi_cec_device* dev, int* version);
/*
* (*get_vendor_id)() returns the identifier of the vendor. It is
* the 24-bit unique company ID obtained from the IEEE Registration
* Authority Committee (RAC).
*/
void (*get_vendor_id)(const struct hdmi_cec_device* dev, uint32_t* vendor_id);
/*
* (*get_port_info)() returns the hdmi port information of underlying hardware.
* info is the list of HDMI port information, and 'total' is the number of
* HDMI ports in the system.
*/
void (*get_port_info)(const struct hdmi_cec_device* dev,
struct hdmi_port_info* list[], int* total);
/*
* (*set_option)() passes flags controlling the way HDMI-CEC service works down
* to HAL implementation. Those flags will be used in case the feature needs
* update in HAL itself, firmware or microcontroller.
*/
void (*set_option)(const struct hdmi_cec_device* dev, int flag, int value);
/*
* (*set_audio_return_channel)() configures ARC circuit in the hardware logic
* to start or stop the feature. Flag can be either 1 to start the feature
* or 0 to stop it.
*
* Returns 0 on success or -errno on error.
*/
void (*set_audio_return_channel)(const struct hdmi_cec_device* dev, int port_id, int flag);
/*
* (*is_connected)() returns the connection status of the specified port.
* Returns HDMI_CONNECTED if a device is connected, otherwise HDMI_NOT_CONNECTED.
* The HAL should watch for +5V power signal to determine the status.
*/
int (*is_connected)(const struct hdmi_cec_device* dev, int port_id);
/* Reserved for future use to maximum 16 functions. Must be NULL. */
void* reserved[16 - 11];
} hdmi_cec_device_t;
/** convenience API for opening and closing a device */
static inline int hdmi_cec_open(const struct hw_module_t* module,
struct hdmi_cec_device** device) {
return module->methods->open(module,
HDMI_CEC_HARDWARE_INTERFACE, (struct hw_device_t**)device);
}
static inline int hdmi_cec_close(struct hdmi_cec_device* device) {
return device->common.close(&device->common);
}
__END_DECLS
#endif /* ANDROID_INCLUDE_HARDWARE_HDMI_CEC_H */
@@ -0,0 +1,53 @@
/*
* 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
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
const uint8_t HW_AUTH_TOKEN_VERSION = 0;
typedef enum {
HW_AUTH_NONE = 0,
HW_AUTH_PASSWORD = 1 << 0,
HW_AUTH_FINGERPRINT = 1 << 1,
// 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
uint64_t timestamp; // in network order
uint8_t hmac[32];
} hw_auth_token_t;
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif // ANDROID_HARDWARE_HW_AUTH_TOKEN_H
@@ -0,0 +1,833 @@
/*
* Copyright (C) 2010 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_HWCOMPOSER_H
#define ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <hardware/gralloc.h>
#include <hardware/hardware.h>
#include <cutils/native_handle.h>
#include <hardware/hwcomposer_defs.h>
__BEGIN_DECLS
/*****************************************************************************/
/* for compatibility */
#define HWC_MODULE_API_VERSION HWC_MODULE_API_VERSION_0_1
#define HWC_DEVICE_API_VERSION HWC_DEVICE_API_VERSION_0_1
#define HWC_API_VERSION HWC_DEVICE_API_VERSION
/*****************************************************************************/
/**
* The id of this module
*/
#define HWC_HARDWARE_MODULE_ID "hwcomposer"
/**
* Name of the sensors device to open
*/
#define HWC_HARDWARE_COMPOSER "composer"
typedef struct hwc_rect {
int left;
int top;
int right;
int bottom;
} hwc_rect_t;
typedef struct hwc_frect {
float left;
float top;
float right;
float bottom;
} hwc_frect_t;
typedef struct hwc_region {
size_t numRects;
hwc_rect_t const* rects;
} hwc_region_t;
typedef struct hwc_color {
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t a;
} hwc_color_t;
typedef struct hwc_layer_1 {
/*
* compositionType is used to specify this layer's type and is set by either
* the hardware composer implementation, or by the caller (see below).
*
* This field is always reset to HWC_BACKGROUND or HWC_FRAMEBUFFER
* before (*prepare)() is called when the HWC_GEOMETRY_CHANGED flag is
* also set, otherwise, this field is preserved between (*prepare)()
* calls.
*
* HWC_BACKGROUND
* Always set by the caller before calling (*prepare)(), this value
* indicates this is a special "background" layer. The only valid field
* is backgroundColor.
* The HWC can toggle this value to HWC_FRAMEBUFFER to indicate it CANNOT
* handle the background color.
*
*
* HWC_FRAMEBUFFER_TARGET
* Always set by the caller before calling (*prepare)(), this value
* indicates this layer is the framebuffer surface used as the target of
* OpenGL ES composition. If the HWC sets all other layers to HWC_OVERLAY
* or HWC_BACKGROUND, then no OpenGL ES composition will be done, and
* this layer should be ignored during set().
*
* This flag (and the framebuffer surface layer) will only be used if the
* HWC version is HWC_DEVICE_API_VERSION_1_1 or higher. In older versions,
* the OpenGL ES target surface is communicated by the (dpy, sur) fields
* in hwc_compositor_device_1_t.
*
* This value cannot be set by the HWC implementation.
*
*
* HWC_FRAMEBUFFER
* Set by the caller before calling (*prepare)() ONLY when the
* HWC_GEOMETRY_CHANGED flag is also set.
*
* Set by the HWC implementation during (*prepare)(), this indicates
* that the layer will be drawn into the framebuffer using OpenGL ES.
* The HWC can toggle this value to HWC_OVERLAY to indicate it will
* handle the layer.
*
*
* HWC_OVERLAY
* Set by the HWC implementation during (*prepare)(), this indicates
* that the layer will be handled by the HWC (ie: it must not be
* composited with OpenGL ES).
*
*
* HWC_SIDEBAND
* Set by the caller before calling (*prepare)(), this value indicates
* the contents of this layer come from a sideband video stream.
*
* The h/w composer is responsible for receiving new image buffers from
* the stream at the appropriate time (e.g. synchronized to a separate
* audio stream), compositing them with the current contents of other
* layers, and displaying the resulting image. This happens
* independently of the normal prepare/set cycle. The prepare/set calls
* only happen when other layers change, or when properties of the
* sideband layer such as position or size change.
*
* If the h/w composer can't handle the layer as a sideband stream for
* some reason (e.g. unsupported scaling/blending/rotation, or too many
* sideband layers) it can set compositionType to HWC_FRAMEBUFFER in
* (*prepare)(). However, doing so will result in the layer being shown
* as a solid color since the platform is not currently able to composite
* sideband layers with the GPU. This may be improved in future
* versions of the platform.
*
*
* HWC_CURSOR_OVERLAY
* Set by the HWC implementation during (*prepare)(), this value
* indicates the layer's composition will now be handled by the HWC.
* Additionally, the client can now asynchronously update the on-screen
* position of this layer using the setCursorPositionAsync() api.
*/
int32_t compositionType;
/*
* hints is bit mask set by the HWC implementation during (*prepare)().
* It is preserved between (*prepare)() calls, unless the
* HWC_GEOMETRY_CHANGED flag is set, in which case it is reset to 0.
*
* see hwc_layer_t::hints
*/
uint32_t hints;
/* see hwc_layer_t::flags */
uint32_t flags;
union {
/* color of the background. hwc_color_t.a is ignored */
hwc_color_t backgroundColor;
struct {
union {
/* When compositionType is HWC_FRAMEBUFFER, HWC_OVERLAY,
* HWC_FRAMEBUFFER_TARGET, this is the handle of the buffer to
* compose. This handle is guaranteed to have been allocated
* from gralloc using the GRALLOC_USAGE_HW_COMPOSER usage flag.
* If the layer's handle is unchanged across two consecutive
* prepare calls and the HWC_GEOMETRY_CHANGED flag is not set
* for the second call then the HWComposer implementation may
* assume that the contents of the buffer have not changed. */
buffer_handle_t handle;
/* When compositionType is HWC_SIDEBAND, this is the handle
* of the sideband video stream to compose. */
const native_handle_t* sidebandStream;
};
/* transformation to apply to the buffer during composition */
uint32_t transform;
/* blending to apply during composition */
int32_t blending;
/* area of the source to consider, the origin is the top-left corner of
* the buffer. As of HWC_DEVICE_API_VERSION_1_3, sourceRect uses floats.
* If the h/w can't support a non-integer source crop rectangle, it should
* punt to OpenGL ES composition.
*/
union {
// crop rectangle in integer (pre HWC_DEVICE_API_VERSION_1_3)
hwc_rect_t sourceCropi;
hwc_rect_t sourceCrop; // just for source compatibility
// crop rectangle in floats (as of HWC_DEVICE_API_VERSION_1_3)
hwc_frect_t sourceCropf;
};
/* where to composite the sourceCrop onto the display. The sourceCrop
* is scaled using linear filtering to the displayFrame. The origin is the
* top-left corner of the screen.
*/
hwc_rect_t displayFrame;
/* visible region in screen space. The origin is the
* top-left corner of the screen.
* The visible region INCLUDES areas overlapped by a translucent layer.
*/
hwc_region_t visibleRegionScreen;
/* Sync fence object that will be signaled when the buffer's
* contents are available. May be -1 if the contents are already
* available. This field is only valid during set(), and should be
* ignored during prepare(). The set() call must not wait for the
* fence to be signaled before returning, but the HWC must wait for
* all buffers to be signaled before reading from them.
*
* HWC_FRAMEBUFFER layers will never have an acquire fence, since
* reads from them are complete before the framebuffer is ready for
* display.
*
* HWC_SIDEBAND layers will never have an acquire fence, since
* synchronization is handled through implementation-defined
* sideband mechanisms.
*
* The HWC takes ownership of the acquireFenceFd and is responsible
* for closing it when no longer needed.
*/
int acquireFenceFd;
/* During set() the HWC must set this field to a file descriptor for
* a sync fence object that will signal after the HWC has finished
* reading from the buffer. The field is ignored by prepare(). Each
* layer should have a unique file descriptor, even if more than one
* refer to the same underlying fence object; this allows each to be
* closed independently.
*
* If buffer reads can complete at significantly different times,
* then using independent fences is preferred. For example, if the
* HWC handles some layers with a blit engine and others with
* overlays, then the blit layers can be reused immediately after
* the blit completes, but the overlay layers can't be reused until
* a subsequent frame has been displayed.
*
* Since HWC doesn't read from HWC_FRAMEBUFFER layers, it shouldn't
* produce a release fence for them. The releaseFenceFd will be -1
* for these layers when set() is called.
*
* Since HWC_SIDEBAND buffers don't pass through the HWC client,
* the HWC shouldn't produce a release fence for them. The
* releaseFenceFd will be -1 for these layers when set() is called.
*
* The HWC client taks ownership of the releaseFenceFd and is
* responsible for closing it when no longer needed.
*/
int releaseFenceFd;
/*
* Availability: HWC_DEVICE_API_VERSION_1_2
*
* Alpha value applied to the whole layer. The effective
* value of each pixel is computed as:
*
* if (blending == HWC_BLENDING_PREMULT)
* pixel.rgb = pixel.rgb * planeAlpha / 255
* pixel.a = pixel.a * planeAlpha / 255
*
* Then blending proceeds as usual according to the "blending"
* field above.
*
* NOTE: planeAlpha applies to YUV layers as well:
*
* pixel.rgb = yuv_to_rgb(pixel.yuv)
* if (blending == HWC_BLENDING_PREMULT)
* pixel.rgb = pixel.rgb * planeAlpha / 255
* pixel.a = planeAlpha
*
*
* IMPLEMENTATION NOTE:
*
* If the source image doesn't have an alpha channel, then
* the h/w can use the HWC_BLENDING_COVERAGE equations instead of
* HWC_BLENDING_PREMULT and simply set the alpha channel to
* planeAlpha.
*
* e.g.:
*
* if (blending == HWC_BLENDING_PREMULT)
* blending = HWC_BLENDING_COVERAGE;
* pixel.a = planeAlpha;
*
*/
uint8_t planeAlpha;
/* Pad to 32 bits */
uint8_t _pad[3];
/*
* Availability: HWC_DEVICE_API_VERSION_1_5
*
* This defines the region of the source buffer that has been
* modified since the last frame.
*
* If surfaceDamage.numRects > 0, then it may be assumed that any
* portion of the source buffer not covered by one of the rects has
* not been modified this frame. If surfaceDamage.numRects == 0,
* then the whole source buffer must be treated as if it had been
* modified.
*
* If the layer's contents are not modified relative to the prior
* prepare/set cycle, surfaceDamage will contain exactly one empty
* rect ([0, 0, 0, 0]).
*
* The damage rects are relative to the pre-transformed buffer, and
* their origin is the top-left corner.
*/
hwc_region_t surfaceDamage;
};
};
#ifdef __LP64__
/*
* For 64-bit mode, this struct is 120 bytes (and 8-byte aligned), and needs
* to be padded as such to maintain binary compatibility.
*/
uint8_t reserved[120 - 112];
#else
/*
* For 32-bit mode, this struct is 96 bytes, and needs to be padded as such
* to maintain binary compatibility.
*/
uint8_t reserved[96 - 84];
#endif
} hwc_layer_1_t;
/* This represents a display, typically an EGLDisplay object */
typedef void* hwc_display_t;
/* This represents a surface, typically an EGLSurface object */
typedef void* hwc_surface_t;
/*
* hwc_display_contents_1_t::flags values
*/
enum {
/*
* HWC_GEOMETRY_CHANGED is set by SurfaceFlinger to indicate that the list
* passed to (*prepare)() has changed by more than just the buffer handles
* and acquire fences.
*/
HWC_GEOMETRY_CHANGED = 0x00000001,
};
/*
* Description of the contents to output on a display.
*
* This is the top-level structure passed to the prepare and set calls to
* negotiate and commit the composition of a display image.
*/
typedef struct hwc_display_contents_1 {
/* File descriptor referring to a Sync HAL fence object which will signal
* when this composition is retired. For a physical display, a composition
* is retired when it has been replaced on-screen by a subsequent set. For
* a virtual display, the composition is retired when the writes to
* outputBuffer are complete and can be read. The fence object is created
* and returned by the set call; this field will be -1 on entry to prepare
* and set. SurfaceFlinger will close the returned file descriptor.
*/
int retireFenceFd;
union {
/* Fields only relevant for HWC_DEVICE_VERSION_1_0. */
struct {
/* (dpy, sur) is the target of SurfaceFlinger's OpenGL ES
* composition for HWC_DEVICE_VERSION_1_0. They aren't relevant to
* prepare. The set call should commit this surface atomically to
* the display along with any overlay layers.
*/
hwc_display_t dpy;
hwc_surface_t sur;
};
/* These fields are used for virtual displays when the h/w composer
* version is at least HWC_DEVICE_VERSION_1_3. */
struct {
/* outbuf is the buffer that receives the composed image for
* virtual displays. Writes to the outbuf must wait until
* outbufAcquireFenceFd signals. A fence that will signal when
* writes to outbuf are complete should be returned in
* retireFenceFd.
*
* This field is set before prepare(), so properties of the buffer
* can be used to decide which layers can be handled by h/w
* composer.
*
* If prepare() sets all layers to FRAMEBUFFER, then GLES
* composition will happen directly to the output buffer. In this
* case, both outbuf and the FRAMEBUFFER_TARGET layer's buffer will
* be the same, and set() has no work to do besides managing fences.
*
* If the TARGET_FORCE_HWC_FOR_VIRTUAL_DISPLAYS board config
* variable is defined (not the default), then this behavior is
* changed: if all layers are marked for FRAMEBUFFER, GLES
* composition will take place to a scratch framebuffer, and
* h/w composer must copy it to the output buffer. This allows the
* h/w composer to do format conversion if there are cases where
* that is more desirable than doing it in the GLES driver or at the
* virtual display consumer.
*
* If some or all layers are marked OVERLAY, then the framebuffer
* and output buffer will be different. As with physical displays,
* the framebuffer handle will not change between frames if all
* layers are marked for OVERLAY.
*/
buffer_handle_t outbuf;
/* File descriptor for a fence that will signal when outbuf is
* ready to be written. The h/w composer is responsible for closing
* this when no longer needed.
*
* Will be -1 whenever outbuf is NULL, or when the outbuf can be
* written immediately.
*/
int outbufAcquireFenceFd;
};
};
/* List of layers that will be composed on the display. The buffer handles
* in the list will be unique. If numHwLayers is 0, all composition will be
* performed by SurfaceFlinger.
*/
uint32_t flags;
size_t numHwLayers;
hwc_layer_1_t hwLayers[0];
} hwc_display_contents_1_t;
/* see hwc_composer_device::registerProcs()
* All of the callbacks are required and non-NULL unless otherwise noted.
*/
typedef struct hwc_procs {
/*
* (*invalidate)() triggers a screen refresh, in particular prepare and set
* will be called shortly after this call is made. Note that there is
* NO GUARANTEE that the screen refresh will happen after invalidate()
* returns (in particular, it could happen before).
* invalidate() is GUARANTEED TO NOT CALL BACK into the h/w composer HAL and
* it is safe to call invalidate() from any of hwc_composer_device
* hooks, unless noted otherwise.
*/
void (*invalidate)(const struct hwc_procs* procs);
/*
* (*vsync)() is called by the h/w composer HAL when a vsync event is
* received and HWC_EVENT_VSYNC is enabled on a display
* (see: hwc_event_control).
*
* the "disp" parameter indicates which display the vsync event is for.
* the "timestamp" parameter is the system monotonic clock timestamp in
* nanosecond of when the vsync event happened.
*
* vsync() is GUARANTEED TO NOT CALL BACK into the h/w composer HAL.
*
* It is expected that vsync() is called from a thread of at least
* HAL_PRIORITY_URGENT_DISPLAY with as little latency as possible,
* typically less than 0.5 ms.
*
* It is a (silent) error to have HWC_EVENT_VSYNC enabled when calling
* hwc_composer_device.set(..., 0, 0, 0) (screen off). The implementation
* can either stop or continue to process VSYNC events, but must not
* crash or cause other problems.
*/
void (*vsync)(const struct hwc_procs* procs, int disp, int64_t timestamp);
/*
* (*hotplug)() is called by the h/w composer HAL when a display is
* connected or disconnected. The PRIMARY display is always connected and
* the hotplug callback should not be called for it.
*
* The disp parameter indicates which display type this event is for.
* The connected parameter indicates whether the display has just been
* connected (1) or disconnected (0).
*
* The hotplug() callback may call back into the h/w composer on the same
* thread to query refresh rate and dpi for the display. Additionally,
* other threads may be calling into the h/w composer while the callback
* is in progress.
*
* The h/w composer must serialize calls to the hotplug callback; only
* one thread may call it at a time.
*
* This callback will be NULL if the h/w composer is using
* HWC_DEVICE_API_VERSION_1_0.
*/
void (*hotplug)(const struct hwc_procs* procs, int disp, int connected);
} hwc_procs_t;
/*****************************************************************************/
typedef struct hwc_module {
/**
* Common methods of the hardware composer module. This *must* be the first member of
* hwc_module as users of this structure will cast a hw_module_t to
* hwc_module pointer in contexts where it's known the hw_module_t references a
* hwc_module.
*/
struct hw_module_t common;
} hwc_module_t;
typedef struct hwc_composer_device_1 {
/**
* Common methods of the hardware composer device. This *must* be the first member of
* hwc_composer_device_1 as users of this structure will cast a hw_device_t to
* hwc_composer_device_1 pointer in contexts where it's known the hw_device_t references a
* hwc_composer_device_1.
*/
struct hw_device_t common;
/*
* (*prepare)() is called for each frame before composition and is used by
* SurfaceFlinger to determine what composition steps the HWC can handle.
*
* (*prepare)() can be called more than once, the last call prevails.
*
* The HWC responds by setting the compositionType field in each layer to
* either HWC_FRAMEBUFFER, HWC_OVERLAY, or HWC_CURSOR_OVERLAY. For the
* HWC_FRAMEBUFFER type, composition for the layer is handled by
* SurfaceFlinger with OpenGL ES. For the latter two overlay types,
* the HWC will have to handle the layer's composition. compositionType
* and hints are preserved between (*prepare)() calles unless the
* HWC_GEOMETRY_CHANGED flag is set.
*
* (*prepare)() is called with HWC_GEOMETRY_CHANGED to indicate that the
* list's geometry has changed, that is, when more than just the buffer's
* handles have been updated. Typically this happens (but is not limited to)
* when a window is added, removed, resized or moved. In this case
* compositionType and hints are reset to their default value.
*
* For HWC 1.0, numDisplays will always be one, and displays[0] will be
* non-NULL.
*
* For HWC 1.1, numDisplays will always be HWC_NUM_PHYSICAL_DISPLAY_TYPES.
* Entries for unsupported or disabled/disconnected display types will be
* NULL.
*
* In HWC 1.3, numDisplays may be up to HWC_NUM_DISPLAY_TYPES. The extra
* entries correspond to enabled virtual displays, and will be non-NULL.
*
* returns: 0 on success. An negative error code on error. If an error is
* returned, SurfaceFlinger will assume that none of the layer will be
* handled by the HWC.
*/
int (*prepare)(struct hwc_composer_device_1 *dev,
size_t numDisplays, hwc_display_contents_1_t** displays);
/*
* (*set)() is used in place of eglSwapBuffers(), and assumes the same
* functionality, except it also commits the work list atomically with
* the actual eglSwapBuffers().
*
* The layer lists are guaranteed to be the same as the ones returned from
* the last call to (*prepare)().
*
* When this call returns the caller assumes that the displays will be
* updated in the near future with the content of their work lists, without
* artifacts during the transition from the previous frame.
*
* A display with zero layers indicates that the entire composition has
* been handled by SurfaceFlinger with OpenGL ES. In this case, (*set)()
* behaves just like eglSwapBuffers().
*
* For HWC 1.0, numDisplays will always be one, and displays[0] will be
* non-NULL.
*
* For HWC 1.1, numDisplays will always be HWC_NUM_PHYSICAL_DISPLAY_TYPES.
* Entries for unsupported or disabled/disconnected display types will be
* NULL.
*
* In HWC 1.3, numDisplays may be up to HWC_NUM_DISPLAY_TYPES. The extra
* entries correspond to enabled virtual displays, and will be non-NULL.
*
* IMPORTANT NOTE: There is an implicit layer containing opaque black
* pixels behind all the layers in the list. It is the responsibility of
* the hwcomposer module to make sure black pixels are output (or blended
* from).
*
* IMPORTANT NOTE: In the event of an error this call *MUST* still cause
* any fences returned in the previous call to set to eventually become
* signaled. The caller may have already issued wait commands on these
* fences, and having set return without causing those fences to signal
* will likely result in a deadlock.
*
* returns: 0 on success. A negative error code on error:
* HWC_EGL_ERROR: eglGetError() will provide the proper error code (only
* allowed prior to HWComposer 1.1)
* Another code for non EGL errors.
*/
int (*set)(struct hwc_composer_device_1 *dev,
size_t numDisplays, hwc_display_contents_1_t** displays);
/*
* eventControl(..., event, enabled)
* Enables or disables h/w composer events for a display.
*
* eventControl can be called from any thread and takes effect
* immediately.
*
* Supported events are:
* HWC_EVENT_VSYNC
*
* returns -EINVAL if the "event" parameter is not one of the value above
* or if the "enabled" parameter is not 0 or 1.
*/
int (*eventControl)(struct hwc_composer_device_1* dev, int disp,
int event, int enabled);
union {
/*
* For HWC 1.3 and earlier, the blank() interface is used.
*
* blank(..., blank)
* Blanks or unblanks a display's screen.
*
* Turns the screen off when blank is nonzero, on when blank is zero.
* Multiple sequential calls with the same blank value must be
* supported.
* The screen state transition must be be complete when the function
* returns.
*
* returns 0 on success, negative on error.
*/
int (*blank)(struct hwc_composer_device_1* dev, int disp, int blank);
/*
* For HWC 1.4 and above, setPowerMode() will be used in place of
* blank().
*
* setPowerMode(..., mode)
* Sets the display screen's power state.
*
* Refer to the documentation of the HWC_POWER_MODE_* constants
* for information about each power mode.
*
* The functionality is similar to the blank() command in previous
* versions of HWC, but with support for more power states.
*
* The display driver is expected to retain and restore the low power
* state of the display while entering and exiting from suspend.
*
* Multiple sequential calls with the same mode value must be supported.
*
* The screen state transition must be be complete when the function
* returns.
*
* returns 0 on success, negative on error.
*/
int (*setPowerMode)(struct hwc_composer_device_1* dev, int disp,
int mode);
};
/*
* Used to retrieve information about the h/w composer
*
* Returns 0 on success or -errno on error.
*/
int (*query)(struct hwc_composer_device_1* dev, int what, int* value);
/*
* (*registerProcs)() registers callbacks that the h/w composer HAL can
* later use. It will be called immediately after the composer device is
* opened with non-NULL procs. It is FORBIDDEN to call any of the callbacks
* from within registerProcs(). registerProcs() must save the hwc_procs_t
* pointer which is needed when calling a registered callback.
*/
void (*registerProcs)(struct hwc_composer_device_1* dev,
hwc_procs_t const* procs);
/*
* This field is OPTIONAL and can be NULL.
*
* If non NULL it will be called by SurfaceFlinger on dumpsys
*/
void (*dump)(struct hwc_composer_device_1* dev, char *buff, int buff_len);
/*
* (*getDisplayConfigs)() returns handles for the configurations available
* on the connected display. These handles must remain valid as long as the
* display is connected.
*
* Configuration handles are written to configs. The number of entries
* allocated by the caller is passed in *numConfigs; getDisplayConfigs must
* not try to write more than this number of config handles. On return, the
* total number of configurations available for the display is returned in
* *numConfigs. If *numConfigs is zero on entry, then configs may be NULL.
*
* Hardware composers implementing HWC_DEVICE_API_VERSION_1_3 or prior
* shall choose one configuration to activate and report it as the first
* entry in the returned list. Reporting the inactive configurations is not
* required.
*
* HWC_DEVICE_API_VERSION_1_4 and later provide configuration management
* through SurfaceFlinger, and hardware composers implementing these APIs
* must also provide getActiveConfig and setActiveConfig. Hardware composers
* implementing these API versions may choose not to activate any
* configuration, leaving configuration selection to higher levels of the
* framework.
*
* Returns 0 on success or a negative error code on error. If disp is a
* hotpluggable display type and no display is connected, an error shall be
* returned.
*
* This field is REQUIRED for HWC_DEVICE_API_VERSION_1_1 and later.
* It shall be NULL for previous versions.
*/
int (*getDisplayConfigs)(struct hwc_composer_device_1* dev, int disp,
uint32_t* configs, size_t* numConfigs);
/*
* (*getDisplayAttributes)() returns attributes for a specific config of a
* connected display. The config parameter is one of the config handles
* returned by getDisplayConfigs.
*
* The list of attributes to return is provided in the attributes
* parameter, terminated by HWC_DISPLAY_NO_ATTRIBUTE. The value for each
* requested attribute is written in order to the values array. The
* HWC_DISPLAY_NO_ATTRIBUTE attribute does not have a value, so the values
* array will have one less value than the attributes array.
*
* This field is REQUIRED for HWC_DEVICE_API_VERSION_1_1 and later.
* It shall be NULL for previous versions.
*
* If disp is a hotpluggable display type and no display is connected,
* or if config is not a valid configuration for the display, a negative
* error code shall be returned.
*/
int (*getDisplayAttributes)(struct hwc_composer_device_1* dev, int disp,
uint32_t config, const uint32_t* attributes, int32_t* values);
/*
* (*getActiveConfig)() returns the index of the configuration that is
* currently active on the connected display. The index is relative to
* the list of configuration handles returned by getDisplayConfigs. If there
* is no active configuration, -1 shall be returned.
*
* Returns the configuration index on success or -1 on error.
*
* This field is REQUIRED for HWC_DEVICE_API_VERSION_1_4 and later.
* It shall be NULL for previous versions.
*/
int (*getActiveConfig)(struct hwc_composer_device_1* dev, int disp);
/*
* (*setActiveConfig)() instructs the hardware composer to switch to the
* display configuration at the given index in the list of configuration
* handles returned by getDisplayConfigs.
*
* If this function returns without error, any subsequent calls to
* getActiveConfig shall return the index set by this function until one
* of the following occurs:
* 1) Another successful call of this function
* 2) The display is disconnected
*
* Returns 0 on success or a negative error code on error. If disp is a
* hotpluggable display type and no display is connected, or if index is
* outside of the range of hardware configurations returned by
* getDisplayConfigs, an error shall be returned.
*
* This field is REQUIRED for HWC_DEVICE_API_VERSION_1_4 and later.
* It shall be NULL for previous versions.
*/
int (*setActiveConfig)(struct hwc_composer_device_1* dev, int disp,
int index);
/*
* Asynchronously update the location of the cursor layer.
*
* Within the standard prepare()/set() composition loop, the client
* (surfaceflinger) can request that a given layer uses dedicated cursor
* composition hardware by specifiying the HWC_IS_CURSOR_LAYER flag. Only
* one layer per display can have this flag set. If the layer is suitable
* for the platform's cursor hardware, hwcomposer will return from prepare()
* a composition type of HWC_CURSOR_OVERLAY for that layer. This indicates
* not only that the client is not responsible for compositing that layer,
* but also that the client can continue to update the position of that layer
* after a call to set(). This can reduce the visible latency of mouse
* movement to visible, on-screen cursor updates. Calls to
* setCursorPositionAsync() may be made from a different thread doing the
* prepare()/set() composition loop, but care must be taken to not interleave
* calls of setCursorPositionAsync() between calls of set()/prepare().
*
* Notes:
* - Only one layer per display can be specified as a cursor layer with
* HWC_IS_CURSOR_LAYER.
* - hwcomposer will only return one layer per display as HWC_CURSOR_OVERLAY
* - This returns 0 on success or -errno on error.
* - This field is optional for HWC_DEVICE_API_VERSION_1_4 and later. It
* should be null for previous versions.
*/
int (*setCursorPositionAsync)(struct hwc_composer_device_1 *dev, int disp, int x_pos, int y_pos);
/*
* Reserved for future use. Must be NULL.
*/
void* reserved_proc[1];
} hwc_composer_device_1_t;
/** convenience API for opening and closing a device */
static inline int hwc_open_1(const struct hw_module_t* module,
hwc_composer_device_1_t** device) {
return module->methods->open(module,
HWC_HARDWARE_COMPOSER, (struct hw_device_t**)device);
}
static inline int hwc_close_1(hwc_composer_device_1_t* device) {
return device->common.close(&device->common);
}
/*****************************************************************************/
__END_DECLS
#endif /* ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_H */
@@ -0,0 +1,263 @@
/*
* Copyright (C) 2010 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_HWCOMPOSER_DEFS_H
#define ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_DEFS_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <hardware/gralloc.h>
#include <hardware/hardware.h>
#include <cutils/native_handle.h>
__BEGIN_DECLS
/*****************************************************************************/
#define HWC_HEADER_VERSION 1
#define HWC_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
#define HWC_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION_2(1, 0, HWC_HEADER_VERSION)
#define HWC_DEVICE_API_VERSION_1_1 HARDWARE_DEVICE_API_VERSION_2(1, 1, HWC_HEADER_VERSION)
#define HWC_DEVICE_API_VERSION_1_2 HARDWARE_DEVICE_API_VERSION_2(1, 2, HWC_HEADER_VERSION)
#define HWC_DEVICE_API_VERSION_1_3 HARDWARE_DEVICE_API_VERSION_2(1, 3, HWC_HEADER_VERSION)
#define HWC_DEVICE_API_VERSION_1_4 HARDWARE_DEVICE_API_VERSION_2(1, 4, HWC_HEADER_VERSION)
#define HWC_DEVICE_API_VERSION_1_5 HARDWARE_DEVICE_API_VERSION_2(1, 5, HWC_HEADER_VERSION)
enum {
/* hwc_composer_device_t::set failed in EGL */
HWC_EGL_ERROR = -1
};
/*
* hwc_layer_t::hints values
* Hints are set by the HAL and read by SurfaceFlinger
*/
enum {
/*
* HWC can set the HWC_HINT_TRIPLE_BUFFER hint to indicate to SurfaceFlinger
* that it should triple buffer this layer. Typically HWC does this when
* the layer will be unavailable for use for an extended period of time,
* e.g. if the display will be fetching data directly from the layer and
* the layer can not be modified until after the next set().
*/
HWC_HINT_TRIPLE_BUFFER = 0x00000001,
/*
* HWC sets HWC_HINT_CLEAR_FB to tell SurfaceFlinger that it should clear the
* framebuffer with transparent pixels where this layer would be.
* SurfaceFlinger will only honor this flag when the layer has no blending
*
*/
HWC_HINT_CLEAR_FB = 0x00000002
};
/*
* hwc_layer_t::flags values
* Flags are set by SurfaceFlinger and read by the HAL
*/
enum {
/*
* HWC_SKIP_LAYER is set by SurfaceFlnger to indicate that the HAL
* shall not consider this layer for composition as it will be handled
* by SurfaceFlinger (just as if compositionType was set to HWC_OVERLAY).
*/
HWC_SKIP_LAYER = 0x00000001,
/*
* HWC_IS_CURSOR_LAYER is set by surfaceflinger to indicate that this
* layer is being used as a cursor on this particular display, and that
* surfaceflinger can potentially perform asynchronous position updates for
* this layer. If a call to prepare() returns HWC_CURSOR_OVERLAY for the
* composition type of this layer, then the hwcomposer will allow async
* position updates to this layer via setCursorPositionAsync().
*/
HWC_IS_CURSOR_LAYER = 0x00000002
};
/*
* hwc_layer_t::compositionType values
*/
enum {
/* this layer is to be drawn into the framebuffer by SurfaceFlinger */
HWC_FRAMEBUFFER = 0,
/* this layer will be handled in the HWC */
HWC_OVERLAY = 1,
/* this is the background layer. it's used to set the background color.
* there is only a single background layer */
HWC_BACKGROUND = 2,
/* this layer holds the result of compositing the HWC_FRAMEBUFFER layers.
* Added in HWC_DEVICE_API_VERSION_1_1. */
HWC_FRAMEBUFFER_TARGET = 3,
/* this layer's contents are taken from a sideband buffer stream.
* Added in HWC_DEVICE_API_VERSION_1_4. */
HWC_SIDEBAND = 4,
/* this layer's composition will be handled by hwcomposer by dedicated
cursor overlay hardware. hwcomposer will also all async position updates
of this layer outside of the normal prepare()/set() loop. Added in
HWC_DEVICE_API_VERSION_1_4. */
HWC_CURSOR_OVERLAY = 5
};
/*
* hwc_layer_t::blending values
*/
enum {
/* no blending */
HWC_BLENDING_NONE = 0x0100,
/* ONE / ONE_MINUS_SRC_ALPHA */
HWC_BLENDING_PREMULT = 0x0105,
/* SRC_ALPHA / ONE_MINUS_SRC_ALPHA */
HWC_BLENDING_COVERAGE = 0x0405
};
/*
* hwc_layer_t::transform values
*/
enum {
/* flip source image horizontally */
HWC_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
/* flip source image vertically */
HWC_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
/* rotate source image 90 degrees clock-wise */
HWC_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
/* rotate source image 180 degrees */
HWC_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
/* rotate source image 270 degrees clock-wise */
HWC_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
};
/* attributes queriable with query() */
enum {
/*
* Must return 1 if the background layer is supported, 0 otherwise.
*/
HWC_BACKGROUND_LAYER_SUPPORTED = 0,
/*
* Returns the vsync period in nanoseconds.
*
* This query is not used for HWC_DEVICE_API_VERSION_1_1 and later.
* Instead, the per-display attribute HWC_DISPLAY_VSYNC_PERIOD is used.
*/
HWC_VSYNC_PERIOD = 1,
/*
* Availability: HWC_DEVICE_API_VERSION_1_1
* Returns a mask of supported display types.
*/
HWC_DISPLAY_TYPES_SUPPORTED = 2,
};
/* display attributes returned by getDisplayAttributes() */
enum {
/* Indicates the end of an attribute list */
HWC_DISPLAY_NO_ATTRIBUTE = 0,
/* The vsync period in nanoseconds */
HWC_DISPLAY_VSYNC_PERIOD = 1,
/* The number of pixels in the horizontal and vertical directions. */
HWC_DISPLAY_WIDTH = 2,
HWC_DISPLAY_HEIGHT = 3,
/* The number of pixels per thousand inches of this configuration.
*
* Scaling DPI by 1000 allows it to be stored in an int without losing
* too much precision.
*
* If the DPI for a configuration is unavailable or the HWC implementation
* considers it unreliable, it should set these attributes to zero.
*/
HWC_DISPLAY_DPI_X = 4,
HWC_DISPLAY_DPI_Y = 5,
/* Indicates which of the vendor-defined color transforms is provided by
* this configuration. */
HWC_DISPLAY_COLOR_TRANSFORM = 6,
};
/* Allowed events for hwc_methods::eventControl() */
enum {
HWC_EVENT_VSYNC = 0
};
/* Display types and associated mask bits. */
enum {
HWC_DISPLAY_PRIMARY = 0,
HWC_DISPLAY_EXTERNAL = 1, // HDMI, DP, etc.
#ifdef QTI_BSP
HWC_DISPLAY_TERTIARY = 2,
HWC_DISPLAY_VIRTUAL = 3,
HWC_NUM_PHYSICAL_DISPLAY_TYPES = 3,
HWC_NUM_DISPLAY_TYPES = 4,
#else
HWC_DISPLAY_VIRTUAL = 2,
HWC_NUM_PHYSICAL_DISPLAY_TYPES = 2,
HWC_NUM_DISPLAY_TYPES = 3,
#endif
};
enum {
HWC_DISPLAY_PRIMARY_BIT = 1 << HWC_DISPLAY_PRIMARY,
HWC_DISPLAY_EXTERNAL_BIT = 1 << HWC_DISPLAY_EXTERNAL,
#ifdef QTI_BSP
HWC_DISPLAY_TERTIARY_BIT = 1 << HWC_DISPLAY_TERTIARY,
#endif
HWC_DISPLAY_VIRTUAL_BIT = 1 << HWC_DISPLAY_VIRTUAL,
};
/* Display power modes */
enum {
/* The display is turned off (blanked). */
HWC_POWER_MODE_OFF = 0,
/* The display is turned on and configured in a low power state
* that is suitable for presenting ambient information to the user,
* possibly with lower fidelity than normal but greater efficiency. */
HWC_POWER_MODE_DOZE = 1,
/* The display is turned on normally. */
HWC_POWER_MODE_NORMAL = 2,
/* The display is configured as in HWC_POWER_MODE_DOZE but may
* stop applying frame buffer updates from the graphics subsystem.
* This power mode is effectively a hint from the doze dream to
* tell the hardware that it is done drawing to the display for the
* time being and that the display should remain on in a low power
* state and continue showing its current contents indefinitely
* until the mode changes.
*
* This mode may also be used as a signal to enable hardware-based doze
* functionality. In this case, the doze dream is effectively
* indicating that the hardware is free to take over the display
* and manage it autonomously to implement low power always-on display
* functionality. */
HWC_POWER_MODE_DOZE_SUSPEND = 3,
};
/*****************************************************************************/
__END_DECLS
#endif /* ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_DEFS_H */
@@ -0,0 +1,549 @@
/*
* 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 struct input_property_map input_property_map_t;
typedef struct input_property input_property_t;
typedef enum {
// keycodes
INPUT_USAGE_KEYCODE_UNKNOWN,
INPUT_USAGE_KEYCODE_SOFT_LEFT,
INPUT_USAGE_KEYCODE_SOFT_RIGHT,
INPUT_USAGE_KEYCODE_HOME,
INPUT_USAGE_KEYCODE_BACK,
INPUT_USAGE_KEYCODE_CALL,
INPUT_USAGE_KEYCODE_ENDCALL,
INPUT_USAGE_KEYCODE_0,
INPUT_USAGE_KEYCODE_1,
INPUT_USAGE_KEYCODE_2,
INPUT_USAGE_KEYCODE_3,
INPUT_USAGE_KEYCODE_4,
INPUT_USAGE_KEYCODE_5,
INPUT_USAGE_KEYCODE_6,
INPUT_USAGE_KEYCODE_7,
INPUT_USAGE_KEYCODE_8,
INPUT_USAGE_KEYCODE_9,
INPUT_USAGE_KEYCODE_STAR,
INPUT_USAGE_KEYCODE_POUND,
INPUT_USAGE_KEYCODE_DPAD_UP,
INPUT_USAGE_KEYCODE_DPAD_DOWN,
INPUT_USAGE_KEYCODE_DPAD_LEFT,
INPUT_USAGE_KEYCODE_DPAD_RIGHT,
INPUT_USAGE_KEYCODE_DPAD_CENTER,
INPUT_USAGE_KEYCODE_VOLUME_UP,
INPUT_USAGE_KEYCODE_VOLUME_DOWN,
INPUT_USAGE_KEYCODE_POWER,
INPUT_USAGE_KEYCODE_CAMERA,
INPUT_USAGE_KEYCODE_CLEAR,
INPUT_USAGE_KEYCODE_A,
INPUT_USAGE_KEYCODE_B,
INPUT_USAGE_KEYCODE_C,
INPUT_USAGE_KEYCODE_D,
INPUT_USAGE_KEYCODE_E,
INPUT_USAGE_KEYCODE_F,
INPUT_USAGE_KEYCODE_G,
INPUT_USAGE_KEYCODE_H,
INPUT_USAGE_KEYCODE_I,
INPUT_USAGE_KEYCODE_J,
INPUT_USAGE_KEYCODE_K,
INPUT_USAGE_KEYCODE_L,
INPUT_USAGE_KEYCODE_M,
INPUT_USAGE_KEYCODE_N,
INPUT_USAGE_KEYCODE_O,
INPUT_USAGE_KEYCODE_P,
INPUT_USAGE_KEYCODE_Q,
INPUT_USAGE_KEYCODE_R,
INPUT_USAGE_KEYCODE_S,
INPUT_USAGE_KEYCODE_T,
INPUT_USAGE_KEYCODE_U,
INPUT_USAGE_KEYCODE_V,
INPUT_USAGE_KEYCODE_W,
INPUT_USAGE_KEYCODE_X,
INPUT_USAGE_KEYCODE_Y,
INPUT_USAGE_KEYCODE_Z,
INPUT_USAGE_KEYCODE_COMMA,
INPUT_USAGE_KEYCODE_PERIOD,
INPUT_USAGE_KEYCODE_ALT_LEFT,
INPUT_USAGE_KEYCODE_ALT_RIGHT,
INPUT_USAGE_KEYCODE_SHIFT_LEFT,
INPUT_USAGE_KEYCODE_SHIFT_RIGHT,
INPUT_USAGE_KEYCODE_TAB,
INPUT_USAGE_KEYCODE_SPACE,
INPUT_USAGE_KEYCODE_SYM,
INPUT_USAGE_KEYCODE_EXPLORER,
INPUT_USAGE_KEYCODE_ENVELOPE,
INPUT_USAGE_KEYCODE_ENTER,
INPUT_USAGE_KEYCODE_DEL,
INPUT_USAGE_KEYCODE_GRAVE,
INPUT_USAGE_KEYCODE_MINUS,
INPUT_USAGE_KEYCODE_EQUALS,
INPUT_USAGE_KEYCODE_LEFT_BRACKET,
INPUT_USAGE_KEYCODE_RIGHT_BRACKET,
INPUT_USAGE_KEYCODE_BACKSLASH,
INPUT_USAGE_KEYCODE_SEMICOLON,
INPUT_USAGE_KEYCODE_APOSTROPHE,
INPUT_USAGE_KEYCODE_SLASH,
INPUT_USAGE_KEYCODE_AT,
INPUT_USAGE_KEYCODE_NUM,
INPUT_USAGE_KEYCODE_HEADSETHOOK,
INPUT_USAGE_KEYCODE_FOCUS, // *Camera* focus
INPUT_USAGE_KEYCODE_PLUS,
INPUT_USAGE_KEYCODE_MENU,
INPUT_USAGE_KEYCODE_NOTIFICATION,
INPUT_USAGE_KEYCODE_SEARCH,
INPUT_USAGE_KEYCODE_MEDIA_PLAY_PAUSE,
INPUT_USAGE_KEYCODE_MEDIA_STOP,
INPUT_USAGE_KEYCODE_MEDIA_NEXT,
INPUT_USAGE_KEYCODE_MEDIA_PREVIOUS,
INPUT_USAGE_KEYCODE_MEDIA_REWIND,
INPUT_USAGE_KEYCODE_MEDIA_FAST_FORWARD,
INPUT_USAGE_KEYCODE_MUTE,
INPUT_USAGE_KEYCODE_PAGE_UP,
INPUT_USAGE_KEYCODE_PAGE_DOWN,
INPUT_USAGE_KEYCODE_PICTSYMBOLS,
INPUT_USAGE_KEYCODE_SWITCH_CHARSET,
INPUT_USAGE_KEYCODE_BUTTON_A,
INPUT_USAGE_KEYCODE_BUTTON_B,
INPUT_USAGE_KEYCODE_BUTTON_C,
INPUT_USAGE_KEYCODE_BUTTON_X,
INPUT_USAGE_KEYCODE_BUTTON_Y,
INPUT_USAGE_KEYCODE_BUTTON_Z,
INPUT_USAGE_KEYCODE_BUTTON_L1,
INPUT_USAGE_KEYCODE_BUTTON_R1,
INPUT_USAGE_KEYCODE_BUTTON_L2,
INPUT_USAGE_KEYCODE_BUTTON_R2,
INPUT_USAGE_KEYCODE_BUTTON_THUMBL,
INPUT_USAGE_KEYCODE_BUTTON_THUMBR,
INPUT_USAGE_KEYCODE_BUTTON_START,
INPUT_USAGE_KEYCODE_BUTTON_SELECT,
INPUT_USAGE_KEYCODE_BUTTON_MODE,
INPUT_USAGE_KEYCODE_ESCAPE,
INPUT_USAGE_KEYCODE_FORWARD_DEL,
INPUT_USAGE_KEYCODE_CTRL_LEFT,
INPUT_USAGE_KEYCODE_CTRL_RIGHT,
INPUT_USAGE_KEYCODE_CAPS_LOCK,
INPUT_USAGE_KEYCODE_SCROLL_LOCK,
INPUT_USAGE_KEYCODE_META_LEFT,
INPUT_USAGE_KEYCODE_META_RIGHT,
INPUT_USAGE_KEYCODE_FUNCTION,
INPUT_USAGE_KEYCODE_SYSRQ,
INPUT_USAGE_KEYCODE_BREAK,
INPUT_USAGE_KEYCODE_MOVE_HOME,
INPUT_USAGE_KEYCODE_MOVE_END,
INPUT_USAGE_KEYCODE_INSERT,
INPUT_USAGE_KEYCODE_FORWARD,
INPUT_USAGE_KEYCODE_MEDIA_PLAY,
INPUT_USAGE_KEYCODE_MEDIA_PAUSE,
INPUT_USAGE_KEYCODE_MEDIA_CLOSE,
INPUT_USAGE_KEYCODE_MEDIA_EJECT,
INPUT_USAGE_KEYCODE_MEDIA_RECORD,
INPUT_USAGE_KEYCODE_F1,
INPUT_USAGE_KEYCODE_F2,
INPUT_USAGE_KEYCODE_F3,
INPUT_USAGE_KEYCODE_F4,
INPUT_USAGE_KEYCODE_F5,
INPUT_USAGE_KEYCODE_F6,
INPUT_USAGE_KEYCODE_F7,
INPUT_USAGE_KEYCODE_F8,
INPUT_USAGE_KEYCODE_F9,
INPUT_USAGE_KEYCODE_F10,
INPUT_USAGE_KEYCODE_F11,
INPUT_USAGE_KEYCODE_F12,
INPUT_USAGE_KEYCODE_NUM_LOCK,
INPUT_USAGE_KEYCODE_NUMPAD_0,
INPUT_USAGE_KEYCODE_NUMPAD_1,
INPUT_USAGE_KEYCODE_NUMPAD_2,
INPUT_USAGE_KEYCODE_NUMPAD_3,
INPUT_USAGE_KEYCODE_NUMPAD_4,
INPUT_USAGE_KEYCODE_NUMPAD_5,
INPUT_USAGE_KEYCODE_NUMPAD_6,
INPUT_USAGE_KEYCODE_NUMPAD_7,
INPUT_USAGE_KEYCODE_NUMPAD_8,
INPUT_USAGE_KEYCODE_NUMPAD_9,
INPUT_USAGE_KEYCODE_NUMPAD_DIVIDE,
INPUT_USAGE_KEYCODE_NUMPAD_MULTIPLY,
INPUT_USAGE_KEYCODE_NUMPAD_SUBTRACT,
INPUT_USAGE_KEYCODE_NUMPAD_ADD,
INPUT_USAGE_KEYCODE_NUMPAD_DOT,
INPUT_USAGE_KEYCODE_NUMPAD_COMMA,
INPUT_USAGE_KEYCODE_NUMPAD_ENTER,
INPUT_USAGE_KEYCODE_NUMPAD_EQUALS,
INPUT_USAGE_KEYCODE_NUMPAD_LEFT_PAREN,
INPUT_USAGE_KEYCODE_NUMPAD_RIGHT_PAREN,
INPUT_USAGE_KEYCODE_VOLUME_MUTE,
INPUT_USAGE_KEYCODE_INFO,
INPUT_USAGE_KEYCODE_CHANNEL_UP,
INPUT_USAGE_KEYCODE_CHANNEL_DOWN,
INPUT_USAGE_KEYCODE_ZOOM_IN,
INPUT_USAGE_KEYCODE_ZOOM_OUT,
INPUT_USAGE_KEYCODE_TV,
INPUT_USAGE_KEYCODE_WINDOW,
INPUT_USAGE_KEYCODE_GUIDE,
INPUT_USAGE_KEYCODE_DVR,
INPUT_USAGE_KEYCODE_BOOKMARK,
INPUT_USAGE_KEYCODE_CAPTIONS,
INPUT_USAGE_KEYCODE_SETTINGS,
INPUT_USAGE_KEYCODE_TV_POWER,
INPUT_USAGE_KEYCODE_TV_INPUT,
INPUT_USAGE_KEYCODE_STB_POWER,
INPUT_USAGE_KEYCODE_STB_INPUT,
INPUT_USAGE_KEYCODE_AVR_POWER,
INPUT_USAGE_KEYCODE_AVR_INPUT,
INPUT_USAGE_KEYCODE_PROG_RED,
INPUT_USAGE_KEYCODE_PROG_GREEN,
INPUT_USAGE_KEYCODE_PROG_YELLOW,
INPUT_USAGE_KEYCODE_PROG_BLUE,
INPUT_USAGE_KEYCODE_APP_SWITCH,
INPUT_USAGE_KEYCODE_BUTTON_1,
INPUT_USAGE_KEYCODE_BUTTON_2,
INPUT_USAGE_KEYCODE_BUTTON_3,
INPUT_USAGE_KEYCODE_BUTTON_4,
INPUT_USAGE_KEYCODE_BUTTON_5,
INPUT_USAGE_KEYCODE_BUTTON_6,
INPUT_USAGE_KEYCODE_BUTTON_7,
INPUT_USAGE_KEYCODE_BUTTON_8,
INPUT_USAGE_KEYCODE_BUTTON_9,
INPUT_USAGE_KEYCODE_BUTTON_10,
INPUT_USAGE_KEYCODE_BUTTON_11,
INPUT_USAGE_KEYCODE_BUTTON_12,
INPUT_USAGE_KEYCODE_BUTTON_13,
INPUT_USAGE_KEYCODE_BUTTON_14,
INPUT_USAGE_KEYCODE_BUTTON_15,
INPUT_USAGE_KEYCODE_BUTTON_16,
INPUT_USAGE_KEYCODE_LANGUAGE_SWITCH,
INPUT_USAGE_KEYCODE_MANNER_MODE,
INPUT_USAGE_KEYCODE_3D_MODE,
INPUT_USAGE_KEYCODE_CONTACTS,
INPUT_USAGE_KEYCODE_CALENDAR,
INPUT_USAGE_KEYCODE_MUSIC,
INPUT_USAGE_KEYCODE_CALCULATOR,
INPUT_USAGE_KEYCODE_ZENKAKU_HANKAKU,
INPUT_USAGE_KEYCODE_EISU,
INPUT_USAGE_KEYCODE_MUHENKAN,
INPUT_USAGE_KEYCODE_HENKAN,
INPUT_USAGE_KEYCODE_KATAKANA_HIRAGANA,
INPUT_USAGE_KEYCODE_YEN,
INPUT_USAGE_KEYCODE_RO,
INPUT_USAGE_KEYCODE_KANA,
INPUT_USAGE_KEYCODE_ASSIST,
INPUT_USAGE_KEYCODE_BRIGHTNESS_DOWN,
INPUT_USAGE_KEYCODE_BRIGHTNESS_UP,
INPUT_USAGE_KEYCODE_MEDIA_AUDIO_TRACK,
INPUT_USAGE_KEYCODE_SLEEP,
INPUT_USAGE_KEYCODE_WAKEUP,
INPUT_USAGE_KEYCODE_PAIRING,
INPUT_USAGE_KEYCODE_MEDIA_TOP_MENU,
INPUT_USAGE_KEYCODE_11,
INPUT_USAGE_KEYCODE_12,
INPUT_USAGE_KEYCODE_LAST_CHANNEL,
INPUT_USAGE_KEYCODE_TV_DATA_SERVICE,
INPUT_USAGE_KEYCODE_VOICE_ASSIST,
INPUT_USAGE_KEYCODE_TV_RADIO_SERVICE,
INPUT_USAGE_KEYCODE_TV_TELETEXT,
INPUT_USAGE_KEYCODE_TV_NUMBER_ENTRY,
INPUT_USAGE_KEYCODE_TV_TERRESTRIAL_ANALOG,
INPUT_USAGE_KEYCODE_TV_TERRESTRIAL_DIGITAL,
INPUT_USAGE_KEYCODE_TV_SATELLITE,
INPUT_USAGE_KEYCODE_TV_SATELLITE_BS,
INPUT_USAGE_KEYCODE_TV_SATELLITE_CS,
INPUT_USAGE_KEYCODE_TV_SATELLITE_SERVICE,
INPUT_USAGE_KEYCODE_TV_NETWORK,
INPUT_USAGE_KEYCODE_TV_ANTENNA_CABLE,
INPUT_USAGE_KEYCODE_TV_INPUT_HDMI_1,
INPUT_USAGE_KEYCODE_TV_INPUT_HDMI_2,
INPUT_USAGE_KEYCODE_TV_INPUT_HDMI_3,
INPUT_USAGE_KEYCODE_TV_INPUT_HDMI_4,
INPUT_USAGE_KEYCODE_TV_INPUT_COMPOSITE_1,
INPUT_USAGE_KEYCODE_TV_INPUT_COMPOSITE_2,
INPUT_USAGE_KEYCODE_TV_INPUT_COMPONENT_1,
INPUT_USAGE_KEYCODE_TV_INPUT_COMPONENT_2,
INPUT_USAGE_KEYCODE_TV_INPUT_VGA_1,
INPUT_USAGE_KEYCODE_TV_AUDIO_DESCRIPTION,
INPUT_USAGE_KEYCODE_TV_AUDIO_DESCRIPTION_MIX_UP,
INPUT_USAGE_KEYCODE_TV_AUDIO_DESCRIPTION_MIX_DOWN,
INPUT_USAGE_KEYCODE_TV_ZOOM_MODE,
INPUT_USAGE_KEYCODE_TV_CONTENTS_MENU,
INPUT_USAGE_KEYCODE_TV_MEDIA_CONTEXT_MENU,
INPUT_USAGE_KEYCODE_TV_TIMER_PROGRAMMING,
INPUT_USAGE_KEYCODE_HELP,
// axes
INPUT_USAGE_AXIS_X,
INPUT_USAGE_AXIS_Y,
INPUT_USAGE_AXIS_PRESSURE,
INPUT_USAGE_AXIS_SIZE,
INPUT_USAGE_AXIS_TOUCH_MAJOR,
INPUT_USAGE_AXIS_TOUCH_MINOR,
INPUT_USAGE_AXIS_TOOL_MAJOR,
INPUT_USAGE_AXIS_TOOL_MINOR,
INPUT_USAGE_AXIS_ORIENTATION,
INPUT_USAGE_AXIS_VSCROLL,
INPUT_USAGE_AXIS_HSCROLL,
INPUT_USAGE_AXIS_Z,
INPUT_USAGE_AXIS_RX,
INPUT_USAGE_AXIS_RY,
INPUT_USAGE_AXIS_RZ,
INPUT_USAGE_AXIS_HAT_X,
INPUT_USAGE_AXIS_HAT_Y,
INPUT_USAGE_AXIS_LTRIGGER,
INPUT_USAGE_AXIS_RTRIGGER,
INPUT_USAGE_AXIS_THROTTLE,
INPUT_USAGE_AXIS_RUDDER,
INPUT_USAGE_AXIS_WHEEL,
INPUT_USAGE_AXIS_GAS,
INPUT_USAGE_AXIS_BRAKE,
INPUT_USAGE_AXIS_DISTANCE,
INPUT_USAGE_AXIS_TILT,
INPUT_USAGE_AXIS_GENERIC_1,
INPUT_USAGE_AXIS_GENERIC_2,
INPUT_USAGE_AXIS_GENERIC_3,
INPUT_USAGE_AXIS_GENERIC_4,
INPUT_USAGE_AXIS_GENERIC_5,
INPUT_USAGE_AXIS_GENERIC_6,
INPUT_USAGE_AXIS_GENERIC_7,
INPUT_USAGE_AXIS_GENERIC_8,
INPUT_USAGE_AXIS_GENERIC_9,
INPUT_USAGE_AXIS_GENERIC_10,
INPUT_USAGE_AXIS_GENERIC_11,
INPUT_USAGE_AXIS_GENERIC_12,
INPUT_USAGE_AXIS_GENERIC_13,
INPUT_USAGE_AXIS_GENERIC_14,
INPUT_USAGE_AXIS_GENERIC_15,
INPUT_USAGE_AXIS_GENERIC_16,
// leds
INPUT_USAGE_LED_NUM_LOCK,
INPUT_USAGE_LED_CAPS_LOCK,
INPUT_USAGE_LED_SCROLL_LOCK,
INPUT_USAGE_LED_COMPOSE,
INPUT_USAGE_LED_KANA,
INPUT_USAGE_LED_SLEEP,
INPUT_USAGE_LED_SUSPEND,
INPUT_USAGE_LED_MUTE,
INPUT_USAGE_LED_MISC,
INPUT_USAGE_LED_MAIL,
INPUT_USAGE_LED_CHARGING,
INPUT_USAGE_LED_CONTROLLER_1,
INPUT_USAGE_LED_CONTROLLER_2,
INPUT_USAGE_LED_CONTROLLER_3,
INPUT_USAGE_LED_CONTROLLER_4,
} 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);
/**
* Add an int usage value to a report.
*/
void (*input_report_set_usage_int)(input_host_t* host, input_report_t* r,
input_collection_id_t id, input_usage_t usage, int32_t value, int32_t arity_index);
/**
* Add a boolean usage value to a report.
*/
void (*input_report_set_usage_bool)(input_host_t* host, input_report_t* r,
input_collection_id_t id, input_usage_t usage, bool value, int32_t arity_index);
void (*report_event)(input_host_t* host, input_device_handle_t* d, input_report_t* report);
/**
* Retrieve the set of properties for the device. The returned
* input_property_map_t* may be used to query specific properties via the
* input_get_device_property callback.
*/
input_property_map_t* (*input_get_device_property_map)(input_host_t* host,
input_device_identifier_t* id);
/**
* Retrieve a property for the device with the given key. Returns NULL if
* the key does not exist, or an input_property_t* that must be freed using
* input_free_device_property(). Using an input_property_t after the
* corresponding input_property_map_t is freed is undefined.
*/
input_property_t* (*input_get_device_property)(input_host_t* host,
input_property_map_t* map, const char* key);
/**
* Get the key for the input property. Returns NULL if the property is NULL.
* The returned const char* is owned by the input_property_t.
*/
const char* (*input_get_property_key)(input_host_t* host, input_property_t* property);
/**
* Get the value for the input property. Returns NULL if the property is
* NULL. The returned const char* is owned by the input_property_t.
*/
const char* (*input_get_property_value)(input_host_t* host, input_property_t* property);
/**
* Frees the input_property_t*.
*/
void (*input_free_device_property)(input_host_t* host, input_property_t* property);
/**
* Frees the input_property_map_t*.
*/
void (*input_free_device_property_map)(input_host_t* host, input_property_map_t* map);
} 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)(const input_module_t* module, 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 */
@@ -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
@@ -0,0 +1,597 @@
/*
* 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; and
* - (KM_TAG_USER_SECURE_ID and KM_TAG_USER_AUTH_TYPE) or KM_TAG_NO_AUTH_REQUIRED.
*
* 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 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. \p key_blob must not be NULL. The caller
* assumes ownership key_blob->key_material and must free() it.
*
* \param[out] characteristics returns the characteristics of the key that was, generated, if
* non-NULL. If non-NULL, the caller assumes ownership and must deallocate 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_set_t* params,
keymaster_key_blob_t* key_blob,
keymaster_key_characteristics_t** characteristics);
/**
* Returns the characteristics of the specified key, or KM_ERROR_INVALID_KEY_BLOB 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, or empty if KM_TAG_APPLICATION_ID and/or KM_TAG_APPLICATION_DATA were not provided
* during generation. Those values are not included in the returned characteristics. The
* 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);
/**
* 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. Values that are always required for import of useful
* keys are:
*
* - KM_TAG_ALGORITHM;
* - KM_TAG_PURPOSE; and
* - (KM_TAG_USER_SECURE_ID and KM_TAG_USER_AUTH_TYPE) or KM_TAG_NO_AUTH_REQUIRED.
*
* KM_TAG_AUTH_TIMEOUT should generally be specified. If unspecified, the user will have to
* authenticate for every use.
*
* The following tags will take default values if unspecified:
*
* - KM_TAG_KEY_SIZE will default to the size of the key provided.
* - KM_TAG_RSA_PUBLIC_EXPONENT will default to the value in the key provided (for RSA keys)
*
* 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(). Note that
* KM_TAG_ROOT_OF_TRUST, KM_TAG_APPLICATION_ID and
* KM_TAG_APPLICATION_DATA are never returned.
*/
keymaster_error_t (*import_key)(const struct keymaster1_device* dev,
const keymaster_key_param_set_t* params,
keymaster_key_format_t key_format,
const keymaster_blob_t* key_data,
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,
keymaster_blob_t* export_data);
/**
* 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. 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.
*/
keymaster_error_t (*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 may leak internal state space or other internal resources and may
* eventually cause begin() to return KM_ERROR_TOO_MANY_OPERATIONS when it runs out of space for
* operations. Any result other than KM_ERROR_OK from begin(), update() or finish() implicitly
* aborts the operation, in which case abort() need not be called (and will return
* KM_ERROR_INVALID_OPERATION_HANDLE if called).
*
* \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, but should be
* specified as KM_PURPOSE_ENCRYPT and KM_PURPOSE_DECRYPT.
*
* \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] in_params Additional parameters for the operation. This is typically used to
* provide authentication data, with KM_TAG_AUTH_TOKEN. If KM_TAG_APPLICATION_ID or
* KM_TAG_APPLICATION_DATA were provided during generation, they must be provided here, or the
* operation will fail with KM_ERROR_INVALID_KEY_BLOB. For operations that require a nonce or
* IV, on keys that were generated with KM_TAG_CALLER_NONCE, in_params may contain a tag
* KM_TAG_NONCE. For AEAD operations KM_TAG_CHUNK_SIZE is specified here.
*
* \param[out] out_params Output parameters. Used to return additional data from the operation
* initialization, notably to return the IV or nonce from operations that generate an IV or
* nonce. The caller takes ownership of the output parameters array and must free it with
* keymaster_free_param_set(). out_params may be set to NULL if no output parameters are
* expected. If out_params is NULL, and output paramaters are generated, begin() will return
* KM_ERROR_OUTPUT_PARAMETER_NULL.
*
* \param[out] operation_handle The newly-created operation handle which must be passed to
* update(), finish() or abort(). If operation_handle is NULL, begin() will return
* KM_ERROR_OUTPUT_PARAMETER_NULL.
*/
keymaster_error_t (*begin)(const struct keymaster1_device* dev, keymaster_purpose_t purpose,
const keymaster_key_blob_t* key,
const keymaster_key_param_set_t* in_params,
keymaster_key_param_set_t* out_params,
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.
*
* update() may not consume all of the data provided in the data buffer. 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] in_params Additional parameters for the operation. For AEAD modes, this is used
* to specify KM_TAG_ADDITIONAL_DATA. Note that additional data may be provided in multiple
* calls to update(), but only until input data has been provided.
*
* \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 input_consumed.
*
* \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] out_params Output parameters. Used to return additional data from the operation
* The caller takes ownership of the output parameters array and must free it with
* keymaster_free_param_set(). out_params may be set to NULL if no output parameters are
* expected. If out_params is NULL, and output paramaters are generated, begin() will return
* KM_ERROR_OUTPUT_PARAMETER_NULL.
*
* \param[out] output The output data, if any. The caller assumes ownership of the allocated
* buffer. output must not be NULL.
*
* Note that update() may not provide any output, in which case output->data_length will be
* zero, and output->data 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_set_t* in_params,
const keymaster_blob_t* input, size_t* input_consumed,
keymaster_key_param_set_t* out_params, keymaster_blob_t* output);
/**
* Finalizes a cryptographic operation begun with begin() and invalidates \p operation_handle.
*
* \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, but only if no input data was provided to update().
*
* \param[in] signature The signature to be verified if the purpose specified in the begin()
* call was KM_PURPOSE_VERIFY.
*
* \param[out] output The output data, if any. The caller assumes ownership of the allocated
* 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_set_t* in_params,
const keymaster_blob_t* signature,
keymaster_key_param_set_t* out_params, keymaster_blob_t* output);
/**
* Aborts a cryptographic operation begun with begin(), freeing all internal resources and
* invalidating \p operation_handle.
*/
keymaster_error_t (*abort)(const struct keymaster1_device* dev,
keymaster_operation_handle_t operation_handle);
/**
* Generates a pair of ATTK defined in SOTER. Save the private key into RPMB.
* Note that the ATTK generated will never be touched outside the keymaster.
*
* \param[in] dev The keymaster device structure.
*
* \param[in] copy_num The number of copies that will be saved in the RPMB.
*/
keymaster_error_t (*generate_attk_key_pair)(const struct keymaster1_device* dev,
const uint8_t copy_num);
/**
* Verify the existance ATTK defined in SOTER.
*
* \param[in] dev The keymaster device structure.
*
* Returns: 0 if the ATTK exists.
*/
keymaster_error_t (*verify_attk_key_pair)(const struct keymaster1_device* dev);
/**
* Export the public key of ATTK in PEM format.
*
* \param[in] dev The keymaster device structure.
*
* \param[out] pub_key_data The public key data in X.509v3 format PEM encoded
*
* \param[out] pub_key_data_length The length of the public key data.
*/
keymaster_error_t (*export_attk_public_key)(const struct keymaster1_device* dev,
const uint8_t* pub_key_data,
const size_t pub_key_data_length);
/**
* Get Unique device ID.
*
* \param[in] dev The keymaster device structure.
*
* \param[out] device_id The unique id for each device, format as below:
* 1.bytes 0-3: Identify each silicon provider id.
* 2.bytes 4-7: SoC model ID, defined by each silicon provider
* 3.bytes 8-15: Public Chip Serial *Number of SoC, defined by each silicon provider
*
* \param[out] device_id_length The length of the device id.
*/
keymaster_error_t (*get_device_id)(const struct keymaster1_device* dev,
const uint8_t* device_id,
const size_t device_id_length);
};
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
@@ -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
@@ -0,0 +1,539 @@
/*
* 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>
#ifdef __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_UINT = 3 << 28,
KM_UINT_REP = 4 << 28, /* Repeatable integer value */
KM_ULONG = 5 << 28,
KM_DATE = 6 << 28,
KM_BOOL = 7 << 28,
KM_BIGNUM = 8 << 28,
KM_BYTES = 9 << 28,
KM_ULONG_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_UINT | 3, /* Key size in bits. */
KM_TAG_BLOCK_MODE = KM_ENUM_REP | 4, /* keymaster_block_mode_t. */
KM_TAG_DIGEST = KM_ENUM_REP | 5, /* keymaster_digest_t. */
KM_TAG_PADDING = KM_ENUM_REP | 6, /* keymaster_padding_t. */
KM_TAG_CALLER_NONCE = KM_BOOL | 7, /* Allow caller to specify nonce or IV. */
KM_TAG_MIN_MAC_LENGTH = KM_UINT | 8, /* Minimum length of MAC or AEAD authentication tag in
* bits. */
/* Algorithm-specific. */
KM_TAG_RSA_PUBLIC_EXPONENT = KM_ULONG | 200,
/* Other hardware-enforced. */
KM_TAG_BLOB_USAGE_REQUIREMENTS = KM_ENUM | 301, /* keymaster_key_blob_usage_requirements_t */
KM_TAG_BOOTLOADER_ONLY = KM_BOOL | 302, /* Usable only by bootloader */
/*
* 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_UINT | 403, /* Minimum elapsed time between
cryptographic operations with the key. */
KM_TAG_MAX_USES_PER_BOOT = KM_UINT | 404, /* Number of times the key can be used per
boot. */
/* User authentication */
KM_TAG_ALL_USERS = KM_BOOL | 500, /* Reserved for future use -- ignore */
KM_TAG_USER_ID = KM_UINT | 501, /* Reserved for future use -- ignore */
KM_TAG_USER_SECURE_ID = KM_ULONG_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_UINT | 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, /* Reserved for future use -- ignore */
KM_TAG_APPLICATION_ID = KM_BYTES | 601, /* Reserved for fugure use -- ignore */
/*
* 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. */
/* 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_AUTH_TOKEN = KM_BYTES | 1002, /* Authentication token that proves secure user
authentication has been performed. Structure
defined in hw_auth_token_t in hw_auth_token.h. */
KM_TAG_MAC_LENGTH = KM_UINT | 1003, /* MAC or AEAD authentication tag length in bits. */
/* Tags used only for SOTER */
/* Tags used only to check if the key is for SOTER */
KM_TAG_SOTER_IS_FROM_SOTER = KM_BOOL | 11000,
/* Attach signature signed with ATTK[pri] while exporting public key */
KM_TAG_SOTER_IS_AUTO_SIGNED_WITH_ATTK_WHEN_GET_PUBLIC_KEY = KM_BOOL | 11001,
/* Attach signature signed with specified private key while exporting public key */
KM_TAG_SOTER_IS_AUTO_SIGNED_WITH_COMMON_KEY_WHEN_GET_PUBLIC_KEY = KM_BOOL | 11002,
/* keyalias for the keypair of KM_TAG_SOTER_IS_AUTO_SIGNED_WITH_COMMON_KEY_WHEN_GET_PUBLIC_KEY */
KM_TAG_SOTER_AUTO_SIGNED_COMMON_KEY_WHEN_GET_PUBLIC_KEY = KM_BYTES | 11003,
/* Attach counter while exporting publick key */
KM_TAG_SOTER_AUTO_ADD_COUNTER_WHEN_GET_PUBLIC_KEY = KM_BOOL | 11004,
/* Attach secmsg(TEE_Name, TEE_Version, Fingerprint_Sensor_Name, Fingerprint_Sensor_Version)
fingerprint_id and counter while signing */
KM_TAG_SOTER_IS_SECMSG_FID_COUNTER_SIGNED_WHEN_SIGN = KM_BOOL | 11005,
/* use and set ATTK index to next backup ATTK */
KM_TAG_SOTER_USE_NEXT_ATTK = KM_BOOL | 11006,
/* attach soter uid */
KM_TAG_SOTER_UID = KM_UINT | 11007,
/* attach key blob of KM_TAG_SOTER_AUTO_SIGNED_COMMON_KEY_WHEN_GET_PUBLIC_KEY if needed */
KM_TAG_SOTER_AUTO_SIGNED_COMMON_KEY_WHEN_GET_PUBLIC_KEY_BLOB = KM_BYTES | 11008,
} 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,
// KM_ALGORITHM_DSA = 2, -- Removed, do not re-use value 2.
KM_ALGORITHM_EC = 3,
/* Block ciphers algorithms */
KM_ALGORITHM_AES = 32,
/* MAC algorithms */
KM_ALGORITHM_HMAC = 128,
} keymaster_algorithm_t;
/**
* Symmetric block cipher modes provided by keymaster implementations.
*/
typedef enum {
/* Unauthenticated modes, usable only for encryption/decryption and not generally recommended
* except for compatibility with existing other protocols. */
KM_MODE_ECB = 1,
KM_MODE_CBC = 2,
KM_MODE_CTR = 3,
/* Authenticated modes, usable for encryption/decryption and signing/verification. Recommended
* over unauthenticated modes for all purposes. */
KM_MODE_GCM = 32,
} 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, /* deprecated */
KM_PAD_RSA_OAEP = 2,
KM_PAD_RSA_PSS = 3,
KM_PAD_RSA_PKCS1_1_5_ENCRYPT = 4,
KM_PAD_RSA_PKCS1_1_5_SIGN = 5,
KM_PAD_PKCS7 = 64,
} keymaster_padding_t;
/**
* Digests provided by keymaster implementations.
*/
typedef enum {
KM_DIGEST_NONE = 0,
KM_DIGEST_MD5 = 1, /* Optional, may not be implemented in hardware, will be handled in software
* if needed. */
KM_DIGEST_SHA1 = 2,
KM_DIGEST_SHA_2_224 = 3,
KM_DIGEST_SHA_2_256 = 4,
KM_DIGEST_SHA_2_384 = 5,
KM_DIGEST_SHA_2_512 = 6,
} keymaster_digest_t;
/**
* The origin of a key (or pair), i.e. where it was generated. Note that KM_TAG_ORIGIN can be found
* in either the hardware-enforced or software-enforced list for a key, indicating whether the key
* is hardware or software-based. Specifically, a key with KM_ORIGIN_GENERATED in the
* hardware-enforced list is guaranteed never to have existed outide the secure hardware.
*/
typedef enum {
KM_ORIGIN_GENERATED = 0, /* Generated in keymaster */
KM_ORIGIN_IMPORTED = 2, /* Imported, origin unknown */
KM_ORIGIN_UNKNOWN = 3, /* Keymaster did not record origin. This value can only be seen on
* keys in a keymaster0 implementation. The keymaster0 adapter uses
* this value to document the fact that it is unkown whether the key
* was generated inside or imported into keymaster. */
} 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 */
KM_KEY_FORMAT_PKCS8 = 1, /* for asymmetric key pair import */
KM_KEY_FORMAT_RAW = 3, /* for symmetric key import */
} 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_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_MISSING_MAC_LENGTH = -53,
KM_ERROR_KEY_RATE_LIMIT_EXCEEDED = -54,
KM_ERROR_CALLER_NONCE_PROHIBITED = -55,
KM_ERROR_KEY_MAX_OPS_EXCEEDED = -56,
KM_ERROR_INVALID_MAC_LENGTH = -57,
KM_ERROR_MISSING_MIN_MAC_LENGTH = -58,
KM_ERROR_UNSUPPORTED_MIN_MAC_LENGTH = -59,
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_UINT_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(&param, 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(&param, 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(&param, 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(&param, 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(&param, 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(&param, 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_UINT:
case KM_UINT_REP:
return KEYMASTER_SIMPLE_COMPARE(a->integer, b->integer);
case KM_ULONG:
case KM_ULONG_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);
}
}
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif // ANDROID_HARDWARE_KEYMASTER_DEFS_H
@@ -0,0 +1,157 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_LIGHTS_INTERFACE_H
#define ANDROID_LIGHTS_INTERFACE_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <hardware/hardware.h>
__BEGIN_DECLS
/**
* The id of this module
*/
#define LIGHTS_HARDWARE_MODULE_ID "lights"
/*
* These light IDs correspond to logical lights, not physical.
* So for example, if your INDICATOR light is in line with your
* BUTTONS, it might make sense to also light the INDICATOR
* light to a reasonable color when the BUTTONS are lit.
*/
#define LIGHT_ID_BACKLIGHT "backlight"
#define LIGHT_ID_KEYBOARD "keyboard"
#define LIGHT_ID_BUTTONS "buttons"
#define LIGHT_ID_BATTERY "battery"
#define LIGHT_ID_NOTIFICATIONS "notifications"
#define LIGHT_ID_ATTENTION "attention"
/*
* These lights aren't currently supported by the higher
* layers, but could be someday, so we have the constants
* here now.
*/
#define LIGHT_ID_BLUETOOTH "bluetooth"
#define LIGHT_ID_WIFI "wifi"
/*
* Additional hardware-specific lights
*/
#define LIGHT_ID_CAPS "caps"
#define LIGHT_ID_FUNC "func"
/* ************************************************************************
* Flash modes for the flashMode field of light_state_t.
*/
#define LIGHT_FLASH_NONE 0
/**
* To flash the light at a given rate, set flashMode to LIGHT_FLASH_TIMED,
* and then flashOnMS should be set to the number of milliseconds to turn
* the light on, followed by the number of milliseconds to turn the light
* off.
*/
#define LIGHT_FLASH_TIMED 1
/**
* To flash the light using hardware assist, set flashMode to
* the hardware mode.
*/
#define LIGHT_FLASH_HARDWARE 2
/**
* Light brightness is managed by a user setting.
*/
#define BRIGHTNESS_MODE_USER 0
/**
* Light brightness is managed by a light sensor.
*/
#define BRIGHTNESS_MODE_SENSOR 1
/**
* Light mode allows multiple LEDs
*/
#define LIGHT_MODE_MULTIPLE_LEDS 0x01
/**
* The parameters that can be set for a given light.
*
* Not all lights must support all parameters. If you
* can do something backward-compatible, you should.
*/
struct light_state_t {
/**
* The color of the LED in ARGB.
*
* Do your best here.
* - If your light can only do red or green, if they ask for blue,
* you should do green.
* - If you can only do a brightness ramp, then use this formula:
* unsigned char brightness = ((77*((color>>16)&0x00ff))
* + (150*((color>>8)&0x00ff)) + (29*(color&0x00ff))) >> 8;
* - If you can only do on or off, 0 is off, anything else is on.
*
* The high byte should be ignored. Callers will set it to 0xff (which
* would correspond to 255 alpha).
*
* CyanogenMod: The high byte value can be implemented to control the LEDs
* Brightness from the Lights settings. The value goes from 0x01 to 0xFF.
*/
unsigned int color;
/**
* See the LIGHT_FLASH_* constants
*/
int flashMode;
int flashOnMS;
int flashOffMS;
/**
* Policy used by the framework to manage the light's brightness.
* Currently the values are BRIGHTNESS_MODE_USER and BRIGHTNESS_MODE_SENSOR.
*/
int brightnessMode;
/**
* Define the LEDs modes (multiple, ...).
* See the LIGHTS_MODE_* mask constants.
*/
unsigned int ledsModes;
};
struct light_device_t {
struct hw_device_t common;
/**
* Set the provided lights to the provided values.
*
* Returns: 0 on succes, error code on failure.
*/
int (*set_light)(struct light_device_t* dev,
struct light_state_t const* state);
};
__END_DECLS
#endif // ANDROID_LIGHTS_INTERFACE_H
@@ -0,0 +1,123 @@
/*
* 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_LOCAL_TIME_HAL_INTERFACE_H
#define ANDROID_LOCAL_TIME_HAL_INTERFACE_H
#include <stdint.h>
#include <hardware/hardware.h>
__BEGIN_DECLS
/**
* The id of this module
*/
#define LOCAL_TIME_HARDWARE_MODULE_ID "local_time"
/**
* Name of the local time devices to open
*/
#define LOCAL_TIME_HARDWARE_INTERFACE "local_time_hw_if"
/**********************************************************************/
/**
* A structure used to collect low level sync data in a lab environment. Most
* HAL implementations will never need this structure.
*/
struct local_time_debug_event {
int64_t local_timesync_event_id;
int64_t local_time;
};
/**
* 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 local_time_module {
struct hw_module_t common;
};
struct local_time_hw_device {
/**
* Common methods of the local time hardware device. This *must* be the first member of
* local_time_hw_device as users of this structure will cast a hw_device_t to
* local_time_hw_device pointer in contexts where it's known the hw_device_t references a
* local_time_hw_device.
*/
struct hw_device_t common;
/**
*
* Returns the current value of the system wide local time counter
*/
int64_t (*get_local_time)(struct local_time_hw_device* dev);
/**
*
* Returns the nominal frequency (in hertz) of the system wide local time
* counter
*/
uint64_t (*get_local_freq)(struct local_time_hw_device* dev);
/**
*
* Sets the HW slew rate of oscillator which drives the system wide local
* time counter. On success, platforms should return 0. Platforms which
* do not support HW slew should leave this method set to NULL.
*
* Valid values for rate range from MIN_INT16 to MAX_INT16. Platform
* implementations should attempt map this range linearly to the min/max
* slew rate of their hardware.
*/
int (*set_local_slew)(struct local_time_hw_device* dev, int16_t rate);
/**
*
* A method used to collect low level sync data in a lab environments.
* Most HAL implementations will simply set this member to NULL, or return
* -EINVAL to indicate that this functionality is not supported.
* Production HALs should never support this method.
*/
int (*get_debug_log)(struct local_time_hw_device* dev,
struct local_time_debug_event* records,
int max_records);
};
typedef struct local_time_hw_device local_time_hw_device_t;
/** convenience API for opening and closing a supported device */
static inline int local_time_hw_device_open(
const struct hw_module_t* module,
struct local_time_hw_device** device)
{
return module->methods->open(module, LOCAL_TIME_HARDWARE_INTERFACE,
(struct hw_device_t**)device);
}
static inline int local_time_hw_device_close(struct local_time_hw_device* device)
{
return device->common.close(&device->common);
}
__END_DECLS
#endif // ANDROID_LOCAL_TIME_INTERFACE_H
@@ -0,0 +1,160 @@
/*
* Copyright (C) 2013 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_MEMTRACK_H
#define ANDROID_INCLUDE_HARDWARE_MEMTRACK_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <hardware/hardware.h>
__BEGIN_DECLS
#define MEMTRACK_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
/**
* The id of this module
*/
#define MEMTRACK_HARDWARE_MODULE_ID "memtrack"
/*
* The Memory Tracker HAL is designed to return information about device-specific
* memory usage. The primary goal is to be able to track memory that is not
* trackable in any other way, for example texture memory that is allocated by
* a process, but not mapped in to that process' address space.
* A secondary goal is to be able to categorize memory used by a process into
* GL, graphics, etc. All memory sizes should be in real memory usage,
* accounting for stride, bit depth, rounding up to page size, etc.
*
* A process collecting memory statistics will call getMemory for each
* combination of pid and memory type. For each memory type that it recognizes
* the HAL should fill out an array of memtrack_record structures breaking
* down the statistics of that memory type as much as possible. For example,
* getMemory(<pid>, MEMTRACK_TYPE_GL) might return:
* { { 4096, ACCOUNTED | PRIVATE | SYSTEM },
* { 40960, UNACCOUNTED | PRIVATE | SYSTEM },
* { 8192, ACCOUNTED | PRIVATE | DEDICATED },
* { 8192, UNACCOUNTED | PRIVATE | DEDICATED } }
* If the HAL could not differentiate between SYSTEM and DEDICATED memory, it
* could return:
* { { 12288, ACCOUNTED | PRIVATE },
* { 49152, UNACCOUNTED | PRIVATE } }
*
* Memory should not overlap between types. For example, a graphics buffer
* that has been mapped into the GPU as a surface should show up when
* MEMTRACK_TYPE_GRAPHICS is requested, and not when MEMTRACK_TYPE_GL
* is requested.
*/
enum memtrack_type {
MEMTRACK_TYPE_OTHER = 0,
MEMTRACK_TYPE_GL = 1,
MEMTRACK_TYPE_GRAPHICS = 2,
MEMTRACK_TYPE_MULTIMEDIA = 3,
MEMTRACK_TYPE_CAMERA = 4,
MEMTRACK_NUM_TYPES,
};
struct memtrack_record {
size_t size_in_bytes;
unsigned int flags;
};
/**
* Flags to differentiate memory that can already be accounted for in
* /proc/<pid>/smaps,
* (Shared_Clean + Shared_Dirty + Private_Clean + Private_Dirty = Size).
* In general, memory mapped in to a userspace process is accounted unless
* it was mapped with remap_pfn_range.
* Exactly one of these should be set.
*/
#define MEMTRACK_FLAG_SMAPS_ACCOUNTED (1 << 1)
#define MEMTRACK_FLAG_SMAPS_UNACCOUNTED (1 << 2)
/**
* Flags to differentiate memory shared across multiple processes vs. memory
* used by a single process. Only zero or one of these may be set in a record.
* If none are set, record is assumed to count shared + private memory.
*/
#define MEMTRACK_FLAG_SHARED (1 << 3)
#define MEMTRACK_FLAG_SHARED_PSS (1 << 4) /* shared / num_procesess */
#define MEMTRACK_FLAG_PRIVATE (1 << 5)
/**
* Flags to differentiate memory taken from the kernel's allocation pool vs.
* memory that is dedicated to non-kernel allocations, for example a carveout
* or separate video memory. Only zero or one of these may be set in a record.
* If none are set, record is assumed to count system + dedicated memory.
*/
#define MEMTRACK_FLAG_SYSTEM (1 << 6)
#define MEMTRACK_FLAG_DEDICATED (1 << 7)
/**
* Flags to differentiate memory accessible by the CPU in non-secure mode vs.
* memory that is protected. Only zero or one of these may be set in a record.
* If none are set, record is assumed to count secure + nonsecure memory.
*/
#define MEMTRACK_FLAG_NONSECURE (1 << 8)
#define MEMTRACK_FLAG_SECURE (1 << 9)
/**
* 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.
*/
typedef struct memtrack_module {
struct hw_module_t common;
/**
* (*init)() performs memtrack management setup actions and is called
* once before any calls to getMemory().
* Returns 0 on success, -errno on error.
*/
int (*init)(const struct memtrack_module *module);
/**
* (*getMemory)() expects an array of record objects and populates up to
* *num_record structures with the sizes of memory plus associated flags for
* that memory. It also updates *num_records with the total number of
* records it could return if *num_records was large enough when passed in.
* Returning records with size 0 is expected, the number of records should
* not vary between calls to getMemory for the same memory type, even
* for different pids.
*
* The caller will often call getMemory for a type and pid with
* *num_records == 0 to determine how many records to allocate room for,
* this case should be a fast-path in the HAL, returning a constant and
* not querying any kernel files. If *num_records passed in is 0,
* then records may be NULL.
*
* This function must be thread-safe, it may get called from multiple
* threads at the same time.
*
* Returns 0 on success, -ENODEV if the type is not supported, -errno
* on other errors.
*/
int (*getMemory)(const struct memtrack_module *module,
pid_t pid,
int type,
struct memtrack_record *records,
size_t *num_records);
} memtrack_module_t;
__END_DECLS
#endif // ANDROID_INCLUDE_HARDWARE_MEMTRACK_H
@@ -0,0 +1,302 @@
/*
* Copyright (C) 2011, 2012 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_NFC_HAL_INTERFACE_H
#define ANDROID_NFC_HAL_INTERFACE_H
#include <stdint.h>
#include <strings.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <hardware/hardware.h>
__BEGIN_DECLS
/* NFC device HAL for NCI-based NFC controllers.
*
* This HAL allows NCI silicon vendors to make use
* of the core NCI stack in Android for their own silicon.
*
* The responibilities of the NCI HAL implementation
* are as follows:
*
* - Implement the transport to the NFC controller
* - Implement each of the HAL methods specified below as applicable to their silicon
* - Pass up received NCI messages from the controller to the stack
*
* A simplified timeline of NCI HAL method calls:
* 1) Core NCI stack calls open()
* 2) Core NCI stack executes CORE_RESET and CORE_INIT through calls to write()
* 3) Core NCI stack calls core_initialized() to allow HAL to do post-init configuration
* 4) Core NCI stack calls pre_discover() to allow HAL to prepare for RF discovery
* 5) Core NCI stack starts discovery through calls to write()
* 6) Core NCI stack stops discovery through calls to write() (e.g. screen turns off)
* 7) Core NCI stack calls pre_discover() to prepare for RF discovery (e.g. screen turned back on)
* 8) Core NCI stack starts discovery through calls to write()
* ...
* ...
* 9) Core NCI stack calls close()
*/
#define NFC_NCI_HARDWARE_MODULE_ID "nfc_nci"
#define NFC_NCI_BCM2079X_HARDWARE_MODULE_ID "nfc_nci.bcm2079x"
#define NFC_NCI_NXP_PN54X_HARDWARE_MODULE_ID "nfc_nci.pn54x"
#define NFC_NCI_CONTROLLER "nci"
/*
* nfc_nci_module_t should contain module-specific parameters
*/
typedef struct nfc_nci_module_t {
/**
* Common methods of the NFC NCI module. This *must* be the first member of
* nfc_nci_module_t as users of this structure will cast a hw_module_t to
* nfc_nci_module_t pointer in contexts where it's known the hw_module_t references a
* nfc_nci_module_t.
*/
struct hw_module_t common;
} nfc_nci_module_t;
/*
* HAL events that can be passed back to the stack
*/
typedef uint8_t nfc_event_t;
enum {
HAL_NFC_OPEN_CPLT_EVT = 0x00,
HAL_NFC_CLOSE_CPLT_EVT = 0x01,
HAL_NFC_POST_INIT_CPLT_EVT = 0x02,
HAL_NFC_PRE_DISCOVER_CPLT_EVT = 0x03,
HAL_NFC_REQUEST_CONTROL_EVT = 0x04,
HAL_NFC_RELEASE_CONTROL_EVT = 0x05,
HAL_NFC_ERROR_EVT = 0x06
};
/*
* Allowed status return values for each of the HAL methods
*/
typedef uint8_t nfc_status_t;
enum {
HAL_NFC_STATUS_OK = 0x00,
HAL_NFC_STATUS_FAILED = 0x01,
HAL_NFC_STATUS_ERR_TRANSPORT = 0x02,
HAL_NFC_STATUS_ERR_CMD_TIMEOUT = 0x03,
HAL_NFC_STATUS_REFUSED = 0x04
};
/*
* The callback passed in from the NFC stack that the HAL
* can use to pass events back to the stack.
*/
typedef void (nfc_stack_callback_t) (nfc_event_t event, nfc_status_t event_status);
/*
* The callback passed in from the NFC stack that the HAL
* can use to pass incomming data to the stack.
*/
typedef void (nfc_stack_data_callback_t) (uint16_t data_len, uint8_t* p_data);
/* nfc_nci_device_t starts with a hw_device_t struct,
* followed by device-specific methods and members.
*
* All methods in the NCI HAL are asynchronous.
*/
typedef struct nfc_nci_device {
/**
* Common methods of the NFC NCI device. This *must* be the first member of
* nfc_nci_device_t as users of this structure will cast a hw_device_t to
* nfc_nci_device_t pointer in contexts where it's known the hw_device_t references a
* nfc_nci_device_t.
*/
struct hw_device_t common;
/*
* (*open)() Opens the NFC controller device and performs initialization.
* This may include patch download and other vendor-specific initialization.
*
* If open completes successfully, the controller should be ready to perform
* NCI initialization - ie accept CORE_RESET and subsequent commands through
* the write() call.
*
* If open() returns 0, the NCI stack will wait for a HAL_NFC_OPEN_CPLT_EVT
* before continuing.
*
* If open() returns any other value, the NCI stack will stop.
*
*/
int (*open)(const struct nfc_nci_device *p_dev, nfc_stack_callback_t *p_cback,
nfc_stack_data_callback_t *p_data_cback);
/*
* (*write)() Performs an NCI write.
*
* This method may queue writes and return immediately. The only
* requirement is that the writes are executed in order.
*/
int (*write)(const struct nfc_nci_device *p_dev, uint16_t data_len, const uint8_t *p_data);
/*
* (*core_initialized)() is called after the CORE_INIT_RSP is received from the NFCC.
* At this time, the HAL can do any chip-specific configuration.
*
* If core_initialized() returns 0, the NCI stack will wait for a HAL_NFC_POST_INIT_CPLT_EVT
* before continuing.
*
* If core_initialized() returns any other value, the NCI stack will continue
* immediately.
*/
int (*core_initialized)(const struct nfc_nci_device *p_dev, uint8_t* p_core_init_rsp_params);
/*
* (*pre_discover)() Is called every time before starting RF discovery.
* It is a good place to do vendor-specific configuration that must be
* performed every time RF discovery is about to be started.
*
* If pre_discover() returns 0, the NCI stack will wait for a HAL_NFC_PRE_DISCOVER_CPLT_EVT
* before continuing.
*
* If pre_discover() returns any other value, the NCI stack will start
* RF discovery immediately.
*/
int (*pre_discover)(const struct nfc_nci_device *p_dev);
/*
* (*close)() Closed the NFC controller. Should free all resources.
*/
int (*close)(const struct nfc_nci_device *p_dev);
/*
* (*control_granted)() Grant HAL the exclusive control to send NCI commands.
* Called in response to HAL_REQUEST_CONTROL_EVT.
* Must only be called when there are no NCI commands pending.
* HAL_RELEASE_CONTROL_EVT will notify when HAL no longer needs exclusive control.
*/
int (*control_granted)(const struct nfc_nci_device *p_dev);
/*
* (*power_cycle)() Restart controller by power cyle;
* HAL_OPEN_CPLT_EVT will notify when operation is complete.
*/
int (*power_cycle)(const struct nfc_nci_device *p_dev);
} nfc_nci_device_t;
/*
* Convenience methods that the NFC stack can use to open
* and close an NCI device
*/
static inline int nfc_nci_open(const struct hw_module_t* module,
nfc_nci_device_t** dev) {
return module->methods->open(module, NFC_NCI_CONTROLLER,
(struct hw_device_t**) dev);
}
static inline int nfc_nci_close(nfc_nci_device_t* dev) {
return dev->common.close(&dev->common);
}
/*
* End NFC NCI HAL
*/
/*
* This is a limited NFC HAL for NXP PN544-based devices.
* This HAL as Android is moving to
* an NCI-based NFC stack.
*
* All NCI-based NFC controllers should use the NFC-NCI
* HAL instead.
* Begin PN544 specific HAL
*/
#define NFC_HARDWARE_MODULE_ID "nfc"
#define NFC_PN544_CONTROLLER "pn544"
typedef struct nfc_module_t {
/**
* Common methods of the NFC NXP PN544 module. This *must* be the first member of
* nfc_module_t as users of this structure will cast a hw_module_t to
* nfc_module_t pointer in contexts where it's known the hw_module_t references a
* nfc_module_t.
*/
struct hw_module_t common;
} nfc_module_t;
/*
* PN544 linktypes.
* UART
* I2C
* USB (uses UART DAL)
*/
typedef enum {
PN544_LINK_TYPE_UART,
PN544_LINK_TYPE_I2C,
PN544_LINK_TYPE_USB,
PN544_LINK_TYPE_INVALID,
} nfc_pn544_linktype;
typedef struct {
/**
* Common methods of the NFC NXP PN544 device. This *must* be the first member of
* nfc_pn544_device_t as users of this structure will cast a hw_device_t to
* nfc_pn544_device_t pointer in contexts where it's known the hw_device_t references a
* nfc_pn544_device_t.
*/
struct hw_device_t common;
/* The number of EEPROM registers to write */
uint32_t num_eeprom_settings;
/* The actual EEPROM settings
* For PN544, each EEPROM setting is a 4-byte entry,
* of the format [0x00, addr_msb, addr_lsb, value].
*/
uint8_t* eeprom_settings;
/* The link type to which the PN544 is connected */
nfc_pn544_linktype linktype;
/* The device node to which the PN544 is connected */
const char* device_node;
/* On Crespo we had an I2C issue that would cause us to sometimes read
* the I2C slave address (0x57) over the bus. libnfc contains
* a hack to ignore this byte and try to read the length byte
* again.
* Set to 0 to disable the workaround, 1 to enable it.
*/
uint8_t enable_i2c_workaround;
/* I2C slave address. Multiple I2C addresses are
* possible for PN544 module. Configure address according to
* board design.
*/
uint8_t i2c_device_address;
} nfc_pn544_device_t;
static inline int nfc_pn544_open(const struct hw_module_t* module,
nfc_pn544_device_t** dev) {
return module->methods->open(module, NFC_PN544_CONTROLLER,
(struct hw_device_t**) dev);
}
static inline int nfc_pn544_close(nfc_pn544_device_t* dev) {
return dev->common.close(&dev->common);
}
/*
* End PN544 specific HAL
*/
__END_DECLS
#endif // ANDROID_NFC_HAL_INTERFACE_H
@@ -0,0 +1,95 @@
/*
* Copyright (C) 2013 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_NFC_TAG_HAL_INTERFACE_H
#define ANDROID_NFC_TAG_HAL_INTERFACE_H
#include <stdint.h>
#include <hardware/hardware.h>
__BEGIN_DECLS
/*
* HAL for programmable NFC tags.
*
*/
#define NFC_TAG_HARDWARE_MODULE_ID "nfc_tag"
#define NFC_TAG_ID "tag"
typedef struct nfc_tag_module_t {
/**
* Common methods of the NFC tag module. This *must* be the first member of
* nfc_tag_module_t as users of this structure will cast a hw_module_t to
* nfc_tag_module_t pointer in contexts where it's known the hw_module_t references a
* nfc_tag_module_t.
*/
struct hw_module_t common;
} nfc_tag_module_t;
typedef struct nfc_tag_device {
/**
* Common methods of the NFC tag device. This *must* be the first member of
* nfc_tag_device_t as users of this structure will cast a hw_device_t to
* nfc_tag_device_t pointer in contexts where it's known the hw_device_t references a
* nfc_tag_device_t.
*/
struct hw_device_t common;
/**
* Initialize the NFC tag.
*
* The driver must:
* * Set the static lock bytes to read only
* * Configure the Capability Container to disable write acess
* eg: 0xE1 0x10 <size> 0x0F
*
* This function is called once before any calls to setContent().
*
* Return 0 on success or -errno on error.
*/
int (*init)(const struct nfc_tag_device *dev);
/**
* Set the NFC tag content.
*
* The driver must write <data> in the data area of the tag starting at
* byte 0 of block 4 and zero the rest of the data area.
*
* Returns 0 on success or -errno on error.
*/
int (*setContent)(const struct nfc_tag_device *dev, const uint8_t *data, size_t len);
/**
* Returns the memory size of the data area.
*/
int (*getMemorySize)(const struct nfc_tag_device *dev);
} nfc_tag_device_t;
static inline int nfc_tag_open(const struct hw_module_t* module,
nfc_tag_device_t** dev) {
return module->methods->open(module, NFC_TAG_ID,
(struct hw_device_t**)dev);
}
static inline int nfc_tag_close(nfc_tag_device_t* dev) {
return dev->common.close(&dev->common);
}
__END_DECLS
#endif // ANDROID_NFC_TAG_HAL_INTERFACE_H
@@ -0,0 +1,184 @@
/*
* Copyright (C) 2012 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_POWER_H
#define ANDROID_INCLUDE_HARDWARE_POWER_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <hardware/hardware.h>
__BEGIN_DECLS
#define POWER_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
#define POWER_MODULE_API_VERSION_0_2 HARDWARE_MODULE_API_VERSION(0, 2)
#define POWER_MODULE_API_VERSION_0_3 HARDWARE_MODULE_API_VERSION(0, 3)
/**
* The id of this module
*/
#define POWER_HARDWARE_MODULE_ID "power"
/*
* Power hint identifiers passed to (*powerHint)
*/
typedef enum {
POWER_HINT_VSYNC = 0x00000001,
POWER_HINT_INTERACTION = 0x00000002,
/* DO NOT USE POWER_HINT_VIDEO_ENCODE/_DECODE! They will be removed in
* KLP.
*/
POWER_HINT_VIDEO_ENCODE = 0x00000003,
POWER_HINT_VIDEO_DECODE = 0x00000004,
POWER_HINT_LOW_POWER = 0x00000005,
POWER_HINT_CAM_PREVIEW = 0x00000006,
POWER_HINT_CPU_BOOST = 0x00000010,
POWER_HINT_LAUNCH_BOOST = 0x00000011,
POWER_HINT_AUDIO = 0x00000020,
POWER_HINT_SET_PROFILE = 0x00000030
} power_hint_t;
typedef enum {
POWER_FEATURE_DOUBLE_TAP_TO_WAKE = 0x00000001,
POWER_FEATURE_SUPPORTED_PROFILES = 0x00001000
} feature_t;
/**
* Process info, passed as an opaque handle when
* using POWER_HINT_LAUNCH_BOOST.
*/
typedef struct launch_boost_info {
pid_t pid;
const char* packageName;
} launch_boost_info_t;
/**
* 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.
*/
typedef struct power_module {
struct hw_module_t common;
/*
* (*init)() performs power management setup actions at runtime
* startup, such as to set default cpufreq parameters. This is
* called only by the Power HAL instance loaded by
* PowerManagerService.
*/
void (*init)(struct power_module *module);
/*
* (*setInteractive)() performs power management actions upon the
* system entering interactive state (that is, the system is awake
* and ready for interaction, often with UI devices such as
* display and touchscreen enabled) or non-interactive state (the
* system appears asleep, display usually turned off). The
* non-interactive state is usually entered after a period of
* inactivity, in order to conserve battery power during
* such inactive periods.
*
* Typical actions are to turn on or off devices and adjust
* cpufreq parameters. This function may also call the
* appropriate interfaces to allow the kernel to suspend the
* system to low-power sleep state when entering non-interactive
* state, and to disallow low-power suspend when the system is in
* interactive state. When low-power suspend state is allowed, the
* kernel may suspend the system whenever no wakelocks are held.
*
* on is non-zero when the system is transitioning to an
* interactive / awake state, and zero when transitioning to a
* non-interactive / asleep state.
*
* This function is called to enter non-interactive state after
* turning off the screen (if present), and called to enter
* interactive state prior to turning on the screen.
*/
void (*setInteractive)(struct power_module *module, int on);
/*
* (*powerHint) is called to pass hints on power requirements, which
* may result in adjustment of power/performance parameters of the
* cpufreq governor and other controls. The possible hints are:
*
* POWER_HINT_VSYNC
*
* Foreground app has started or stopped requesting a VSYNC pulse
* from SurfaceFlinger. If the app has started requesting VSYNC
* then CPU and GPU load is expected soon, and it may be appropriate
* to raise speeds of CPU, memory bus, etc. The data parameter is
* non-zero to indicate VSYNC pulse is now requested, or zero for
* VSYNC pulse no longer requested.
*
* POWER_HINT_INTERACTION
*
* User is interacting with the device, for example, touchscreen
* events are incoming. CPU and GPU load may be expected soon,
* and it may be appropriate to raise speeds of CPU, memory bus,
* etc. The data parameter is the estimated length of the interaction
* in milliseconds, or 0 if unknown.
*
* POWER_HINT_LOW_POWER
*
* Low power mode is activated or deactivated. Low power mode
* is intended to save battery at the cost of performance. The data
* parameter is non-zero when low power mode is activated, and zero
* when deactivated.
*
* POWER_HINT_CPU_BOOST
*
* An operation is happening where it would be ideal for the CPU to
* be boosted for a specific duration. The data parameter is an
* integer value of the boost duration in microseconds.
*
* A particular platform may choose to ignore any hint.
*
* availability: version 0.2
*
*/
void (*powerHint)(struct power_module *module, power_hint_t hint,
void *data);
/*
* (*setFeature) is called to turn on or off a particular feature
* depending on the state parameter. The possible features are:
*
* FEATURE_DOUBLE_TAP_TO_WAKE
*
* Enabling/Disabling this feature will allow/disallow the system
* to wake up by tapping the screen twice.
*
* availability: version 0.3
*
*/
void (*setFeature)(struct power_module *module, feature_t feature, int state);
/*
* (*getFeature) is called to get the current value of a particular
* feature or capability from the hardware or PowerHAL
*/
int (*getFeature)(struct power_module *module, feature_t feature);
} power_module_t;
__END_DECLS
#endif // ANDROID_INCLUDE_HARDWARE_POWER_H
@@ -0,0 +1,94 @@
/*
* 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_INCLUDE_HARDWARE_QEMU_PIPE_H
#define ANDROID_INCLUDE_HARDWARE_QEMU_PIPE_H
#include <sys/cdefs.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <pthread.h> /* for pthread_once() */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#ifndef D
# define D(...) do{}while(0)
#endif
/* Try to open a new Qemu fast-pipe. This function returns a file descriptor
* that can be used to communicate with a named service managed by the
* emulator.
*
* This file descriptor can be used as a standard pipe/socket descriptor.
*
* 'pipeName' is the name of the emulator service you want to connect to.
* E.g. 'opengles' or 'camera'.
*
* On success, return a valid file descriptor
* Returns -1 on error, and errno gives the error code, e.g.:
*
* EINVAL -> unknown/unsupported pipeName
* ENOSYS -> fast pipes not available in this system.
*
* ENOSYS should never happen, except if you're trying to run within a
* misconfigured emulator.
*
* You should be able to open several pipes to the same pipe service,
* except for a few special cases (e.g. GSM modem), where EBUSY will be
* returned if more than one client tries to connect to it.
*/
static __inline__ int
qemu_pipe_open(const char* pipeName)
{
char buff[256];
int buffLen;
int fd, ret;
if (pipeName == NULL || pipeName[0] == '\0') {
errno = EINVAL;
return -1;
}
snprintf(buff, sizeof buff, "pipe:%s", pipeName);
fd = open("/dev/qemu_pipe", O_RDWR);
if (fd < 0 && errno == ENOENT)
fd = open("/dev/goldfish_pipe", O_RDWR);
if (fd < 0) {
D("%s: Could not open /dev/qemu_pipe: %s", __FUNCTION__, strerror(errno));
//errno = ENOSYS;
return -1;
}
buffLen = strlen(buff);
ret = TEMP_FAILURE_RETRY(write(fd, buff, buffLen+1));
if (ret != buffLen+1) {
D("%s: Could not connect to %s pipe service: %s", __FUNCTION__, pipeName, strerror(errno));
if (ret == 0) {
errno = ECONNRESET;
} else if (ret > 0) {
errno = EINVAL;
}
return -1;
}
return fd;
}
#endif /* ANDROID_INCLUDE_HARDWARE_QEMUD_PIPE_H */
@@ -0,0 +1,153 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_INCLUDE_HARDWARE_QEMUD_H
#define ANDROID_INCLUDE_HARDWARE_QEMUD_H
#include <cutils/sockets.h>
#include "qemu_pipe.h"
/* the following is helper code that is used by the QEMU-specific
* hardware HAL modules to communicate with the emulator program
* through the 'qemud' multiplexing daemon, or through the qemud
* pipe.
*
* see the documentation comments for details in
* development/emulator/qemud/qemud.c
*
* all definitions here are built into the HAL module to avoid
* having to write a tiny shared library for this.
*/
/* we expect the D macro to be defined to a function macro
* that sends its formatted string argument(s) to the log.
* If not, ignore the traces.
*/
#ifndef D
# define D(...) ((void)0)
#endif
static __inline__ int
qemud_fd_write(int fd, const void* buff, int len)
{
int len2;
do {
len2 = write(fd, buff, len);
} while (len2 < 0 && errno == EINTR);
return len2;
}
static __inline__ int
qemud_fd_read(int fd, void* buff, int len)
{
int len2;
do {
len2 = read(fd, buff, len);
} while (len2 < 0 && errno == EINTR);
return len2;
}
static __inline__ int
qemud_channel_open(const char* name)
{
int fd;
int namelen = strlen(name);
char answer[2];
char pipe_name[256];
/* First, try to connect to the pipe. */
snprintf(pipe_name, sizeof(pipe_name), "qemud:%s", name);
fd = qemu_pipe_open(pipe_name);
if (fd < 0) {
D("QEMUD pipe is not available for %s: %s", name, strerror(errno));
/* If pipe is not available, connect to qemud control socket */
fd = socket_local_client( "qemud",
ANDROID_SOCKET_NAMESPACE_RESERVED,
SOCK_STREAM );
if (fd < 0) {
D("no qemud control socket: %s", strerror(errno));
return -1;
}
/* send service name to connect */
if (qemud_fd_write(fd, name, namelen) != namelen) {
D("can't send service name to qemud: %s",
strerror(errno));
close(fd);
return -1;
}
/* read answer from daemon */
if (qemud_fd_read(fd, answer, 2) != 2 ||
answer[0] != 'O' || answer[1] != 'K') {
D("cant' connect to %s service through qemud", name);
close(fd);
return -1;
}
}
return fd;
}
static __inline__ int
qemud_channel_send(int fd, const void* msg, int msglen)
{
char header[5];
if (msglen < 0)
msglen = strlen((const char*)msg);
if (msglen == 0)
return 0;
snprintf(header, sizeof header, "%04x", msglen);
if (qemud_fd_write(fd, header, 4) != 4) {
D("can't write qemud frame header: %s", strerror(errno));
return -1;
}
if (qemud_fd_write(fd, msg, msglen) != msglen) {
D("can4t write qemud frame payload: %s", strerror(errno));
return -1;
}
return 0;
}
static __inline__ int
qemud_channel_recv(int fd, void* msg, int msgsize)
{
char header[5];
int size, avail;
if (qemud_fd_read(fd, header, 4) != 4) {
D("can't read qemud frame header: %s", strerror(errno));
return -1;
}
header[4] = 0;
if (sscanf(header, "%04x", &size) != 1) {
D("malformed qemud frame header: '%.*s'", 4, header);
return -1;
}
if (size > msgsize)
return -1;
if (qemud_fd_read(fd, msg, size) != size) {
D("can't read qemud frame payload: %s", strerror(errno));
return -1;
}
return size;
}
#endif /* ANDROID_INCLUDE_HARDWARE_QEMUD_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
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,130 @@
/*
* 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 <system/audio.h>
#include <system/sound_trigger.h>
#include <hardware/hardware.h>
#ifndef ANDROID_SOUND_TRIGGER_HAL_H
#define ANDROID_SOUND_TRIGGER_HAL_H
__BEGIN_DECLS
/**
* The id of this module
*/
#define SOUND_TRIGGER_HARDWARE_MODULE_ID "sound_trigger"
/**
* Name of the audio devices to open
*/
#define SOUND_TRIGGER_HARDWARE_INTERFACE "sound_trigger_hw_if"
#define SOUND_TRIGGER_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
#define SOUND_TRIGGER_MODULE_API_VERSION_CURRENT SOUND_TRIGGER_MODULE_API_VERSION_1_0
#define SOUND_TRIGGER_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
#define SOUND_TRIGGER_DEVICE_API_VERSION_CURRENT SOUND_TRIGGER_DEVICE_API_VERSION_1_0
/**
* List of known sound trigger HAL modules. This is the base name of the sound_trigger HAL
* library composed of the "sound_trigger." prefix, one of the base names below and
* a suffix specific to the device.
* e.g: sondtrigger.primary.goldfish.so or sound_trigger.primary.default.so
*/
#define SOUND_TRIGGER_HARDWARE_MODULE_ID_PRIMARY "primary"
/**
* 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 sound_trigger_module {
struct hw_module_t common;
};
typedef void (*recognition_callback_t)(struct sound_trigger_recognition_event *event, void *cookie);
typedef void (*sound_model_callback_t)(struct sound_trigger_model_event *event, void *cookie);
struct sound_trigger_hw_device {
struct hw_device_t common;
/*
* Retrieve implementation properties.
*/
int (*get_properties)(const struct sound_trigger_hw_device *dev,
struct sound_trigger_properties *properties);
/*
* Load a sound model. Once loaded, recognition of this model can be started and stopped.
* Only one active recognition per model at a time. The SoundTrigger service will handle
* concurrent recognition requests by different users/applications on the same model.
* The implementation returns a unique handle used by other functions (unload_sound_model(),
* start_recognition(), etc...
*/
int (*load_sound_model)(const struct sound_trigger_hw_device *dev,
struct sound_trigger_sound_model *sound_model,
sound_model_callback_t callback,
void *cookie,
sound_model_handle_t *handle);
/*
* Unload a sound model. A sound model can be unloaded to make room for a new one to overcome
* implementation limitations.
*/
int (*unload_sound_model)(const struct sound_trigger_hw_device *dev,
sound_model_handle_t handle);
/* Start recognition on a given model. Only one recognition active at a time per model.
* Once recognition succeeds of fails, the callback is called.
* TODO: group recognition configuration parameters into one struct and add key phrase options.
*/
int (*start_recognition)(const struct sound_trigger_hw_device *dev,
sound_model_handle_t sound_model_handle,
const struct sound_trigger_recognition_config *config,
recognition_callback_t callback,
void *cookie);
/* Stop recognition on a given model.
* The implementation does not have to call the callback when stopped via this method.
*/
int (*stop_recognition)(const struct sound_trigger_hw_device *dev,
sound_model_handle_t sound_model_handle);
};
typedef struct sound_trigger_hw_device sound_trigger_hw_device_t;
/** convenience API for opening and closing a supported device */
static inline int sound_trigger_hw_device_open(const struct hw_module_t* module,
struct sound_trigger_hw_device** device)
{
return module->methods->open(module, SOUND_TRIGGER_HARDWARE_INTERFACE,
(struct hw_device_t**)device);
}
static inline int sound_trigger_hw_device_close(struct sound_trigger_hw_device* device)
{
return device->common.close(&device->common);
}
__END_DECLS
#endif // ANDROID_SOUND_TRIGGER_HAL_H
@@ -0,0 +1,408 @@
/*
* Copyright 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_TV_INPUT_INTERFACE_H
#define ANDROID_TV_INPUT_INTERFACE_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <hardware/hardware.h>
#include <system/audio.h>
#include <system/window.h>
__BEGIN_DECLS
/*
* Module versioning information for the TV input hardware module, based on
* tv_input_module_t.common.module_api_version.
*
* Version History:
*
* TV_INPUT_MODULE_API_VERSION_0_1:
* Initial TV input hardware module API.
*
*/
#define TV_INPUT_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
#define TV_INPUT_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION(0, 1)
/*
* The id of this module
*/
#define TV_INPUT_HARDWARE_MODULE_ID "tv_input"
#define TV_INPUT_DEFAULT_DEVICE "default"
/*****************************************************************************/
/*
* 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.
*/
typedef struct tv_input_module {
struct hw_module_t common;
} tv_input_module_t;
/*****************************************************************************/
enum {
/* Generic hardware. */
TV_INPUT_TYPE_OTHER_HARDWARE = 1,
/* Tuner. (e.g. built-in terrestrial tuner) */
TV_INPUT_TYPE_TUNER = 2,
TV_INPUT_TYPE_COMPOSITE = 3,
TV_INPUT_TYPE_SVIDEO = 4,
TV_INPUT_TYPE_SCART = 5,
TV_INPUT_TYPE_COMPONENT = 6,
TV_INPUT_TYPE_VGA = 7,
TV_INPUT_TYPE_DVI = 8,
/* Physical HDMI port. (e.g. HDMI 1) */
TV_INPUT_TYPE_HDMI = 9,
TV_INPUT_TYPE_DISPLAY_PORT = 10,
};
typedef uint32_t tv_input_type_t;
typedef struct tv_input_device_info {
/* Device ID */
int device_id;
/* Type of physical TV input. */
tv_input_type_t type;
union {
struct {
/* HDMI port ID number */
uint32_t port_id;
} hdmi;
/* TODO: add other type specific information. */
int32_t type_info_reserved[16];
};
/* TODO: Add capability if necessary. */
/*
* Audio info
*
* audio_type == AUDIO_DEVICE_NONE if this input has no audio.
*/
audio_devices_t audio_type;
const char* audio_address;
int32_t reserved[16];
} tv_input_device_info_t;
/* See tv_input_event_t for more details. */
enum {
/*
* Hardware notifies the framework that a device is available.
*
* Note that DEVICE_AVAILABLE and DEVICE_UNAVAILABLE events do not represent
* hotplug events (i.e. plugging cable into or out of the physical port).
* These events notify the framework whether the port is available or not.
* For a concrete example, when a user plugs in or pulls out the HDMI cable
* from a HDMI port, it does not generate DEVICE_AVAILABLE and/or
* DEVICE_UNAVAILABLE events. However, if a user inserts a pluggable USB
* tuner into the Android device, it will generate a DEVICE_AVAILABLE event
* and when the port is removed, it should generate a DEVICE_UNAVAILABLE
* event.
*
* For hotplug events, please see STREAM_CONFIGURATION_CHANGED for more
* details.
*
* HAL implementation should register devices by using this event when the
* device boots up. The framework will recognize device reported via this
* event only. In addition, the implementation could use this event to
* notify the framework that a removable TV input device (such as USB tuner
* as stated in the example above) is attached.
*/
TV_INPUT_EVENT_DEVICE_AVAILABLE = 1,
/*
* Hardware notifies the framework that a device is unavailable.
*
* HAL implementation should generate this event when a device registered
* by TV_INPUT_EVENT_DEVICE_AVAILABLE is no longer available. For example,
* the event can indicate that a USB tuner is plugged out from the Android
* device.
*
* Note that this event is not for indicating cable plugged out of the port;
* for that purpose, the implementation should use
* STREAM_CONFIGURATION_CHANGED event. This event represents the port itself
* being no longer available.
*/
TV_INPUT_EVENT_DEVICE_UNAVAILABLE = 2,
/*
* Stream configurations are changed. Client should regard all open streams
* at the specific device are closed, and should call
* get_stream_configurations() again, opening some of them if necessary.
*
* HAL implementation should generate this event when the available stream
* configurations change for any reason. A typical use case of this event
* would be to notify the framework that the input signal has changed
* resolution, or that the cable is plugged out so that the number of
* available streams is 0.
*
* The implementation may use this event to indicate hotplug status of the
* port. the framework regards input devices with no available streams as
* disconnected, so the implementation can generate this event with no
* available streams to indicate that this device is disconnected, and vice
* versa.
*/
TV_INPUT_EVENT_STREAM_CONFIGURATIONS_CHANGED = 3,
/*
* Hardware is done with capture request with the buffer. Client can assume
* ownership of the buffer again.
*
* HAL implementation should generate this event after request_capture() if
* it succeeded. The event shall have the buffer with the captured image.
*/
TV_INPUT_EVENT_CAPTURE_SUCCEEDED = 4,
/*
* Hardware met a failure while processing a capture request or client
* canceled the request. Client can assume ownership of the buffer again.
*
* The event is similar to TV_INPUT_EVENT_CAPTURE_SUCCEEDED, but HAL
* implementation generates this event upon a failure to process
* request_capture(), or a request cancellation.
*/
TV_INPUT_EVENT_CAPTURE_FAILED = 5,
};
typedef uint32_t tv_input_event_type_t;
typedef struct tv_input_capture_result {
/* Device ID */
int device_id;
/* Stream ID */
int stream_id;
/* Sequence number of the request */
uint32_t seq;
/*
* The buffer passed to hardware in request_capture(). The content of
* buffer is undefined (although buffer itself is valid) for
* TV_INPUT_CAPTURE_FAILED event.
*/
buffer_handle_t buffer;
/*
* Error code for the request. -ECANCELED if request is cancelled; other
* error codes are unknown errors.
*/
int error_code;
} tv_input_capture_result_t;
typedef struct tv_input_event {
tv_input_event_type_t type;
union {
/*
* TV_INPUT_EVENT_DEVICE_AVAILABLE: all fields are relevant
* TV_INPUT_EVENT_DEVICE_UNAVAILABLE: only device_id is relevant
* TV_INPUT_EVENT_STREAM_CONFIGURATIONS_CHANGED: only device_id is
* relevant
*/
tv_input_device_info_t device_info;
/*
* TV_INPUT_EVENT_CAPTURE_SUCCEEDED: error_code is not relevant
* TV_INPUT_EVENT_CAPTURE_FAILED: all fields are relevant
*/
tv_input_capture_result_t capture_result;
};
} tv_input_event_t;
typedef struct tv_input_callback_ops {
/*
* event contains the type of the event and additional data if necessary.
* The event object is guaranteed to be valid only for the duration of the
* call.
*
* data is an object supplied at device initialization, opaque to the
* hardware.
    */
void (*notify)(struct tv_input_device* dev,
tv_input_event_t* event, void* data);
} tv_input_callback_ops_t;
enum {
TV_STREAM_TYPE_INDEPENDENT_VIDEO_SOURCE = 1,
TV_STREAM_TYPE_BUFFER_PRODUCER = 2,
};
typedef uint32_t tv_stream_type_t;
typedef struct tv_stream_config {
/*
* ID number of the stream. This value is used to identify the whole stream
* configuration.
*/
int stream_id;
/* Type of the stream */
tv_stream_type_t type;
/* Max width/height of the stream. */
uint32_t max_video_width;
uint32_t max_video_height;
} tv_stream_config_t;
typedef struct buffer_producer_stream {
/*
* IN/OUT: Width / height of the stream. Client may request for specific
* size but hardware may change it. Client must allocate buffers with
* specified width and height.
*/
uint32_t width;
uint32_t height;
/* OUT: Client must set this usage when allocating buffer. */
uint32_t usage;
/* OUT: Client must allocate a buffer with this format. */
uint32_t format;
/* OUT: Client must allocate buffers based on this count. */
uint32_t buffer_count;
} buffer_producer_stream_t;
typedef struct tv_stream {
/* IN: ID in the stream configuration */
int stream_id;
/* OUT: Type of the stream (for convenience) */
tv_stream_type_t type;
/* Data associated with the stream for client's use */
union {
/* OUT: A native handle describing the sideband stream source */
native_handle_t* sideband_stream_source_handle;
/* IN/OUT: Details are in buffer_producer_stream_t */
buffer_producer_stream_t buffer_producer;
};
} tv_stream_t;
/*
* Every device data structure must begin with hw_device_t
* followed by module specific public methods and attributes.
*/
typedef struct tv_input_device {
struct hw_device_t common;
/*
* initialize:
*
* Provide callbacks to the device and start operation. At first, no device
* is available and after initialize() completes, currently available
* devices including static devices should notify via callback.
*
* Framework owns callbacks object.
*
* data is a framework-owned object which would be sent back to the
* framework for each callback notifications.
*
* Return 0 on success.
*/
int (*initialize)(struct tv_input_device* dev,
const tv_input_callback_ops_t* callback, void* data);
/*
* get_stream_configurations:
*
* Get stream configurations for a specific device. An input device may have
* multiple configurations.
*
* The configs object is guaranteed to be valid only until the next call to
* get_stream_configurations() or STREAM_CONFIGURATIONS_CHANGED event.
*
* Return 0 on success.
*/
int (*get_stream_configurations)(const struct tv_input_device* dev,
int device_id, int* num_configurations,
const tv_stream_config_t** configs);
/*
* open_stream:
*
* Open a stream with given stream ID. Caller owns stream object, and the
* populated data is only valid until the stream is closed.
*
* Return 0 on success; -EBUSY if the client should close other streams to
* open the stream; -EEXIST if the stream with the given ID is already open;
* -EINVAL if device_id and/or stream_id are invalid; other non-zero value
* denotes unknown error.
*/
int (*open_stream)(struct tv_input_device* dev, int device_id,
tv_stream_t* stream);
/*
* close_stream:
*
* Close a stream to a device. data in tv_stream_t* object associated with
* the stream_id is obsolete once this call finishes.
*
* Return 0 on success; -ENOENT if the stream is not open; -EINVAL if
* device_id and/or stream_id are invalid.
*/
int (*close_stream)(struct tv_input_device* dev, int device_id,
int stream_id);
/*
* request_capture:
*
* Request buffer capture for a stream. This is only valid for buffer
* producer streams. The buffer should be created with size, format and
* usage specified in the stream. Framework provides seq in an
* increasing sequence per each stream. Hardware should provide the picture
* in a chronological order according to seq. For example, if two
* requests are being processed at the same time, the request with the
* smaller seq should get an earlier frame.
*
* The framework releases the ownership of the buffer upon calling this
* function. When the buffer is filled, hardware notifies the framework
* via TV_INPUT_EVENT_CAPTURE_FINISHED callback, and the ownership is
* transferred back to framework at that time.
*
* Return 0 on success; -ENOENT if the stream is not open; -EINVAL if
* device_id and/or stream_id are invalid; -EWOULDBLOCK if HAL cannot take
* additional requests until it releases a buffer.
*/
int (*request_capture)(struct tv_input_device* dev, int device_id,
int stream_id, buffer_handle_t buffer, uint32_t seq);
/*
* cancel_capture:
*
* Cancel an ongoing capture. Hardware should release the buffer as soon as
* possible via TV_INPUT_EVENT_CAPTURE_FAILED callback.
*
* Return 0 on success; -ENOENT if the stream is not open; -EINVAL if
* device_id, stream_id, and/or seq are invalid.
*/
int (*cancel_capture)(struct tv_input_device* dev, int device_id,
int stream_id, uint32_t seq);
void* reserved[16];
} tv_input_device_t;
__END_DECLS
#endif // ANDROID_TV_INPUT_INTERFACE_H
@@ -0,0 +1,74 @@
/*
* Copyright (C) 2013 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 _HARDWARE_VIBRATOR_H
#define _HARDWARE_VIBRATOR_H
#include <hardware/hardware.h>
__BEGIN_DECLS
#define VIBRATOR_API_VERSION HARDWARE_MODULE_API_VERSION(1,0)
/**
* The id of this module
*/
#define VIBRATOR_HARDWARE_MODULE_ID "vibrator"
/**
* The id of the main vibrator device
*/
#define VIBRATOR_DEVICE_ID_MAIN "main_vibrator"
struct vibrator_device;
typedef struct vibrator_device {
/**
* Common methods of the vibrator device. This *must* be the first member of
* vibrator_device as users of this structure will cast a hw_device_t to
* vibrator_device pointer in contexts where it's known the hw_device_t references a
* vibrator_device.
*/
struct hw_device_t common;
/** Turn on vibrator
*
* What happens when this function is called while the the timeout of a
* previous call has not expired is implementation dependent.
*
* @param timeout_ms number of milliseconds to vibrate
*
* @return 0 in case of success, negative errno code else
*/
int (*vibrator_on)(struct vibrator_device* vibradev, unsigned int timeout_ms);
/** Turn off vibrator
*
* It is not guaranteed that the vibrator will be immediately stopped: the
* behaviour is implementation dependent.
*
* @return 0 in case of success, negative errno code else
*/
int (*vibrator_off)(struct vibrator_device* vibradev);
} vibrator_device_t;
static inline int vibrator_open(const struct hw_module_t* module, vibrator_device_t** device)
{
return module->methods->open(module, VIBRATOR_DEVICE_ID_MAIN, (struct hw_device_t**)device);
}
__END_DECLS
#endif // _HARDWARE_VIBRATOR_H
@@ -0,0 +1,119 @@
/*
* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ANDROID_INCLUDE_WIPOWER_H
#define ANDROID_INCLUDE_WIPOWER_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <stdbool.h>
#include <hardware/hardware.h>
#include <hardware/bluetooth.h>
__BEGIN_DECLS
typedef enum {
OFF =0,
ON
} wipower_state_t;
typedef struct {
unsigned char optional;
unsigned short rect_voltage;
unsigned short rect_current;
unsigned short out_voltage;
unsigned short out_current;
unsigned char temp;
unsigned short rect_voltage_min;
unsigned short rect_voltage_set;
unsigned short rect_voltage_max;
unsigned char alert;
unsigned short rfu1;
unsigned char rfu2;
}__attribute__((packed)) wipower_dyn_data_t;
/** Bluetooth Enable/Disable Callback. */
typedef void (*wipower_state_changed_callback)(wipower_state_t state);
typedef void (*wipower_alerts)(unsigned char alert);
typedef void (*wipower_dynamic_data)(wipower_dyn_data_t* alert_data);
typedef void (*wipower_power_apply)(unsigned char power_flag);
typedef void (*callback_thread_event)(bt_cb_thread_evt evt);
/** Bluetooth DM callback structure. */
typedef struct {
/** set to sizeof(wipower_callbacks_t) */
size_t size;
wipower_state_changed_callback wipower_state_changed_cb;
wipower_alerts wipower_alert;
wipower_dynamic_data wipower_data;
wipower_power_apply wipower_power_event;
callback_thread_event callback_thread_event;
} wipower_callbacks_t;
/** Represents the standard Wipower interface. */
typedef struct {
/** set to sizeof(wipower_interface_t) */
size_t size;
/** Initialize Wipower modules*/
int (*init)(wipower_callbacks_t *wp_callbacks);
/** Enable/Disable Wipower charging */
int (*enable)(bool enable);
int (*set_current_limit)(short value);
unsigned char (*get_current_limit)(void);
wipower_state_t (*get_state)(void);
/** Enable/Disable Wipower charging */
int (*enable_alerts)(bool enable);
int (*enable_data_notify)(bool enable);
int (*enable_power_apply)(bool enable, bool on, bool time_flag);
} wipower_interface_t;
__END_DECLS
#endif /* ANDROID_INCLUDE_WIPOWER_H */