Update sources to compile on Android Nougat

This commit is contained in:
Mr Jenkins 2016-09-01 21:26:27 +02:00
parent 8e6221eef6
commit 8bf9a36de4
113 changed files with 5966 additions and 1948 deletions

0
Android.mk Normal file → Executable file
View file

View file

@ -95,6 +95,7 @@
<ctl name="AIF1OUT0R Mux" value="AIF1_AD0R" />
<ctl name="AIF1 AD0L Mixer ADCL Switch" value="1" />
<ctl name="AIF1 AD0R Mixer ADCR Switch" value="1" />
<ctl name="ADC volume" value="192" />
<ctl name="ADCR Mux" value="DMIC" />
<ctl name="ADCL Mux" value="DMIC" />
</path>
@ -104,7 +105,8 @@
<ctl name="RIGHT ADC input Mixer MIC2 boost Switch" value="1" />
<ctl name="LEFT ADC input Mixer MIC2 boost Switch" value="1" />
<ctl name="MIC2 SRC" value="MIC2" />
<ctl name="MIC2 boost amplifier gain" value="4" />
<ctl name="ADC volume" value="160" />
<ctl name="MIC2 boost amplifier gain" value="3" />
</path>
<!-- dbb phone path -->

View file

@ -86,7 +86,7 @@ static bool NO_EARPIECE = 1;
/* number of frames per long period (low power) */
#define LONG_PERIOD_SIZE (SHORT_PERIOD_SIZE * LONG_PERIOD_MULTIPLIER)
/* number of pseudo periods for playback */
#define PLAYBACK_PERIOD_COUNT 4
#define PLAYBACK_PERIOD_COUNT 3
/* number of periods for capture */
#define CAPTURE_PERIOD_COUNT 2
/* minimum sleep time in out_write() when write threshold is not reached */
@ -109,7 +109,6 @@ static bool last_call_path_is_bt = 0;
static bool dmic_used = 0;
static bool last_communication_is_bt = 0;
/*VOLUME CTL*/
#define MIXER_HP_VOLUME "headphone volume"
#define MIXER_SPK_VOLUME "speaker volume"
@ -1736,6 +1735,7 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
WritePcmData((void *)buf, out_frames * frame_size, &adev->PcmManager);
memset(buf, 0, out_frames * frame_size); //mute
}
ret = pcm_write(out->pcm, (void *)buf, out_frames * frame_size);
if(ret!=0)
{
@ -2390,6 +2390,7 @@ static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
struct sunxi_stream_in *in = (struct sunxi_stream_in *)stream;
struct sunxi_audio_device *adev = in->dev;
size_t frames_rq = bytes / audio_stream_frame_size(&stream->common);
int is_first_data = 0;
if (adev->mode == AUDIO_MODE_IN_CALL) {
//ALOGD("in call mode, in_read, return ;");
@ -2432,6 +2433,7 @@ static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
pthread_mutex_lock(&in->lock);
if (in->standby) {
ret = start_input_stream(in);
is_first_data = 1;
if (ret == 0)
in->standby = 0;
}
@ -2450,6 +2452,15 @@ static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
ret = pcm_read(in->pcm, buffer, bytes);
}
/* If connect headset, set the first data to zero.
* There may be a noise pulse.
*/
if (is_first_data &&
(adev->in_device & AUDIO_DEVICE_IN_WIRED_HEADSET)) {
memset(buffer, 0, bytes);
}
if (ret > 0)
ret = 0;
@ -2962,6 +2973,7 @@ static int adev_close(hw_device_t *device)
audio_route_free(adev->ar);
free(adev->vol_array);
free(device);
return 0;
}

View file

@ -75,7 +75,7 @@ audio_hw_modules {
usb_device {
sampling_rates dynamic
channel_masks AUDIO_CHANNEL_IN_STEREO
formats AUDIO_FORMAT_PCM_16_BIT
formats AUDIO_FORMAT_PCM_24_BIT_PACKED
devices AUDIO_DEVICE_IN_USB_DEVICE
}
}

View file

@ -17,7 +17,7 @@ LOCAL_PATH := $(call my-dir)
# libAwHeadpSurround
include $(CLEAR_VARS)
LOCAL_MODULE := libAwHeadpSurround
LOCAL_SRC_FILES := libAwHeadpSurround.so
LOCAL_SRC_FILES := audio_3d_surround/libAwHeadpSurround.so
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_SUFFIX := .so
@ -31,7 +31,7 @@ LOCAL_MODULE := audio.primary.$(TARGET_BOARD_PLATFORM)
#LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := audio_hw.c audio_iface.c sunxi_volume.c
LOCAL_SRC_FILES := audio_hw.c audio_iface.c sunxi_volume.c audio_3d_surround/audio_3d_surround.c
#ifneq ($(SW_BOARD_HAVE_3G), true)
#LOCAL_SRC_FILES += audio_ril_stub.c

View file

@ -22,8 +22,8 @@
<path name="media-speaker-off">
<ctl name="AIF1IN0L Mux" value="AIF1_DA0L" />
<ctl name="AIF1IN0R Mux" value="AIF1_DA0R" />
<ctl name="DACL Mixer AIF1DA0L Switch" value="1" />
<ctl name="DACR Mixer AIF1DA0R Switch" value="1" />
<ctl name="DACL Mixer AIF1DA0L Switch" value="0" />
<ctl name="DACR Mixer AIF1DA0R Switch" value="0" />
<ctl name="Left Output Mixer DACL Switch" value="1" />
<ctl name="Right Output Mixer DACR Switch" value="1" />
<ctl name="SPK_L Mux" value="MIXEL Switch" />
@ -56,8 +56,8 @@
<path name="media-single-speaker-off">
<ctl name="AIF1IN0L Mux" value="AIF1_DA0L" />
<ctl name="AIF1IN0R Mux" value="AIF1_DA0R" />
<ctl name="DACL Mixer AIF1DA0L Switch" value="1" />
<ctl name="DACR Mixer AIF1DA0R Switch" value="1" />
<ctl name="DACL Mixer AIF1DA0L Switch" value="0" />
<ctl name="DACR Mixer AIF1DA0R Switch" value="0" />
<ctl name="Left Output Mixer DACL Switch" value="1" />
<ctl name="Left Output Mixer DACR Switch" value="1" />
<ctl name="SPK_L Mux" value="MIXL MIXR Switch" />

View file

@ -0,0 +1,91 @@
#define LOG_TAG "audio_3d_surround"
#include <dlfcn.h>
#include <cutils/log.h>
#include <cutils/properties.h>
#include <stdbool.h>
#include <stdlib.h>
#include <system/audio.h>
#include "audio_3d_surround.h"
#define SUR_LIB_PATH "libAwHeadpSurround.so"
#define SPACE_GAIN (0.50)
#define BASS_GAIN (0.33)
#define DEFINTION_GAIN (0.80)
int surround_init(struct audio_3d_surround *sur,
int samp_rate, int chn, int num_frame)
{
memset(sur, 0, sizeof(*sur));
/* open lib */
sur->lib = dlopen(SUR_LIB_PATH, RTLD_LAZY);
if (NULL == sur->lib) {
ALOGW("%s,line:%d, can't open surround lib.", __func__, __LINE__);
return -1;
}
/* get 3d srround function */
sur->process_init = dlsym(sur->lib, "process_init");
sur->process_exit = dlsym(sur->lib, "process_exit");
sur->surround_pro_in_out = dlsym(sur->lib, "surround_pro_in_out");
sur->set_bass = dlsym(sur->lib, "set_bass");
sur->set_defintion = dlsym(sur->lib, "set_defintion");
sur->set_space = dlsym(sur->lib, "set_space");
/* init 3d suround parameter */
sur->sur_handle = sur->process_init(sur->sur_handle, samp_rate, chn, num_frame);
sur->set_bass(sur->sur_handle, BASS_GAIN);
sur->set_defintion(sur->sur_handle, DEFINTION_GAIN);
sur->set_space(sur->sur_handle, SPACE_GAIN);
return 0;
}
bool surround_ready(struct audio_3d_surround sur)
{
if ( (NULL == sur.lib) || (NULL == sur.sur_handle) )
return false;
return true;
}
/*
* if out device is headset and android settings
* 3d surround switch opened, use surround.
*/
bool surround_use(int out_device)
{
int hs_on;
int use;
char value[PROPERTY_VALUE_MAX];
/* get the current switch state. Default value is close. */
property_get("persist.sys.audio_3d_surround", value, "0");
use = atoi(value);
hs_on = out_device & (AUDIO_DEVICE_OUT_WIRED_HEADSET | AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
return (hs_on && use);
}
int surround_process(struct audio_3d_surround sur, short *buf, int frames, int channels)
{
sur.surround_pro_in_out(sur.sur_handle, buf, buf, frames * channels);
return 0;
}
void surround_exit(struct audio_3d_surround *sur)
{
if (sur->sur_handle != NULL) {
sur->process_exit(sur->sur_handle);
sur->sur_handle = NULL;
}
if (sur->lib != NULL) {
dlclose(sur->lib);
sur->lib = NULL;
}
}

View file

@ -0,0 +1,30 @@
#ifndef __AUDIO_3D_SURROUND_H_
#define __AUDIO_3D_SURROUND_H_
/*
* the 3d surround struct
*
*/
struct audio_3d_surround {
void *lib;
void *sur_handle;
void *(*process_init)(void *handle, int samp_rate, int chn, int num_frame);
void (*surround_pro_in_out)(void *handle, short *buf, short *new_sp, int data_num);
void (*process_exit)(void *handle);
void (*set_space)(void *handle, double space_gain);
void (*set_bass)(void *handle, double sub_gain);
void (*set_defintion)(void *handle, double defintion_gain);
};
/*
* interface for user
*
*/
int surround_init(struct audio_3d_surround *sur, int samp_rate, int chn, int num_frame);
bool surround_ready(struct audio_3d_surround sur);
bool surround_use(int out_device);
int surround_process(struct audio_3d_surround sur, short *buf, int frames, int channels);
void surround_exit(struct audio_3d_surround *sur);
#endif

File diff suppressed because it is too large Load diff

View file

@ -39,8 +39,8 @@ audio_hw_modules {
}
inputs {
primary {
sampling_rates 8000|11025|16000|22050|24000|32000|44100|48000
channel_masks AUDIO_CHANNEL_IN_MONO|AUDIO_CHANNEL_IN_STEREO|AUDIO_CHANNEL_IN_VOICE_UPLINK|AUDIO_CHANNEL_IN_VOICE_DNLINK|AUDIO_CHANNEL_IN_VOICE
sampling_rates 44100
channel_masks AUDIO_CHANNEL_IN_STEREO
formats AUDIO_FORMAT_PCM_16_BIT
devices AUDIO_DEVICE_IN_BUILTIN_MIC|AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET|AUDIO_DEVICE_IN_WIRED_HEADSET|AUDIO_DEVICE_IN_BACK_MIC|AUDIO_DEVICE_IN_AF|AUDIO_DEVICE_IN_VOICE_CALL|AUDIO_DEVICE_IN_FM
}
@ -75,7 +75,7 @@ audio_hw_modules {
usb_device {
sampling_rates dynamic
channel_masks AUDIO_CHANNEL_IN_STEREO
formats AUDIO_FORMAT_PCM_16_BIT
formats AUDIO_FORMAT_PCM_24_BIT_PACKED
devices AUDIO_DEVICE_IN_USB_DEVICE
}
}

View file

@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#define LOG_TAG "codec_audio"
#define LOG_NDEBUG 0

View file

@ -1,6 +1,8 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
ifeq ($(SECURE_OS_OPTEE), no)
LOCAL_SRC_FILES:= \
sunxi_tee_api.c
@ -29,3 +31,5 @@ LOCAL_MODULE_TAGS := optional
LOCAL_MODULE:= test_api
#include $(BUILD_EXECUTABLE)
endif

View file

@ -48,6 +48,7 @@ TEEC_Result TEEC_InitializeContext(const char* name, TEEC_Context* context) {
context->fd = ret;
context->session_count = 0;
context->shared_mem_cnt = 0;
context->nSessionNum = 0;
INIT_LIST_HEAD(&context->shared_mem_list);
}
return TEEC_SUCCESS;
@ -325,7 +326,7 @@ TEEC_Result TEEC_InvokeCommand(
(param_types[param_count] == TEEC_MEMREF_PARTIAL_INPUT) ||
(param_types[param_count] == TEEC_MEMREF_PARTIAL_INOUT) ||
(param_types[param_count] == TEEC_MEMREF_PARTIAL_OUTPUT)) {
//* check the info
if(!operation->params[param_count].memref.parent) {
if(returnOrigin){
*returnOrigin = TEEC_ORIGIN_API;
@ -393,41 +394,44 @@ TEEC_Result TEEC_InvokeCommand(
break;
}
}
//* assign sunxi_tee_param from operation->param
if (param_types[param_count] == TEEC_MEMREF_PARTIAL_INPUT) {
sunxi_tee_param[param_count].type = TE_PARAM_TYPE_MEM_RO;
sunxi_tee_param[param_count].u.Mem.base = (void*) ((uint32_t)operation->params[param_count].memref.parent->buffer +
sunxi_tee_param[param_count].u.Mem.base = (void*) ((uintptr_t)operation->params[param_count].memref.parent->buffer +
(uint32_t)operation->params[param_count].memref.offset);
sunxi_tee_param[param_count].u.Mem.len = operation->params[param_count].memref.parent->size;
sunxi_tee_param[param_count].index = (uint32_t)operation->params[param_count].memref.parent->buffer;
sunxi_tee_param[param_count].index = (uintptr_t)operation->params[param_count].memref.parent->buffer;
}else if((param_types[param_count] == TEEC_MEMREF_PARTIAL_OUTPUT) ||
(param_types[param_count] == TEEC_MEMREF_PARTIAL_INOUT)){
sunxi_tee_param[param_count].type = TE_PARAM_TYPE_MEM_RW;
sunxi_tee_param[param_count].u.Mem.base = (void*) ((uint32_t)operation->params[param_count].memref.parent->buffer +
sunxi_tee_param[param_count].u.Mem.base = (void*) ((uintptr_t)operation->params[param_count].memref.parent->buffer +
(uint32_t)operation->params[param_count].memref.offset);
sunxi_tee_param[param_count].u.Mem.len = operation->params[param_count].memref.parent->size;
sunxi_tee_param[param_count].index = (uint32_t)operation->params[param_count].memref.parent->buffer;
sunxi_tee_param[param_count].index = (uintptr_t)operation->params[param_count].memref.parent->buffer;
}else if((param_types[param_count] == TEEC_MEMREF_WHOLE)){
if(operation->params[param_count].memref.parent->flags == TEEC_MEM_INPUT){
sunxi_tee_param[param_count].type = TE_PARAM_TYPE_MEM_RO;
sunxi_tee_param[param_count].u.Mem.base = (void*) ((uint32_t)operation->params[param_count].memref.parent->buffer);
sunxi_tee_param[param_count].u.Mem.base = (void*) ((uintptr_t)operation->params[param_count].memref.parent->buffer);
sunxi_tee_param[param_count].u.Mem.len = operation->params[param_count].memref.parent->size;
sunxi_tee_param[param_count].index = (uint32_t)operation->params[param_count].memref.parent->buffer;
sunxi_tee_param[param_count].index = (uintptr_t)operation->params[param_count].memref.parent->buffer;
}
if((operation->params[param_count].memref.parent->flags == TEEC_MEM_OUTPUT) ||
(operation->params[param_count].memref.parent->flags == (TEEC_MEM_INPUT|TEEC_MEM_OUTPUT ))){
sunxi_tee_param[param_count].type = TE_PARAM_TYPE_MEM_RW;
sunxi_tee_param[param_count].u.Mem.base = (void*) ((uint32_t)operation->params[param_count].memref.parent->buffer);
sunxi_tee_param[param_count].u.Mem.base = (void*) ((uintptr_t)operation->params[param_count].memref.parent->buffer);
sunxi_tee_param[param_count].u.Mem.len = operation->params[param_count].memref.parent->size;
sunxi_tee_param[param_count].index = (uint32_t)operation->params[param_count].memref.parent->buffer;
sunxi_tee_param[param_count].index = (uintptr_t)operation->params[param_count].memref.parent->buffer;
}
}
}else if(param_types[param_count] == TEEC_NONE){
sunxi_tee_param[param_count].type = TE_PARAM_TYPE_NONE;
}
}
//* set sunxi_tee_param to cmd
for (param_count = 0; param_count < 4; param_count++) {
if (cmd->launchop.operation.list_count == 0) {
cmd->launchop.operation.list_head = sunxi_tee_param + param_count;

View file

@ -237,6 +237,8 @@ struct TEEC_Context
struct list shared_mem_list;
/*! Error number from the client driver */
int s_errno;
int nSessionNum;
};

View file

@ -54,6 +54,11 @@ static int hwc_blank(struct hwc_composer_device_1* dev, int disp, int blank)
HWC_UNREFERENCED_PARAMETER(blank);
SUNXI_hwcdev_context_t *Globctx = &gSunxiHwcDevice;
if(!blank)
{
Globctx->unblank_flag = 1;
return 0;
}
unsigned long arg[4]={0};
DisplayInfo *PsDisplayInfo = &Globctx->SunxiDisplay[disp];
if(PsDisplayInfo->VirtualToHWDisplay != -EINVAL)

View file

@ -174,6 +174,7 @@ typedef struct {
int share_fd;//ion_handle share_fd
int size_buffer;
bool valid;
bool is_secure;
}hwc_cache_t;
typedef struct {
@ -191,6 +192,7 @@ typedef struct {
int share_fd;
bool needsync;//for sw_write
bool iscursor;
bool is_secure;
disp_layer_config hwc_layer_info;
}hwc_commit_layer_t;
@ -255,6 +257,7 @@ typedef struct layer_info {
bool is3D;
bool is_cursor;
bool need_sync;
bool is_secure;
int shared_fd;
AssignDUETO_T info;
hwc_layer_1_t *psLayer;
@ -407,7 +410,7 @@ typedef struct
mutable android::Condition CommitCondition;
hwc_commit_layer_t cursor_rotate_layer[VIDEO_ROTATE_COUNT];// 0 is 90, 1 is 180,2 is 270;
int unblank_flag;
}SUNXI_hwcdev_context_t;
typedef struct

View file

@ -333,6 +333,7 @@ void *commit_thread(void *priv)
hwc_dispc_data_t *DisplayData = NULL;
int i = 0, j = 0, ret = -1, lyr = 0, rotatecall = 0;
int primary_disp = 0, video_fence_fd = -1, share_fd = -1;
int unblank_count = 0;
unsigned long arg[4] = {0};
unsigned int current_sync_count = 0, cusor_sync = 0;
hwc_ioctl_arg hwc_cmd;
@ -498,6 +499,28 @@ deal_fence:
arg[0] = 0;
arg[1] = (unsigned long)(&hwc_cmd);
ret = ioctl(Globctx->DisplayFd, DISP_HWC_COMMIT, (unsigned long)arg);
if(Globctx->unblank_flag)
{
if(unblank_count == 3)
{
unsigned long arg[4]={0};
DisplayInfo *PsDisplayInfo = &Globctx->SunxiDisplay[DisplayData->first_disp];
if(PsDisplayInfo->VirtualToHWDisplay != -EINVAL)
{
arg[0] = PsDisplayInfo->VirtualToHWDisplay;
arg[1] = 0;
if(ioctl(Globctx->DisplayFd, DISP_BLANK, (unsigned long)arg) != 0)
ALOGE("##########unblank error!");
}
Globctx->unblank_flag = 0;
unblank_count = 0;
}
unblank_count++;
}
/* check wb and display to HDMI or miracast */
/* update cursor disp data */

View file

@ -98,7 +98,7 @@ int culate_timeout(disp_rectsz disp_src)
return 32;
}
static hwc_cache_t *hwc_video_cache_get(int size, int fd, unsigned int sync_count)
static hwc_cache_t *hwc_video_cache_get(int size, int fd, unsigned int sync_count, bool is_secure)
{
SUNXI_hwcdev_context_t *Globctx = &gSunxiHwcDevice;
hwc_cache_t *wb_cache = NULL;
@ -130,7 +130,7 @@ static hwc_cache_t *hwc_video_cache_get(int size, int fd, unsigned int sync_coun
close(wb_cache->fd);
wb_cache->fd = -1;
}
if(wb_cache->share_fd >= 0 && size < wb_cache->size_buffer)
if(wb_cache->share_fd >= 0 && size < wb_cache->size_buffer && wb_cache->is_secure == is_secure)
{
if(wb_cache->size_buffer - size > 4096)
{
@ -148,23 +148,38 @@ static hwc_cache_t *hwc_video_cache_get(int size, int fd, unsigned int sync_coun
}
if(wb_cache->share_fd == -1 || wb_cache->size_buffer == 0)
{
ret = ion_alloc_fd(Globctx->IonFd, size,
4096, ION_HEAP_TYPE_DMA_MASK, 0, &wb_cache->share_fd);
if(ret < 0)
if(is_secure)
{
ALOGD("alloc err from ION_HEAP_CARVEOUT_MASK");
ret = ion_alloc_fd(Globctx->IonFd, size,
4096, ION_HEAP_SYSTEM_CONTIG_MASK, 0, &wb_cache->share_fd);
ret = ion_alloc_fd(Globctx->IonFd, size,
4096, ION_HEAP_SECURE_MASK, 0, &wb_cache->share_fd);
if(ret < 0)
{
ALOGD("alloc err from ION_HEAP_SYSTEM_CONTIG_MASK");
wb_cache->share_fd = -1;
wb_cache->size_buffer = 0;
return NULL;
ALOGD("alloc err from ION_HEAP_SECURE_MASK");
return NULL;
}
wb_cache->is_secure = 1;
}else{
ret = ion_alloc_fd(Globctx->IonFd, size,
4096, ION_HEAP_TYPE_DMA_MASK, 0, &wb_cache->share_fd);
if(ret < 0)
{
ALOGD("alloc err from ION_HEAP_CARVEOUT_MASK");
ret = ion_alloc_fd(Globctx->IonFd, size,
4096, ION_HEAP_SYSTEM_CONTIG_MASK, 0, &wb_cache->share_fd);
if(ret < 0)
{
ALOGD("alloc err from ION_HEAP_SYSTEM_CONTIG_MASK");
wb_cache->share_fd = -1;
wb_cache->size_buffer = 0;
return NULL;
}
}
}
ion_sync_fd(Globctx->IonFd, wb_cache->share_fd);
wb_cache->size_buffer = size;
if(!is_secure)
{
ion_sync_fd(Globctx->IonFd, wb_cache->share_fd);
}
wb_cache->size_buffer = size;
}
wb_cache->sync_cnt = sync_count;
wb_cache->valid = 0;
@ -520,7 +535,7 @@ bool hwc_rotate_layer_video(hwc_dispc_data_t *hwc_layer,
hwc_rotate_settimeout(ret);
Globctx->tr_time_out = ret;
}
wb_cache = hwc_video_cache_get(size, commit_data->releasefencefd[disp], hwc_layer->sync_count);
wb_cache = hwc_video_cache_get(size, commit_data->releasefencefd[disp], hwc_layer->sync_count, commit_layer->is_secure);
if(wb_cache != NULL)
{
memset(&tr_info, 0, sizeof(tr_info));

View file

@ -443,8 +443,8 @@ static inline int check_valid_format(int format)
case HAL_PIXEL_FORMAT_RGB_888:
case HAL_PIXEL_FORMAT_RGB_565:
case HAL_PIXEL_FORMAT_BGRA_8888:
case HAL_PIXEL_FORMAT_sRGB_A_8888:
case HAL_PIXEL_FORMAT_sRGB_X_8888:
// case HAL_PIXEL_FORMAT_sRGB_A_8888:
// case HAL_PIXEL_FORMAT_sRGB_X_8888:
case HAL_PIXEL_FORMAT_YV12:
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
case HAL_PIXEL_FORMAT_BGRX_8888:
@ -520,8 +520,8 @@ static inline bool check_support_blending(int format)
case HAL_PIXEL_FORMAT_RGB_888:
case HAL_PIXEL_FORMAT_RGB_565:
case HAL_PIXEL_FORMAT_BGRA_8888:
case HAL_PIXEL_FORMAT_sRGB_A_8888:
case HAL_PIXEL_FORMAT_sRGB_X_8888:
// case HAL_PIXEL_FORMAT_sRGB_A_8888:
// case HAL_PIXEL_FORMAT_sRGB_X_8888:
case HAL_PIXEL_FORMAT_BGRX_8888:
return 1;
default:
@ -764,7 +764,7 @@ static int hwc_can_scale(HwcDisContext_t *Localctx, hwc_layer_1_t *psLayer, bool
{
vsyncPeroid /= 2;
}
de_freq = 504000000;
de_freq = 254000000;
lcd_line_peroid = vsyncPeroid / lcd_h;
layer_line_peroid = (src_w > dst_w)
? (1000000*((long long)(lcd_w - dst_w + src_w))/(de_freq/1000))
@ -1395,7 +1395,7 @@ ret_ok:
HwcAssignStatus hwc_try_assign_layer(HwcDisContext_t *Localctx, size_t singcout, int zOrder)
{
bool needchannel = 1, isvideo = 0, isalpha = 0, isFB = 0;
bool needchannel = 1, isvideo = 0, isalpha = 0, isFB = 0, issecure = 0;
bool is3D = 0, need_sync = 0, is_cursor = 0;
float WscalFac = 1.0, HscaleFac = 1.0;
int CH= -1, tmCnt1 = 0, tmCnt2 = 0, addLayerCnt = 1;
@ -1444,13 +1444,18 @@ HwcAssignStatus hwc_try_assign_layer(HwcDisContext_t *Localctx, size_t singcout,
goto assign_gpu;
}
if(check_usage_protected(handle) && !PsDisplayInfo->issecure)
if(check_usage_protected(handle))
{
ALOGV("%s:Video Protected", __func__);
dueto = D_VIDEO_PD;
goto assign_gpu;
if(!PsDisplayInfo->issecure)
{
ALOGV("%s:Video Protected", __func__);
dueto = D_VIDEO_PD;
goto assign_gpu;
}else{
issecure = 1;
}
}
dueto = check_valid_layer(psLayer, is_cursor);
if(dueto != I_OVERLAY)
{
@ -1643,8 +1648,9 @@ assign_overlay:
Localctx->psAllLayer[singcout].is3D = is3D;
Localctx->psAllLayer[singcout].info = dueto;
Localctx->psAllLayer[singcout].isvideo= isvideo;
Localctx->psAllLayer[singcout].need_sync = need_sync;
Localctx->psAllLayer[singcout].is_cursor= is_cursor;
Localctx->psAllLayer[singcout].need_sync = issecure?0:need_sync;
Localctx->psAllLayer[singcout].is_cursor = is_cursor;
Localctx->psAllLayer[singcout].is_secure = issecure;
if(is_cursor)
{
return ASSIGN_CURSOR;
@ -1734,6 +1740,7 @@ int hwc_setup_layer(hwc_dispc_data_t *DisplayData, HwcDisContext_t *Localctx)
}
hw_layer_config->needsync = psHwlayer_info->need_sync;
hw_layer_config->share_fd = dup(psHwlayer_info->shared_fd);
hw_layer_config->is_secure = psHwlayer_info->is_secure;
if(check_is_blending(psLayer))
{
layer_info->alpha_mode = 2;
@ -2054,6 +2061,9 @@ deal_fence:
&& PsDisplayInfo->VirtualToHWDisplay >= 0)
{
releasefecefd = returnfenceFd[ture_disp];
}else{
ALOGW("has plugout the disp[%d]",disp);
continue;
}
for(i = 0; i < psDisplay->numHwLayers; i++)
{
@ -2378,7 +2388,7 @@ SUNXI_hwcdev_context_t* hwc_create_device(void)
ALOGD("###open /sys/class/disp/disp/attr/runtime_enable fail");
}
open_fd = open("/sys/devices/platform/sunxi-ddrfreq/devfreq/sunxi-ddrfreq/max_freq", O_RDONLY);
open_fd = open("/sys/class/devfreq/sunxi-ddrfreq/max_freq", O_RDONLY);
if(open_fd >= 0)
{
char val_ddr[10] = {0x0,};
@ -2427,6 +2437,7 @@ SUNXI_hwcdev_context_t* hwc_create_device(void)
Globctx->uiBeginFrame = 0;
Globctx->hwcdebug = 0;
Globctx->stop_rotate_hw = 0;
Globctx->unblank_flag = 0;
Globctx->ManageLock = PTHREAD_MUTEX_INITIALIZER;
Globctx->AbandonLock = PTHREAD_MUTEX_INITIALIZER;
Globctx->HeadLock = PTHREAD_MUTEX_INITIALIZER;

View file

@ -185,6 +185,7 @@ typedef struct {
int share_fd;//ion_handle share_fd
int size_buffer;
bool valid;
bool is_secure;
}hwc_cache_t;
typedef struct {
@ -207,6 +208,7 @@ typedef struct {
int share_fd;
bool needsync;//for sw_write
bool iscursor;
bool is_secure;
disp_layer_config hwc_layer_info;
}hwc_commit_layer_t;
@ -286,6 +288,7 @@ typedef struct layer_info {
bool is3D;
bool is_cursor;
bool need_sync;
bool is_secure;
int shared_fd;
format_info form_info;
AssignDUETO_T info;
@ -312,7 +315,6 @@ typedef struct{
bool VsyncEnable;
bool issecure;
bool active;
bool setblank;
int HwChannelNum;
int LayerNumofCH;
@ -460,6 +462,7 @@ typedef struct
int fb_pre_mem;
/* end mem limit */
int unblank_flag;
unsigned char has_secure;
}SUNXI_hwcdev_context_t;
@ -603,8 +606,8 @@ static inline int check_valid_format(int format)
//case HAL_PIXEL_FORMAT_RGB_888:
case HAL_PIXEL_FORMAT_RGB_565:
case HAL_PIXEL_FORMAT_BGRA_8888:
case HAL_PIXEL_FORMAT_sRGB_A_8888:
case HAL_PIXEL_FORMAT_sRGB_X_8888:
//case HAL_PIXEL_FORMAT_sRGB_A_8888:
//case HAL_PIXEL_FORMAT_sRGB_X_8888:
case HAL_PIXEL_FORMAT_YV12:
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
case HAL_PIXEL_FORMAT_BGRX_8888:
@ -690,8 +693,8 @@ static inline bool check_support_blending(int format)
case HAL_PIXEL_FORMAT_RGB_888:
case HAL_PIXEL_FORMAT_RGB_565:
case HAL_PIXEL_FORMAT_BGRA_8888:
case HAL_PIXEL_FORMAT_sRGB_A_8888:
case HAL_PIXEL_FORMAT_sRGB_X_8888:
//case HAL_PIXEL_FORMAT_sRGB_A_8888:
//case HAL_PIXEL_FORMAT_sRGB_X_8888:
case HAL_PIXEL_FORMAT_BGRX_8888:
return 1;
default:

View file

@ -17,6 +17,13 @@
#include "hwc.h"
typedef struct {
ion_user_handle_t handle;
unsigned int phys_addr;
unsigned int size;
}sunxi_phys_data;
#define ION_IOC_SUNXI_PHYS_ADDR 7
ion_user_handle_t ion_alloc_buffer(int iAllocBytes, unsigned int heap_mask)
{
SUNXI_hwcdev_context_t *Globctx = &gSunxiHwcDevice;
@ -36,7 +43,7 @@ ion_user_handle_t ion_alloc_buffer(int iAllocBytes, unsigned int heap_mask)
ALOGW("%s: ION_IOC_ALLOC failed (ret=%d)", __func__, ret);
return (ion_user_handle_t) -1;
}
return sAllocInfo.handle;
}
@ -64,7 +71,7 @@ unsigned int ion_get_addr_fromfd(int sharefd)
sunxi_phys_data phys_data;
ion_handle_data freedata;
struct ion_fd_data data ;
data.fd = sharefd;
ret = ioctl(Globctx->IonFd, ION_IOC_IMPORT, &data);
if (ret < 0)
@ -88,7 +95,7 @@ unsigned int ion_get_addr_fromfd(int sharefd)
ALOGE("%s: ION_IOC_FREE failed(ret=%d)", __func__, ret);
return 0;
}
return phys_data.phys_addr;
return phys_data.phys_addr;
}
unsigned long ion_get_addr_from_handle(ion_user_handle_t handle)
@ -122,7 +129,7 @@ ion_user_handle_t ion_handle_add_ref(int sharefd)
ALOGE("%s: ION_IOC_IMPORT failed(ret=%d)", __func__, ret);
return -1;
}
return data.handle;
return data.handle;
}
void ion_handle_dec_ref(ion_user_handle_t handle_id)
@ -180,7 +187,7 @@ void ion_free_cache(hwc_ion_hold_t *ion_cache)
bool hwc_manage_ref_cache(bool cache, hwc_dispc_data_t *dispc_data)
{
hwc_ion_hold_t *ion_cache = NULL;
int i, little_sync, cnt = 0, size = 0;
int i, little_sync, cnt = 0, size = 0;
hwc_commit_layer_t *commit_layer = NULL;
int *_array = NULL;
@ -237,8 +244,7 @@ bool hwc_manage_ref_cache(bool cache, hwc_dispc_data_t *dispc_data)
}
ion_cache->num_used = size;
ion_cache->sync_count = dispc_data->sync_count;
manage_ok:
return 1;
}

View file

@ -144,6 +144,11 @@ void hwc_down_limit(SUNXI_hwcdev_context_t *Globctx, int local_mem[NUMBEROFDISPL
{
HWC_UNREFERENCED_PARAMETER(local_mem);
int i = 0, tmp_mem_thruput0 = 0;
if(Globctx->has_secure != 0)
{
Globctx->memlimit = Globctx->max_mem_limit;
return;
}
if(Globctx->ForceGPUComp[0] == 0 && Globctx->CanForceGPUCom && force_gpu)
{
if(Globctx->psHwcProcs != NULL

View file

@ -129,8 +129,6 @@ int _hwc_device_set_enhancemode(int disp, bool on_off, bool half)
int _hwc_device_set_output_mode(int disp, int out_type, int out_mode)
{
SUNXI_hwcdev_context_t *Globctx = &gSunxiHwcDevice;
if(Globctx->SunxiDisplay[0].DisplayType == DISP_OUTPUT_TYPE_HDMI)
disp = 0;
DisplayInfo *PsDisplayInfo = &Globctx->SunxiDisplay[disp];
int disp_t;
@ -149,8 +147,6 @@ int _hwc_set_persent(int disp,int para0, int para1)
{
SUNXI_hwcdev_context_t *Globctx = &gSunxiHwcDevice;
DisplayInfo *PsDisplayInfo = NULL;
if(Globctx->SunxiDisplay[0].DisplayType == DISP_OUTPUT_TYPE_HDMI)
disp = 0;
PsDisplayInfo = &Globctx->SunxiDisplay[disp];
if(PsDisplayInfo->VirtualToHWDisplay != -1 && PsDisplayInfo->DisplayType == DISP_OUTPUT_TYPE_HDMI)

View file

@ -15,6 +15,9 @@
*/
#include "hwc.h"
#define ION_HEAP_TYPE_SECURE (ION_HEAP_TYPE_CUSTOM+1)
#define ION_HEAP_SECURE_MASK (1 << ION_HEAP_TYPE_SECURE)
int hwc_rotate_query(unsigned long tr_handle)
{
SUNXI_hwcdev_context_t *Globctx = &gSunxiHwcDevice;
@ -129,7 +132,7 @@ static rotate_cache_t *hwc_ratate_cache_manage(SUNXI_hwcdev_context_t *Globctx,
return ratate_cache;
}
static hwc_cache_t *hwc_tr_cache_get(rotate_cache_t *rotate_cache, int size, int fd, unsigned int sync_count)
static hwc_cache_t *hwc_tr_cache_get(rotate_cache_t *rotate_cache, int size, int fd, unsigned int sync_count, bool is_secure)
{
SUNXI_hwcdev_context_t *Globctx = &gSunxiHwcDevice;
hwc_cache_t *tr_cache = NULL;
@ -163,7 +166,7 @@ static hwc_cache_t *hwc_tr_cache_get(rotate_cache_t *rotate_cache, int size, int
close(tr_cache->fd);
tr_cache->fd = -1;
}
if(tr_cache->share_fd >= 0 && size <= tr_cache->size_buffer)
if(tr_cache->share_fd >= 0 && size <= tr_cache->size_buffer && tr_cache->is_secure == is_secure)
{
if(tr_cache->size_buffer - size > 4096)
{
@ -181,22 +184,35 @@ static hwc_cache_t *hwc_tr_cache_get(rotate_cache_t *rotate_cache, int size, int
}
if(tr_cache->share_fd == -1 || tr_cache->size_buffer == 0)
{
ret = ion_alloc_fd(Globctx->IonFd, size,
4096, ION_HEAP_TYPE_DMA_MASK, 0, &tr_cache->share_fd);
if(ret < 0)
{
ALOGD("alloc err from ION_HEAP_TYPE_DMA_MASK");
ret = ion_alloc_fd(Globctx->IonFd, size,
4096, ION_HEAP_SYSTEM_CONTIG_MASK, 0, &tr_cache->share_fd);
if(is_secure){
ret = ion_alloc_fd(Globctx->IonFd, size,
4096, ION_HEAP_SECURE_MASK, 0, &tr_cache->share_fd);
if(ret < 0)
{
ALOGD("alloc err from ION_HEAP_SYSTEM_CONTIG_MASK");
tr_cache->share_fd = -1;
tr_cache->size_buffer = 0;
return NULL;
ALOGD("alloc err from ION_HEAP_SECURE_MASK");
return NULL;
}
}
ion_sync_fd(Globctx->IonFd, tr_cache->share_fd);
tr_cache->is_secure = 1;
}else{
ret = ion_alloc_fd(Globctx->IonFd, size,
4096, ION_HEAP_TYPE_DMA_MASK, 0, &tr_cache->share_fd);
if(ret < 0)
{
ALOGD("alloc err from ION_HEAP_TYPE_DMA_MASK");
ret = ion_alloc_fd(Globctx->IonFd, size,
4096, ION_HEAP_SYSTEM_CONTIG_MASK, 0, &tr_cache->share_fd);
if(ret < 0)
{
ALOGD("alloc err from ION_HEAP_SYSTEM_CONTIG_MASK");
tr_cache->share_fd = -1;
tr_cache->size_buffer = 0;
return NULL;
}
}
}
if(!is_secure){
ion_sync_fd(Globctx->IonFd, tr_cache->share_fd);
}
tr_cache->size_buffer = size;
}
tr_cache->sync_cnt = sync_count;
@ -267,7 +283,7 @@ void hwc_rotate_cache_free(void)
static int inline hwc_disp_pixel_bytes(disp_pixel_format format)
{
switch(format)
switch(format)
{
case DISP_FORMAT_YUV420_P:
case DISP_FORMAT_YUV420_SP_VUVU:
@ -285,13 +301,13 @@ static int inline hwc_disp_pixel_bytes(disp_pixel_format format)
return 16;
default:
return 0;
}
}
return 0;
}
static inline int hwc_disp_layer_plan(disp_pixel_format format)
{
switch(format)
switch(format)
{
case DISP_FORMAT_YUV420_P:
return 3;
@ -308,7 +324,7 @@ static inline int hwc_disp_layer_plan(disp_pixel_format format)
return 1;
default:
return 1;
}
}
}
static inline disp_pixel_format tr_to_disp(tr_pixel_format tr_format)
@ -473,9 +489,9 @@ bool hwc_layer_to_tr(disp_fb_info* hw_layer, tr_info *tr_info, hwc_cache_t *tr_b
/*tr_info->dst_frame.laddr[2] --> V*/
if(cnt != 1)// is YUV Format
{
tr_info->dst_frame.laddr[2] = tr_info->dst_frame.laddr[0] +
tr_info->dst_frame.laddr[2] = tr_info->dst_frame.laddr[0] +
tr_info->dst_frame.pitch[0] * tr_info->dst_frame.height[0];
tr_info->dst_frame.laddr[1] = tr_info->dst_frame.laddr[2] +
tr_info->dst_frame.laddr[1] = tr_info->dst_frame.laddr[2] +
tr_info->dst_frame.pitch[2] * tr_info->dst_frame.height[2];
}
return 1;
@ -487,7 +503,7 @@ void hwc_resize_crop(disp_fb_info *hw_layer, int w_original, int h_original, tr_
switch(mode)
{
case TR_HFLIP:
w_diff = hw_layer->size[0].width - w_original;
w_diff = hw_layer->size[0].width - w_original;
hw_layer->crop.x + (long long)(((long long)w_diff)<<32);
break;
case TR_VFLIP:
@ -495,7 +511,7 @@ void hwc_resize_crop(disp_fb_info *hw_layer, int w_original, int h_original, tr_
hw_layer->crop.y + (long long)(((long long)h_diff)<<32);
break;
case TR_ROT_90:
w_diff = hw_layer->size[0].width - h_original;
w_diff = hw_layer->size[0].width - h_original;
hw_layer->crop.x + (long long)(((long long)w_diff)<<32);
h_diff = hw_layer->size[0].height - w_original;
hw_layer->crop.y + (long long)(((long long)h_diff)<<32);
@ -503,7 +519,7 @@ void hwc_resize_crop(disp_fb_info *hw_layer, int w_original, int h_original, tr_
case TR_ROT_180:
h_diff = hw_layer->size[0].height - h_original;
hw_layer->crop.y + (long long)(((long long)h_diff)<<32);
w_diff = hw_layer->size[0].width - w_original;
w_diff = hw_layer->size[0].width - w_original;
hw_layer->crop.x + (long long)(((long long)w_diff)<<32);
break;
case TR_ROT_270:
@ -580,7 +596,7 @@ bool hwc_tr_to_layer(disp_fb_info *hw_layer, tr_info *tr_info, hwc_cache_t *tr_b
hw_layer->addr[0] = addr;
if(hw_layer->format == DISP_FORMAT_YUV420_P)
{
hw_layer->addr[2] = hw_layer->addr[0]
hw_layer->addr[2] = hw_layer->addr[0]
+ w_stride * h_stride ;
hw_layer->addr[1] = hw_layer->addr[2]
+ w_stride * h_stride / 4;
@ -645,7 +661,7 @@ bool hwc_rotate_layer_tr(hwc_dispc_data_t *hwc_layer,
goto translat_err;
}
tr_cache = hwc_tr_cache_get(rotate_cache, size,
commit_data->releasefencefd[disp], hwc_layer->sync_count);
commit_data->releasefencefd[disp], hwc_layer->sync_count,commit_layer->is_secure);
if(tr_cache != NULL)
{
memset(&tr_info, 0, sizeof(tr_info));
@ -720,6 +736,5 @@ translat_err:
disp_layer->enable =0;
ALOGE("######hwc get a rotate err#####");
return 0;
}

View file

@ -178,6 +178,7 @@ static bool reset_globle(SUNXI_hwcdev_context_t *Globctx,
Globctx->currentmem = 0;
Globctx->has_tr_mem = 0;
Globctx->has_tr_cnt = 0;
Globctx->has_secure = 0;
int tmp_mem_thruput0 = 0;
int all_mem_diff = 0, all_mem = 0, all_mem_fb = 0, ture_disp;
for(i = 0; i < (int)NumofDisp && i < Globctx->NumberofDisp; i++)
@ -924,24 +925,6 @@ static bool resize_layer(HwcDisContext_t *Localctx,
layer_info->fb.crop.y = fb_crop->top + ((cut_top == 1) ? cut_mod:0);
layer_info->fb.crop.height = srcdiff - cut_mod;
}
#if defined(HWC_DEBUG)
ALOGD("\nold:\n[%f,%f]#S[%lld,%lld,%lld,%lld] F[%lld,%lld,%lld,%lld]\n",
Localctx->WidthScaleFactor, Localctx->HighetScaleFactor,
layer_info->fb.crop.x, layer_info->fb.crop.y, layer_info->fb.crop.width,
layer_info->fb.crop.height, layer_info->screen_win.x, layer_info->screen_win.y,
layer_info->screen_win.width, layer_info->screen_win.height);
#endif
if(gSunxiHwcDevice.SunxiDisplay[0].DisplayType == DISP_OUTPUT_TYPE_HDMI) {
layer_info->fb.crop.x = (long long)(((long long)(psLayer->sourceCrop.left)) << 32);
layer_info->fb.crop.width = (long long)(((long long)(psLayer->sourceCrop.right)) << 32);
layer_info->fb.crop.width -= layer_info->fb.crop.x;
layer_info->fb.crop.y = (long long)(((long long)(psLayer->sourceCrop.top)) << 32);
layer_info->fb.crop.height = (long long)(((long long)(psLayer->sourceCrop.bottom)) << 32);
layer_info->fb.crop.height -= layer_info->fb.crop.y;
}
if(layer_info->b_trd_out == 1)
{
switch(PsDisplayInfo->Current3DMode)
@ -1045,7 +1028,7 @@ ret_ok:
HwcAssignStatus hwc_try_assign_layer(HwcDisContext_t *Localctx, size_t singcout, int zOrder)
{
bool needchannel = 1, isvideo = 0, isalpha = 0, isFB = 0, has_tr = 0;
bool needchannel = 1, isvideo = 0, isalpha = 0, isFB = 0, has_tr = 0, issecure = 0;
bool is3D = 0, need_sync = 0, is_cursor = 0;
float WscalFac = 1.0, HscaleFac = 1.0;
int CH= -1, tmCnt1 = 0, tmCnt2 = 0, addLayerCnt = 1;
@ -1095,11 +1078,16 @@ HwcAssignStatus hwc_try_assign_layer(HwcDisContext_t *Localctx, size_t singcout,
goto assign_gpu;
}
if(check_usage_protected(handle) && !PsDisplayInfo->issecure)
if(check_usage_protected(handle))
{
ALOGV("%s:Video Protected", __func__);
dueto = D_VIDEO_PD;
goto assign_gpu;
if(!PsDisplayInfo->issecure)
{
ALOGV("%s:Video Protected", __func__);
dueto = D_VIDEO_PD;
goto assign_gpu;
}else{
issecure = 1;
}
}
dueto = check_valid_layer(psLayer);
@ -1239,7 +1227,7 @@ needchannel:
}
}
/*check the mem thruput*/
if(!is_cursor)
if(!is_cursor && (Globctx->has_secure == 0))
{
dueto = calculate_memthruput(Localctx, &Localctx->psAllLayer[singcout],
WscalFac, HscaleFac, Localctx->HwCHUsedCnt - CHdiff, isFB, isvideo);
@ -1274,7 +1262,7 @@ needchannel:
if(!Localctx->force_gpu
&& (Localctx->UsedFB? isFB: ((int)singcout == Localctx->numberofLayer - 2)))
{
if(mem_ctrl_power_policy(Globctx, Localctx))
if(mem_ctrl_power_policy(Globctx, Localctx) && (Globctx->has_secure == 0))
{
Localctx->force_gpu = 1;
goto assigned_need_resigne;
@ -1293,6 +1281,7 @@ assign_overlay:
Globctx->has_tr_cnt += has_tr;
Localctx->tr_mem += has_tr ? (handle->width * handle->height) : 0;
Globctx->has_tr_mem += has_tr ? (handle->width * handle->height) : 0;
Globctx->has_secure += issecure;
psCH[Localctx->HwCHUsedCnt - CHdiff].hasVideo = isvideo;
psCH[Localctx->HwCHUsedCnt - CHdiff].iCHFormat =
@ -1315,8 +1304,9 @@ assign_overlay:
Localctx->psAllLayer[singcout].is3D = is3D;
Localctx->psAllLayer[singcout].info = dueto;
Localctx->psAllLayer[singcout].isvideo = isvideo;
Localctx->psAllLayer[singcout].need_sync = need_sync;
Localctx->psAllLayer[singcout].need_sync = issecure?0:need_sync;
Localctx->psAllLayer[singcout].is_cursor = is_cursor;
Localctx->psAllLayer[singcout].is_secure = issecure;
if(is_cursor)
{
return ASSIGN_CURSOR;
@ -1360,7 +1350,6 @@ int hwc_setup_layer(hwc_dispc_data_t *DisplayData, HwcDisContext_t *Localctx)
const DisplayInfo *PsDisplayInfo = Localctx->psDisplayInfo;
ChannelInfo_t *psChannelInfo = Localctx->ChannelInfo;
struct private_handle_t *handle = NULL;
bool enableLayer = !(PsDisplayInfo->setblank);
ture_disp = PsDisplayInfo->VirtualToHWDisplay;
if(ture_disp < 0 || ture_disp >= NUMBEROFDISPLAY)
@ -1413,6 +1402,7 @@ int hwc_setup_layer(hwc_dispc_data_t *DisplayData, HwcDisContext_t *Localctx)
}
hw_layer_config->needsync = psHwlayer_info->need_sync;
hw_layer_config->share_fd = dup(psHwlayer_info->shared_fd);
hw_layer_config->is_secure = psHwlayer_info->is_secure;
if(check_is_blending(psLayer))
{
layer_info->alpha_mode = 2;
@ -1430,7 +1420,7 @@ int hwc_setup_layer(hwc_dispc_data_t *DisplayData, HwcDisContext_t *Localctx)
layer_info->zorder = zOrder;
layer_info->alpha_value = psChannelInfo[CHCnt].planeAlpha;
psDisconfig->enable = enableLayer;
psDisconfig->enable = 1;
psDisconfig->layer_id = LCnt;
psDisconfig->channel = psChannelInfo[CHCnt].hasVideo ? VideoCnt : UiCnt;
psHwlayer_info->hwchannel = psDisconfig->channel;
@ -2033,11 +2023,10 @@ SUNXI_hwcdev_context_t* hwc_create_device(void)
&& Globctx->SunxiDisplay[1].VirtualToHWDisplay == -EINVAL)
{
hwc_hotplug_switch(1, 1, DISP_TV_MODE_NUM);
ALOGD("### init hdmi_plug: IN ###");
}
ALOGD("### init hdmi_plug: IN ###");
}else{
if(Globctx->SunxiDisplay[0].DisplayType != DISP_OUTPUT_TYPE_HDMI)
ALOGD("### init hdmi_plug: OUT ###");
ALOGD("### init hdmi_plug: OUT ###");
}
close(open_fd);
}else{
@ -2119,7 +2108,8 @@ SUNXI_hwcdev_context_t* hwc_create_device(void)
Globctx->layer_st = -1;
Globctx->fBeginTime = 0.0;
Globctx->uiBeginFrame = 0;
Globctx->unblank_flag = 0;
Globctx->unblank_flag = 0;
Globctx->has_secure = 0;
hwc_list_init(&Globctx->rotate_cache_list);
Globctx->rotate_hold_cnt = 0;

View file

@ -146,12 +146,12 @@ int hwc_manage_display(DisplayInfo **retDisplayInfo, int DispInfo, ManageDisp mo
disp_tv_mode get_suitable_hdmi_mode(int select, disp_tv_mode lastmode)
{
ALOGI("get_suitable_hdmi_mode select=%d lastmode=%d", select, lastmode);
SUNXI_hwcdev_context_t *Globctx = &gSunxiHwcDevice;
unsigned long arg[4]={0};
arg[0] = select;
int ret, i, j = -1;
disp_tv_mode theMostMode = DISP_TV_MODE_NUM;
struct disp_output para;
i = sizeof(g_tv_para) / sizeof(g_tv_para[0]);
if(lastmode < DISP_TV_MODE_NUM)
{
@ -164,41 +164,38 @@ disp_tv_mode get_suitable_hdmi_mode(int select, disp_tv_mode lastmode)
}
}
if(Globctx->SunxiDisplay[0].DisplayType == DISP_OUTPUT_TYPE_HDMI)
{
arg[1] = (unsigned long)&para;
ret = ioctl(Globctx->DisplayFd, DISP_GET_OUTPUT, arg);
if(ret >= 0)
{
theMostMode = (disp_tv_mode)para.mode;
}
}else{
while(i > 0)
{
i--;
if(g_tv_para[i].mode == DISP_TV_MOD_1080P_60HZ)
theMostMode = DISP_TV_MOD_1080P_60HZ;
arg[1] = DISP_OUTPUT_TYPE_HDMI;
arg[2] = theMostMode;
ret = ioctl(Globctx->DisplayFd, DISP_DEVICE_SWITCH, arg);
return theMostMode;
while(i > 0)
{
i--;
if(g_tv_para[i].mode == DISP_TV_MOD_1080P_60HZ)
{
j = i;
}
if(j != -1)
{
arg[1] = DISP_OUTPUT_TYPE_HDMI;
arg[2] = g_tv_para[i].mode;
ret = ioctl(Globctx->DisplayFd, DISP_DEVICE_SWITCH, arg);
if(ret >= 0)
{
j = i;
if(theMostMode == DISP_TV_MODE_NUM)
{
g_tv_para[sizeof(g_tv_para) / sizeof(g_tv_para[0])-1].support = 1<<select;
theMostMode = g_tv_para[i].mode;
}
g_tv_para[i].support |= 1<<select;
}else{
g_tv_para[i].support &= ~(1<<select);
}
if(j != -1)
{
arg[1] = DISP_OUTPUT_TYPE_HDMI;
arg[2] = g_tv_para[i].mode;
ret = ioctl(Globctx->DisplayFd, DISP_DEVICE_SWITCH, arg);
if(ret >= 0)
{
if(theMostMode == DISP_TV_MODE_NUM)
{
g_tv_para[sizeof(g_tv_para) / sizeof(g_tv_para[0])-1].support = 1<<select;
theMostMode = g_tv_para[i].mode;
}
g_tv_para[i].support |= 1<<select;
}else{
g_tv_para[i].support &= ~(1<<select);
}
}
}
}
}
}
if(theMostMode != DISP_TV_MODE_NUM)
{
return theMostMode;
@ -213,6 +210,8 @@ int hwc_hotplug_switch(int DisplayNum, bool plug, disp_tv_mode set_mode)
int vir_disp = -1;
DisplayInfo *PsDisplayInfo = NULL;
ALOGE("hwc_hotplug_switch: displayNum=%d plug=%d set_mode=%d", DisplayNum, plug, set_mode);
unsigned long arg[4] = {0};
bool AllreadyPlugin = 0;
vir_disp = hwc_manage_display(&PsDisplayInfo, DisplayNum, FIND_HWDISPNUM);
@ -235,7 +234,6 @@ int hwc_hotplug_switch(int DisplayNum, bool plug, disp_tv_mode set_mode)
}
if(set_mode != DISP_TV_MODE_NUM)
{
PsDisplayInfo->setblank = 1;
PsDisplayInfo->VarDisplayWidth = get_info_mode(set_mode,WIDTH);
PsDisplayInfo->VarDisplayHeight = get_info_mode(set_mode,HEIGHT);
PsDisplayInfo->DisplayType = DISP_OUTPUT_TYPE_HDMI;
@ -252,16 +250,11 @@ int hwc_hotplug_switch(int DisplayNum, bool plug, disp_tv_mode set_mode)
PsDisplayInfo->InitDisplayWidth = PsDisplayInfo->VarDisplayWidth;
}
Globctx->memlimit += PsDisplayInfo->InitDisplayHeight * PsDisplayInfo->InitDisplayWidth * 4;
if(Globctx->SunxiDisplay[0].DisplayType != DISP_OUTPUT_TYPE_HDMI)
{
Globctx->hot_plug = 1;
}
Globctx->hot_plug = 1;
arg[0] = DisplayNum;
arg[1] = DISP_OUTPUT_TYPE_HDMI;
arg[2] = set_mode;
ioctl(Globctx->DisplayFd, DISP_DEVICE_SWITCH, (unsigned long)arg);
PsDisplayInfo->setblank = 0;
Globctx->psHwcProcs->invalidate(Globctx->psHwcProcs);
arg[0] = DisplayNum;
arg[1] = 1;
ioctl(Globctx->DisplayFd, DISP_VSYNC_EVENT_EN,(unsigned long)arg);
@ -273,8 +266,7 @@ int hwc_hotplug_switch(int DisplayNum, bool plug, disp_tv_mode set_mode)
ALOGD( "###hdmi plug in, Type:%d, Mode:0x%08x###",
PsDisplayInfo->DisplayType, PsDisplayInfo->DisplayMode);
}
else if(Globctx->SunxiDisplay[0].DisplayType != DISP_OUTPUT_TYPE_HDMI){
}else{
Globctx->hot_plug = 0;
hwc_manage_display(NULL, DisplayNum ,FREE_DISP);
}
@ -289,7 +281,7 @@ int hwc_hotplug_switch(int DisplayNum, bool plug, disp_tv_mode set_mode)
}else{
ALOGD("###psHwcProcs No register.###");
}
if(!plug && Globctx->SunxiDisplay[0].DisplayType != DISP_OUTPUT_TYPE_HDMI)
if(!plug)
{
arg[0] = DisplayNum;
arg[1] = DISP_OUTPUT_TYPE_NONE;
@ -424,7 +416,7 @@ static int hwc_uevent(void)
}
}
if(IsHdmi && Globctx->SunxiDisplay[0].DisplayType != DISP_OUTPUT_TYPE_HDMI)
if(IsHdmi)
{
while(s)
{

View file

@ -19,6 +19,7 @@
#include <cutils/log.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>

7
optee_client-master/.gitignore vendored Executable file
View file

@ -0,0 +1,7 @@
cscope.*
build
out
Debug
*.swp
.cproject
.project

18
optee_client-master/.travis.yml Executable file
View file

@ -0,0 +1,18 @@
# One may have a look at http://docs.travis-ci.com/user/installing-dependencies/
language: c
notifications:
- email: true
# Install the cross-compiler
before_install:
- sudo apt-get update -qq
- sudo apt-get install -y gcc-arm-linux-gnueabihf
- arm-linux-gnueabihf-gcc --version
# Several compilation options are checked
script:
- make clean all
- CFG_TEE_CLIENT_LOG_LEVEL=0 make clean all
- CFG_TEE_CLIENT_LOG_LEVEL=5 make clean all

72
optee_client-master/Android.mk Executable file
View file

@ -0,0 +1,72 @@
# Android optee-client and optee-supplicant makefile #
################################################################################
LOCAL_PATH := $(call my-dir)
ifeq ($(SECURE_OS_OPTEE), yes)
################################################################################
# Include optee-client common config and flags #
################################################################################
include $(LOCAL_PATH)/config.mk
include $(LOCAL_PATH)/flags.mk
################################################################################
# Build libteec.so - TEE (Trusted Execution Environment) shared library #
################################################################################
include $(CLEAR_VARS)
LOCAL_CFLAGS += -DANDROID_BUILD
#LOCAL_CFLAGS += $(CFLAGS)
ifeq ($(CFG_TEE_CLIENT_LOG_FILE), true)
LOCAL_CFLAGS += -DTEEC_LOG_FILE=$(CFG_TEE_CLIENT_LOG_FILE)
endif
LOCAL_CFLAGS += -DDEBUGLEVEL_$(CFG_TEE_CLIENT_LOG_LEVEL)
LOCAL_CFLAGS += -DBINARY_PREFIX=\"TEEC\"
LOCAL_SRC_FILES += libteec/src/tee_client_api.c
LOCAL_SRC_FILES += libteec/src/teec_trace.c
LOCAL_SHARED_LIBRARIES:=\
libcutils \
libutils
LOCAL_C_INCLUDES := $(LOCAL_PATH)/public \
$(LOCAL_PATH)/libteec/include \
LOCAL_PRELINK_MODULE := false
LOCAL_MODULE := libteec
LOCAL_MODULE_TAGS := optional
include $(BUILD_SHARED_LIBRARY)
################################################################################
# Build tee supplicant #
################################################################################
include $(CLEAR_VARS)
#LOCAL_CFLAGS += -DANDROID_BUILD
#LOCAL_CFLAGS += $(CFLAGS)
LOCAL_CFLAGS += -DDEBUGLEVEL_$(CFG_TEE_SUPP_LOG_LEVEL)
LOCAL_CFLAGS += -DBINARY_PREFIX=\"TEES\"
LOCAL_CFLAGS += -DTEEC_LOAD_PATH=\"$(CFG_TEE_CLIENT_LOAD_PATH)\"
LOCAL_SRC_FILES += tee-supplicant/src/handle.c
LOCAL_SRC_FILES += tee-supplicant/src/tee_supp_fs.c
LOCAL_SRC_FILES += tee-supplicant/src/tee_supplicant.c
LOCAL_SRC_FILES += tee-supplicant/src/teec_ta_load.c
LOCAL_SHARED_LIBRARIES:=\
libcutils \
libutils
LOCAL_C_INCLUDES := $(LOCAL_PATH)/public \
$(LOCAL_PATH)/libteec/include \
$(LOCAL_PATH)/tee-supplicant/src
LOCAL_SHARED_LIBRARIES := libteec liblog
LOCAL_MODULE := tee_supplicant
LOCAL_MODULE_TAGS := optional
LOCAL_MULTILIB := 32
include $(BUILD_EXECUTABLE)
endif

27
optee_client-master/LICENSE Executable file
View file

@ -0,0 +1,27 @@
Unless it has its own copyright/license embedded in its body, each source file
is subject to the following license terms:
Copyright (c) 2014, STMicroelectronics International N.V.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. 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.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.

129
optee_client-master/Makefile Executable file
View file

@ -0,0 +1,129 @@
# Public variables are stored in config.mk
include ./config.mk
#########################################################################
# Set Internal Variables #
# May be modified to match your setup #
#########################################################################
BUILD_VERBOSE ?= 0
VPREFIX ?= @
COMPILER_DIR ?= $(CURDIR)/../toolchain/gcc-aarch64/bin
ifeq ($(BUILD_VERBOSE),1)
VPREFIX:=
endif
export VPREFIX COMPILER_DIR
EXPORT_DIR ?= $(O)/export
ROOTFS_DIR ?= $(CURDIR)/../../../out/sun50iw1p1/linux/common/rootfs_def
.PHONY: all build build-libteec install copy_export \
clean cscope clean-cscope \
checkpatch-pre-req checkpatch-modified-patch checkpatch-modified-file \
checkpatch-last-commit-patch checkpatch-last-commit-file \
checkpatch-base-commit-patch checkpatch-base-commit-file \
checkpatch-all-files distclean
all: build install
build-libteec:
@echo "Building libteec.so"
@$(MAKE) --directory=libteec --no-print-directory
build-tee-supplicant: build-libteec
@echo "Building tee-supplicant"
$(MAKE) --directory=tee-supplicant --no-print-directory
build: build-libteec build-tee-supplicant
install: copy_export
clean: clean-libteec clean-tee-supplicant clean-cscope
clean-libteec:
@$(MAKE) --directory=libteec --no-print-directory clean
clean-tee-supplicant:
@$(MAKE) --directory=tee-supplicant --no-print-directory clean
cscope:
@echo " CSCOPE"
${VPREFIX}find ${CURDIR} -name "*.[chsS]" > cscope.files
${VPREFIX}cscope -b -q -k
clean-cscope:
${VPREFIX}rm -f cscope.*
# Various checkpatch targets. The ones ending with "patch" only considers the
# patch, whilst the ones ending with "file" checks the complete file.
# +-------------------------------+------------+----------------------------+
# | Target commit | File/Patch | Comment |
# +-------------------------------+------------+----------------------------+
# | checkpatch-modified-patch | Patch | Check local modifications |
# +-------------------------------+------------+----------------------------+
# | checkpatch-modified-file | File | Check Local modifications |
# +-------------------------------+------------+----------------------------+
# | checkpatch-last-commit-patch | Patch | Check against HEAD^ |
# +-------------------------------+------------+----------------------------+
# | checkpatch-last-commit-file | File | Check against HEAD^ |
# +-------------------------------+------------+----------------------------+
# | checkpatch-base-commit-patch | Patch | Against specic commit |
# +-------------------------------+------------+----------------------------+
# | checkpatch-base-commit-file | File | Against specic commit |
# +-------------------------------+------------+----------------------------+
# | checkpatch-all-files | File | Check all tracked files |
# +-------------------------------+------------+----------------------------+
CHECKPATCH_IGNORE ?= --ignore NEW_TYPEDEFS --no-signoff
CHECKPATCH_STRICT ?= --strict
CHECKPATCH_ARGS ?= $(CHECKPATCH_IGNORE) $(CHECKPATCH_STRICT) --no-tree --terse
CHECKPATCH_PATCH_ARGS := $(CHECKPATCH_ARGS) --patch
CHECKPATCH_FILE_ARGS := $(CHECKPATCH_ARGS) --file --no-patch
checkpatch-pre-req:
@echo " CHECKPATCH"
ifndef CHECKPATCH
$(error "Environment variable CHECKPATCH must point to Linux kernels checkpatch script")
else
ifeq (,$(wildcard ${CHECKPATCH}))
$(error "CHECKPATCH points to the incorrect file")
endif
endif
checkpatch-modified-patch: checkpatch-pre-req
${VPREFIX}git diff | ${CHECKPATCH} $(CHECKPATCH_PATCH_ARGS) - || true
checkpatch-modified-file: checkpatch-pre-req
${VPREFIX}${CHECKPATCH} $(CHECKPATCH_FILE_ARGS) $(shell git diff --name-only)
checkpatch-last-commit-patch: checkpatch-pre-req
${VPREFIX}git diff HEAD^ | ${CHECKPATCH} $(CHECKPATCH_PATCH_ARGS) - || true
checkpatch-last-commit-file: checkpatch-pre-req
${VPREFIX}${CHECKPATCH} $(CHECKPATCH_FILE_ARGS) $(shell git diff --name-only HEAD^)
checkpatch-base-commit-patch: checkpatch-pre-req
ifndef BASE_COMMIT
$(error "Environment variable BASE_COMMIT must contain a valid commit")
endif
${VPREFIX}git diff $(BASE_COMMIT) | ${CHECKPATCH} $(CHECKPATCH_PATCH_ARGS) - || true
checkpatch-base-commit-file: checkpatch-pre-req
ifndef BASE_COMMIT
$(error "Environment variable BASE_COMMIT must contain a valid commit")
endif
${VPREFIX}${CHECKPATCH} $(CHECKPATCH_FILE_ARGS) $(shell git diff --name-only ${BASE_COMMIT})
checkpatch-all-files: checkpatch-pre-req
${VPREFIX}${CHECKPATCH} $(CHECKPATCH_FILE_ARGS) $(shell git ls-files)
distclean: clean
copy_export: build
mkdir -p ${EXPORT_DIR}/lib ${EXPORT_DIR}/include ${EXPORT_DIR}/bin
cp ${O}/libteec/libteec.so* ${EXPORT_DIR}/lib
cp ${O}/tee-supplicant/tee-supplicant ${EXPORT_DIR}/bin
cp ${O}/libteec/libteec.so* ${ROOTFS_DIR}/usr/lib64
cp ${O}/tee-supplicant/tee-supplicant ${ROOTFS_DIR}/usr/bin
cp public/*.h ${EXPORT_DIR}/include

35
optee_client-master/Notice.md Executable file
View file

@ -0,0 +1,35 @@
OP-TEE
=======
This is the repository of OP-TEE (Open Portable Trusted Execution Environment), the open-source TEE maintained by STMicroelectronics, with initial contributions from STMicroelectronics, Ericsson, the Linaro industry association.
What OP-TEE is
------
OP-TEE is designed primarily to rely on the ARM TrustZone(R) technology as the underlying hardware isolation mechanism. However, it has been structured to be compatible with any isolation technology suitable for the TEE concept and goals, such as running as a virtual machine or on a dedicated CPU.
The main design goals for OP-TEE are:
- Isolation - the TEE provides isolation from the Rich OS (typically, Linux/Android) and it protects the Trusted Applications (TAs) it executes from each other, using underlying HW support,
- Small footprint - the TEE should remain small enough so that the TEE core, including all the code and data required to provide isolation, can reside in a reasonable amount of on-chip memory,
- Portability - the TEE must be easily pluggable to different architectures and available HW, and it has to support various setups such as multiple TEEs or multiple client OSes.
Repository structure
------
OP-TEE is composed of three gits:
- The optee-client git, containing the source code for the TEE client library in Linux. This component provides the TEE Client API as defined by the <a href="https://www.globalplatform.org/specificationsdevice.asp">GlobalPlatform TEE standard</a>. It is distributed under the BSD 2-clause open-source license.
- The optee_os git, containing the source code for the TEE OS itself. This component provides the TEE Internal APIs as defined by the GlobalPlatform TEE standard to the Trusted Applications that it executes. It is distributed mostly under the BSD 2-clause open-source license. It includes few external files under BSD 3-clause license or other free software licenses.
- The optee_linuxdriver git, containing the source code for the TEE driver in Linux. This component implements a generic TEE driver, designed primarily for TEE implementations that rely on the ARM TrustZone(R)technology. It is distributed under the GPLv2 open-source license. Please note that re-distribution under other versions of the GPL license is not allowed. The rationale behind this limitation is to ensure that this code may be used on products which have security devices which prevent reloading the code. Such security devices would be incompatible with some licenses such as GPLv3 and so distribution under those licenses would be inconsistent with this goal. Therefore it is recommended that care be taken before redistributing any of the components under other license terms than those provided here.
Contributions
------
Contributions to OP-TEE are managed by the OP-TEE gatekeepers, whose contact email is op-tee-support[at]st[.]com.
Contributions must be original work of the contributor. In order to preserve the rights of the contributor while allowing distribution to and protection of the recipients of OP-TEE, the contributor must complete, sign and send the Contribution Agreement or a scanned copy to ST for counter-signature, prior to any contribution. The address where to send the agreement and other details will be provided upon contact with the OP-TEE gatekeepers.
Once the Contribution Agreement is complete, the contributor may propose contributions to the OP-TEE gatekeepers. Proposed Contributions are reviewed for acceptance by the OP-TEE gatekeepers and the OP-TEE community.
Submission of non-original work
------
You may submit work that is not your original creation separately from any Contribution, identifying the complete details of its source and of any license or other restriction of which you are personally aware. Such submissions are not subject to the Contribution Agreement. They are reviewed for acceptance by the OP-TEE gatekeepers and the OP-TEE community.

84
optee_client-master/README.md Executable file
View file

@ -0,0 +1,84 @@
# OP-TEE Client API
The optee-client git, containing the source code for the TEE client library in
Linux. This component provides the TEE Client API as defined by the
GlobalPlatform TEE standard. It is distributed under the BSD 2-clause
open-source license. For a general overview of OP-TEE, please see the
[Notice.md](Notice.md) file.
In this git there are two main target/binaries to build. There is libteec.so,
which is the library that contains that API for communication with the Trusted
OS. Then the other target is the binary tee-supplicant which is a daemon serving
the Trusted OS in secure world with miscellaneous features, such as file system
access.
## License
The software is provided under the
[BSD 2-Clause](http://opensource.org/licenses/BSD-2-Clause) license.
## Platforms supported
This software in this git doesn't directly have any dependencies to any
particular hardware, since it's pure software library directly communicating
with the Linux kernel. Currently the software has been tested using:
- STMicroelectronics b2020-h416 (orly-2) hardware (32-bits)
- Some initial testing has been done using
[Foundation FVP](http://www.arm.com/fvp), which can be downloaded free of
charge.
## Get and build the software
### Get the compiler
We will strive to use the latest available compiler from Linaro. Start by
downloading and unpacking the compiler. Then export the PATH to the bin folder.
$ cd $HOME
$ mkdir toolchains
$ cd toolchains
$ wget http://releases.linaro.org/14.05/components/toolchain/binaries/gcc-linaro-arm-linux-gnueabihf-4.9-2014.05_linux.tar.xz
$ tar xvf gcc-linaro-arm-linux-gnueabihf-4.9-2014.05_linux.tar.xz
$ export PATH=$HOME/toolchains/gcc-linaro-arm-linux-gnueabihf-4.9-2014.05_linux/bin:$PATH
### Download the source code
$ cd $HOME
$ mkdir devel
$ cd devel
$ git clone https://github.com/OP-TEE/optee_client.git
### Build
$ cd $HOME/devel/optee_client
$ make
#### Compiler flags
To be able to see the full command when building you could build using following
flag:
`$ make BUILD_VERBOSE=1`
## Coding standards
In this project we are trying to adhere to the same coding convention as used in
the Linux kernel (see
[CodingStyle](https://www.kernel.org/doc/Documentation/CodingStyle)). We achieve this by running
[checkpatch](http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/scripts/checkpatch.pl) from Linux kernel.
However there are a few exceptions that we had to make since the code also
follows GlobalPlatform standards. The exceptions are as follows:
- CamelCase for GlobalPlatform types are allowed.
- And we also exclude checking third party code that we might use in this
project, such as LibTomCrypt, MPA, newlib (not in this particular git, but
those are also part of the complete TEE solution). The reason for excluding
and not fixing third party code is because we would probably deviate too much
from upstream and therefore it would be hard to rebase against those projects
later on (and we don't expect that it is easy to convince other software
projects to change coding style).
### checkpatch
Since checkpatch is licensed under the terms of GNU GPL License Version 2, we
cannot include this script directly into this project. Therefore we have
written the Makefile so you need to explicitly point to the script by exporting
an environment variable, namely CHECKPATCH. So, suppose that the source code for
the Linux kernel is at `$HOME/devel/linux`, then you have to export like follows:
$ export CHECKPATCH=$HOME/devel/linux/scripts/checkpatch.pl
thereafter it should be possible to use one of the different checkpatch targets
in the [Makefile](Makefile). There are targets for checking all files, checking
against latest commit, against a certain base-commit etc. For the details, read
the [Makefile](Makefile).

53
optee_client-master/config.mk Executable file
View file

@ -0,0 +1,53 @@
#########################################################################
# Public variables #
# Developers may override these values when calling the makefile, #
# as for example #
# CFG_TEE_CLIENT_LOG_LEVEL=1 make #
# or by declaring the variable in their environement, as for example #
# export CFG_TEE_CLIENT_LOG_LEVEL=1 #
# make #
#########################################################################
# CFG_TEE_CLIENT_LOG_LEVEL
# Client (User Non Secure) log level
# Supported values: 0 (no traces) to 4 (all traces)
CFG_TEE_CLIENT_LOG_LEVEL?=1
export CFG_TEE_CLIENT_LOG_LEVEL
# CFG_TEE_SUPP_LOG_LEVEL
# Supplicant log level
# Supported values: 0 (no traces) to 4 (all traces)
CFG_TEE_SUPP_LOG_LEVEL?=1
export CFG_TEE_SUPP_LOG_LEVEL
# CFG_TEE_CLIENT_LOG_FILE
# The location of the client log file when logging to file is enabled.
CFG_TEE_CLIENT_LOG_FILE ?= \"/data/teec.log\"
# CFG_TEE_SUPP_LOG_FILE
# The location of the supplicant log file when logging to file is enabled.
CFG_TEE_SUPP_LOG_FILE ?= \"/data/teesupp.log\"
# CFG_TEE_CLIENT_LOAD_PATH
# The location of the client library file.
CFG_TEE_CLIENT_LOAD_PATH ?= /system/lib
# Default out dir.
# Must be a relative path with respect to the op-tee-client root directory
O ?= out
export O
#########################################################################
# Private Values #
#########################################################################
# Check that settings are coherent.
ifdef ARM_TOOLCHAIN_DIR
ifeq ($(wildcard ${ARM_TOOLCHAIN_DIR}/bin/${ARM_GCC_PREFIX}-gcc),)
$(error "ARM_TOOLCHAIN_DIR wrongly setup. Is ${ARM_TOOLCHAIN_DIR}")
endif
export ARM_TOOLCHAIN_DIR
export ARM_GCC_PREFIX
endif

24
optee_client-master/flags.mk Executable file
View file

@ -0,0 +1,24 @@
#########################################################################
# COMMON COMPILATION FLAGS #
#########################################################################
CROSS_COMPILE ?= $(COMPILER_DIR)/aarch64-linux-gnu-
CC := $(CROSS_COMPILE)gcc
CFLAGS := -Wall -Wbad-function-cast -Wcast-align \
-Werror-implicit-function-declaration -Wextra \
-Wfloat-equal -Wformat-nonliteral -Wformat-security \
-Wformat=2 -Winit-self -Wmissing-declarations \
-Wmissing-format-attribute -Wmissing-include-dirs \
-Wmissing-noreturn -Wmissing-prototypes -Wnested-externs \
-Wpointer-arith -Wshadow -Wstrict-prototypes \
-Wswitch-default -Wunsafe-loop-optimizations \
-Wwrite-strings -Werror
CFLAGS += -c -fPIC
DEBUG ?= 0
ifeq ($(DEBUG), 1)
CFLAGS += -DDEBUG -O0 -g
endif
RM := rm -rf

View file

@ -0,0 +1,52 @@
include ../flags.mk
OUT_DIR ?= ${CURDIR}/../$(O)/libteec
.PHONY: all libteec clean
all: libteec
################################################################################
# Teec configuration
################################################################################
MAJOR_VERSION := 1
MINOR_VERSION := 0
LIB_NAME := libteec.so
LIB_MAJOR := $(LIB_NAME).$(MAJOR_VERSION)
LIB_MAJ_MIN := $(LIB_NAME).$(MAJOR_VERSION).$(MINOR_VERSION)
TEEC_SRCS := tee_client_api.c \
teec_trace.c
TEEC_SRC_DIR := src
TEEC_OBJ_DIR := $(OUT_DIR)
TEEC_OBJS := $(patsubst %.c,$(TEEC_OBJ_DIR)/%.o, $(TEEC_SRCS))
TEEC_INCLUDES := \
${CURDIR}/include \
${CURDIR}/../public \
TEEC_CFLAGS := $(addprefix -I, $(TEEC_INCLUDES)) $(CFLAGS) -D_GNU_SOURCE \
-DDEBUGLEVEL_$(CFG_TEE_CLIENT_LOG_LEVEL) \
-DBINARY_PREFIX=\"TEEC\"
TEEC_LFLAGS := -lpthread
TEEC_LIBRARY := $(OUT_DIR)/$(LIB_MAJ_MIN)
libteec: $(TEEC_LIBRARY)
$(VPREFIX)ln -sf $(TEEC_LIBRARY) $(OUT_DIR)/$(LIB_MAJOR)
$(VPREFIX)ln -sf $(OUT_DIR)/$(LIB_MAJOR) $(OUT_DIR)/$(LIB_NAME)
$(TEEC_LIBRARY): $(TEEC_OBJS)
@echo " LD $@"
$(VPREFIX)$(CC) -shared -Wl,-soname,$(LIB_MAJ_MIN) $(TEEC_LFLAGS) -o $@ $+
@echo ""
$(TEEC_OBJ_DIR)/%.o: ${TEEC_SRC_DIR}/%.c
$(VPREFIX)mkdir -p $(TEEC_OBJ_DIR)
@echo " CC $<"
$(VPREFIX)$(CC) $(TEEC_CFLAGS) -c $< -o $@
################################################################################
# Cleaning up configuration
################################################################################
clean:
$(RM) $(OUT_DIR)

View file

@ -0,0 +1,97 @@
/*
* Copyright (c) 2014, STMicroelectronics International N.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 _TEE_IOC_H
#define _TEE_IOC_H
#include <tee_client_api.h>
#ifndef __KERNEL__
#define __user
#endif
/**
* struct tee_cmd_io - The command sent to an open tee device.
* @err: Error code (as in Global Platform TEE Client API spec)
* @origin: Origin for the error code (also from spec).
* @cmd: The command to be executed in the trusted application.
* @uuid: The uuid for the trusted application.
* @data: The trusted application or memory block.
* @data_size: The size of the trusted application or memory block.
* @op: The cmd payload operation for the trusted application.
*
* This structure is mainly used in the Linux kernel for communication
* with the user space.
*/
struct tee_cmd_io {
TEEC_Result err;
uint32_t origin;
uint32_t cmd;
int fd_sess;
/*
* Here fd_sess is 32-bit variable. Since TEEC_Result also is defined as
* "uint32_t", this structure is aligned.
*/
union {
TEEC_UUID __user *uuid;
uint64_t padding_uuid;
};
union {
void __user *data;
uint64_t padding_data;
};
union {
TEEC_Operation __user *op;
uint64_t padding_op;
};
uint32_t data_size;
int32_t reserved;
};
struct tee_shm_io {
union {
void __user *buffer;
uint64_t padding_buf;
};
uint32_t size;
uint32_t flags;
/*
* Here fd_shm is 32-bit. To be compliant with the convention of file
* descriptor definition, fd_shm is defined as "int" type other
* than "int32_t". Even though using "int32_t" is more obvious to
* indicate that we intend to keep this structure aligned.
*/
int fd_shm;
uint32_t registered;
};
#define TEE_OPEN_SESSION_IOC _IOWR('t', 161, struct tee_cmd_io)
#define TEE_INVOKE_COMMAND_IOC _IOWR('t', 163, struct tee_cmd_io)
#define TEE_REQUEST_CANCELLATION_IOC _IOWR('t', 164, struct tee_cmd_io)
#define TEE_ALLOC_SHM_IOC _IOWR('t', 165, struct tee_shm_io)
#define TEE_GET_FD_FOR_RPC_SHM_IOC _IOWR('t', 167, struct tee_shm_io)
#endif /* _TEE_IOC_H */

View file

@ -0,0 +1,38 @@
/*
* Copyright (c) 2014, STMicroelectronics International N.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 TEEC_H
#define TEEC_H
#include <stdint.h>
#include "tee_client_api.h"
#include <linux/tee_ioc.h>
#ifndef strlcpy
#define strlcpy(dst, src, size) snprintf((dst), (size), "%s", (src))
#endif
#endif

View file

@ -0,0 +1,452 @@
/*
* Copyright (c) 2014, STMicroelectronics International N.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <teec_trace.h>
#include <teec.h>
#include <tee_client_api.h>
#include <malloc.h>
#include <utils/Log.h>
#define TEE_TZ_DEVICE_NAME "opteearmtz00"
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
/*
* Maximum size of the device name
*/
#define TEEC_MAX_DEVNAME_SIZE 256
/*
#ifdef _GNU_SOURCE
static pthread_mutex_t mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
#else
static pthread_mutex_t mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER;
#endif
*/
static pthread_mutex_t mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
static void teec_mutex_lock(pthread_mutex_t *mu)
{
int e = pthread_mutex_lock(mu);
if (e != 0)
EMSG("pthread_mutex_lock failed: %d\n", e);
}
static void teec_mutex_unlock(pthread_mutex_t *mu)
{
int e = pthread_mutex_unlock(mu);
if (e != 0)
EMSG("pthread_mutex_unlock failed: %d\n", e);
}
static void teec_resetTeeCmd(struct tee_cmd_io *cmd)
{
memset((void *)cmd, 0, sizeof(struct tee_cmd_io));
cmd->fd_sess = -1;
cmd->cmd = 0;
cmd->uuid = NULL;
cmd->origin = TEEC_ORIGIN_API;
cmd->err = TEEC_SUCCESS;
cmd->data = NULL;
cmd->data_size = 0;
cmd->op = NULL;
}
/*
* This function initializes a new TEE Context, connecting this Client
* application to the TEE identified by the name name.
*
* name == NULL will give the default TEE.
*/
TEEC_Result TEEC_InitializeContext(const char *name, TEEC_Context *context)
{
int name_size = 0;
const char* _name = name;
INMSG("%s", name);
ALOGV("%s", name);
if (context == NULL)
return TEEC_ERROR_BAD_PARAMETERS;
/*
* Specification says that when no name is provided it should fall back
* on a predefined TEE.
*/
if (name == NULL)
_name = TEE_TZ_DEVICE_NAME;
name_size = snprintf(context->devname, TEEC_MAX_DEVNAME_SIZE,
"/dev/%s", _name);
if (name_size >= TEEC_MAX_DEVNAME_SIZE)
return TEEC_ERROR_BAD_PARAMETERS; /* Device name truncated */
ALOGV("context->devname=%s\n", context->devname);
context->fd = open(context->devname, O_RDWR);
ALOGV("context-fd=%d, err=%d\n", context->fd, errno);
if (context->fd == -1)
return TEEC_ERROR_ITEM_NOT_FOUND;
ALOGV("context-fd=%d\n", context->fd);
pthread_mutex_init(&mutex, NULL);
OUTMSG("");
return TEEC_SUCCESS;
}
/*
* This function destroys an initialized TEE Context, closing the connection
* between the Client and the TEE.
* The function implementation MUST do nothing if context is NULL
*/
void TEEC_FinalizeContext(TEEC_Context *context)
{
if (context)
close(context->fd);
}
/*
* Allocates or registers shared memory.
*/
TEEC_Result TEEC_AllocateSharedMemory(TEEC_Context *context,
TEEC_SharedMemory *shared_memory)
{
struct tee_shm_io shm;
size_t size;
uint32_t flags;
if (context == NULL || shared_memory == NULL)
return TEEC_ERROR_BAD_PARAMETERS;
size = shared_memory->size;
flags = shared_memory->flags;
memset(shared_memory, 0, sizeof(TEEC_SharedMemory));
shared_memory->size = size;
shared_memory->flags = flags;
memset((void *)&shm, 0, sizeof(shm));
shm.buffer = NULL;
shm.size = size;
shm.registered = 0;
shm.fd_shm = 0;
shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
if (ioctl(context->fd, TEE_ALLOC_SHM_IOC, &shm) != 0) {
EMSG("Ioctl(TEE_ALLOC_SHM_IOC) failed! (%s)\n",
strerror(errno));
return TEEC_ERROR_OUT_OF_MEMORY;
}
DMSG("fd %d size %d flags %08x", shared_memory->d.fd,
(int)shared_memory->size, shared_memory->flags);
shared_memory->size = size;
shared_memory->d.fd = shm.fd_shm;
/*
* Map memory to current user space process.
*
* Adjust the size in case it is 0 as, from the spec:
* The size is allowed to be zero. In this case memory is
* allocated and the pointer written in to the buffer field
* on return MUST not be NULL but MUST never be de-referenced
* by the Client Application. In this case however, the
* Shared Memory block can be used in Registered Memory References
*/
shared_memory->buffer = mmap(NULL,
(shared_memory->size ==
0) ? 8 : shared_memory->size,
PROT_READ | PROT_WRITE, MAP_SHARED,
shared_memory->d.fd, 0);
if (shared_memory->buffer == (void *)MAP_FAILED) {
EMSG("Mmap failed (%s)\n", strerror(errno));
shared_memory->buffer = NULL;
close(shared_memory->d.fd);
return TEEC_ERROR_OUT_OF_MEMORY;
}
shared_memory->registered = 0;
return TEEC_SUCCESS;
}
/*
* Releases shared memory.
*/
void TEEC_ReleaseSharedMemory(TEEC_SharedMemory *shared_memory)
{
if (!shared_memory)
return;
if (shared_memory->registered)
return;
if (shared_memory->d.fd != 0) {
munmap(shared_memory->buffer, (shared_memory->size ==
0) ? 8 : shared_memory->size);
close(shared_memory->d.fd);
shared_memory->d.fd = 0;
}
shared_memory->buffer = NULL;
}
/*
* Register shared memory
*/
TEEC_Result TEEC_RegisterSharedMemory(TEEC_Context *context,
TEEC_SharedMemory *shared_memory)
{
if (!context || !shared_memory)
return TEEC_ERROR_BAD_PARAMETERS;
shared_memory->registered = 1;
/* Use a default fd when not using the dma_buf framework */
if (!(shared_memory->flags & TEEC_MEM_DMABUF))
shared_memory->d.fd = 0;
return TEEC_SUCCESS;
}
/*
* This function opens a new Session between the Client application and the
* specified TEE application.
*
* Only connection_method == TEEC_LOGIN_PUBLIC is supported connection_data and
* operation shall be set to NULL.
*/
TEEC_Result TEEC_OpenSession(TEEC_Context *context,
TEEC_Session *session,
const TEEC_UUID *destination,
uint32_t connection_method,
const void *connection_data,
TEEC_Operation *operation, uint32_t *error_origin)
{
TEEC_Operation dummy_op;
uint32_t origin = TEEC_ORIGIN_API;
TEEC_Result res = TEEC_SUCCESS;
(void)connection_data;
struct tee_cmd_io cmd;
if (session != NULL)
session->fd = -1;
if ((context == NULL) || (session == NULL)) {
res = TEEC_ERROR_BAD_PARAMETERS;
goto error;
}
if (connection_method != TEEC_LOGIN_PUBLIC) {
res = TEEC_ERROR_NOT_SUPPORTED;
goto error;
}
teec_resetTeeCmd(&cmd);
cmd.uuid = (TEEC_UUID *)destination;
if (operation == NULL) {
/*
* The code here exist because Global Platform API states that
* it is allowed to give operation as a NULL pointer. In kernel
* and secure world we in most cases don't want this to be NULL,
* hence we use this dummy operation when a client doesn't
* provide any operation.
*/
memset(&dummy_op, 0, sizeof(TEEC_Operation));
operation = &dummy_op;
}
cmd.op = operation;
ALOGV("context-fd=%d\n", context->fd);
ALOGV("TEEC_OpenSession\n");
ALOGV("TEE_OPEN_SESSION_IOC=0x%x\n", TEE_OPEN_SESSION_IOC);
errno = 0;
if (ioctl(context->fd, TEE_OPEN_SESSION_IOC, &cmd) != 0) {
EMSG("Ioctl(TEE_OPEN_SESSION_IOC) failed! (%s) err %08x ori %08x\n",
strerror(errno), cmd.err, cmd.origin);
if (cmd.origin)
origin = cmd.origin;
else
origin = TEEC_ORIGIN_COMMS;
if (cmd.err)
res = cmd.err;
else
res = TEEC_ERROR_COMMUNICATION;
goto error;
}
session->fd = cmd.fd_sess;
if (cmd.err != 0) {
EMSG("open session to TA UUID %x %x %x failed\n",
destination->timeLow,
destination->timeMid, destination->timeHiAndVersion);
}
origin = cmd.origin;
res = cmd.err;
error:
// printf("**** res=0x%08x, org=%d, seeid=%d ***\n", res, origin, cmd.fd_sess)
/*
* We do this check at the end instead of checking on every place where
* we set the error origin.
*/
if (res != TEEC_SUCCESS) {
if (session != NULL && session->fd != -1) {
close(session->fd);
session->fd = -1;
}
if (context)
close(context->fd);
}
if (error_origin != NULL)
*error_origin = origin;
return res;
}
/*
* This function closes a session which has been opened with a TEE
* application.
*/
void TEEC_CloseSession(TEEC_Session *session)
{
if (session == NULL)
return;
close(session->fd);
}
/*
* Invokes a TEE command (secure service, sub-PA or whatever).
*/
TEEC_Result TEEC_InvokeCommand(TEEC_Session *session,
uint32_t cmd_id,
TEEC_Operation *operation,
uint32_t *error_origin)
{
INMSG("session: [%p], cmd_id: [%d]", session, cmd_id);
struct tee_cmd_io cmd;
TEEC_Operation dummy_op;
TEEC_Result result = TEEC_SUCCESS;
uint32_t origin = TEEC_ORIGIN_API;
if (session == NULL) {
origin = TEEC_ORIGIN_API;
result = TEEC_ERROR_BAD_PARAMETERS;
goto error;
}
if (operation == NULL) {
/*
* The code here exist because Global Platform API states that
* it is allowed to give operation as a NULL pointer. In kernel
* and secure world we in most cases don't want this to be NULL,
* hence we use this dummy operation when a client doesn't
* provide any operation.
*/
memset(&dummy_op, 0, sizeof(TEEC_Operation));
operation = &dummy_op;
}
teec_mutex_lock(&mutex);
operation->session = session;
teec_mutex_unlock(&mutex);
teec_resetTeeCmd(&cmd);
cmd.cmd = cmd_id;
cmd.op = operation;
if (ioctl(session->fd, TEE_INVOKE_COMMAND_IOC, &cmd) != 0)
EMSG("Ioctl(TEE_INVOKE_COMMAND_IOC) failed! (%s)\n",
strerror(errno));
if (operation != NULL) {
teec_mutex_lock(&mutex);
operation->session = NULL;
teec_mutex_unlock(&mutex);
}
origin = cmd.origin;
result = cmd.err;
ALOGV("cmd = 0x%x, cmd.err = %d \n", cmd.cmd, cmd.err);
error:
if (error_origin != NULL)
*error_origin = origin;
OUTRMSG(result);
}
void TEEC_RequestCancellation(TEEC_Operation *operation)
{
struct tee_cmd_io cmd;
TEEC_Session *session;
if (operation == NULL)
return;
teec_mutex_lock(&mutex);
session = operation->session;
teec_mutex_unlock(&mutex);
if (session == NULL)
return;
teec_resetTeeCmd(&cmd);
cmd.op = operation;
if (ioctl(session->fd, TEE_REQUEST_CANCELLATION_IOC, &cmd) != 0)
EMSG("Ioctl(TEE_REQUEST_CANCELLATION_IOC) failed! (%s)\n",
strerror(errno));
}

View file

@ -0,0 +1,172 @@
/*
* Copyright (c) 2014, STMicroelectronics International N.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdarg.h>
#include <stdint.h>
#include <ctype.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include "teec_trace.h"
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
/*
* The length of the prefix is 37, for example it looks like this:
* P = Prefix
* M = Message
* F = Function name
* L = Line number
* PPPP: MMMMM [FFFFFFFFFFFFFFF : LLLLL]
*/
#define MAX_PRINT_SIZE 256
#define MAX_FUNC_PRINT_SIZE 32
#ifdef TEEC_LOG_FILE
static void log_to_file(const char *buffer)
{
FILE *log_file;
log_file = fopen(TEEC_LOG_FILE, "a");
if (log_file != NULL) {
fprintf(log_file, "%s", buffer);
fclose(log_file);
log_file = NULL;
}
}
#else
#define log_to_file(buffer)
#endif
static const char * const trace_level_strings[] = {
"", "ERR", "INF", "DBG", "FLW"
};
int _dprintf(const char *function, int flen, int line, int level,
const char *prefix, const char *fmt, ...)
{
char raw[MAX_PRINT_SIZE];
char prefixed[MAX_PRINT_SIZE];
char *to_print = NULL;
const char *func;
int err;
va_list ap;
va_start(ap, fmt);
err = vsnprintf(raw, sizeof(raw), fmt, ap);
va_end(ap);
if (function) {
#ifdef TRACE_FUNC_LENGTH_CST
char func_buf[MAX_FUNC_PRINT_SIZE];
/* Limit the function name to MAX_FUNC_PRINT_SIZE characters. */
strncpy(func_buf, function, flen > MAX_FUNC_PRINT_SIZE ?
(MAX_FUNC_PRINT_SIZE - 1) : flen);
if (flen < (MAX_FUNC_PRINT_SIZE - 1)) {
memset(func_buf + flen, 0x20,
(MAX_FUNC_PRINT_SIZE - flen));
}
func_buf[MAX_FUNC_PRINT_SIZE - 1] = '\0';
func = func_buf;
#else
(void)flen;
func = function;
#endif
#ifdef ANDROID_BUILD
/* TOD(emi): What is the syscall eq for Android ? */
int thread_id = pthread_self();
#else
/*
* pthread_self returns the POSIX tid which is different from
* the kernel id
*/
int thread_id = syscall(SYS_gettid); /* perf issue ? */
#endif
snprintf(prefixed, MAX_PRINT_SIZE,
"%s [%d] %s:%s:%d: %s",
trace_level_strings[level], thread_id, prefix, func,
line, raw);
to_print = prefixed;
} else {
to_print = raw;
}
fprintf(stdout, "%s", to_print);
log_to_file(to_print);
return err;
}
#if (defined(DEBUGLEVEL_3) || defined(DEBUGLEVEL_true) || defined(DEBUGLEVEL_4))
void dump_buffer(const char *bname, const uint8_t *buffer, size_t blen)
{
fprintf(stderr, "#### %s\n", bname);
while (blen > 0) {
size_t n;
for (n = 0; n < 16; n++) {
if (n < blen)
fprintf(stderr, "%02x ", (int)buffer[n]);
else
fprintf(stderr, " ");
if (n == 7)
fprintf(stderr, " ");
}
fprintf(stderr, " |");
for (n = 0; n < 16; n++) {
if (n < blen) {
if (isprint(buffer[n]))
fprintf(stderr, "%c", (int)buffer[n]);
else
fprintf(stderr, ".");
}
}
fprintf(stderr, "|\n");
blen -= MIN(blen, 16);
buffer += 16;
}
}
#else
void dump_buffer(const char *bname, const uint8_t *buffer, size_t blen)
{
(void)bname;
(void)buffer;
(void)blen;
}
#endif

View file

@ -0,0 +1,615 @@
/*
* Copyright (c) 2014, STMicroelectronics International N.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 TEE_CLIENT_API_H
#define TEE_CLIENT_API_H
#ifndef __KERNEL__
#include <stdint.h>
#include <stddef.h>
#endif /* __KERNEL__ */
/*
* Defines the number of available memory references in an open session or
* invoke command operation payload.
*/
#define TEEC_CONFIG_PAYLOAD_REF_COUNT 4
/**
* Defines the maximum size of a single shared memory block, in bytes, of both
* API allocated and API registered memory. The size is currently set to
* 512 * kB (512 * 1024).
*/
#define TEEC_CONFIG_SHAREDMEM_MAX_SIZE 0x8000
/**
* Flag constants indicating the type of parameters encoded inside the
* operation payload (TEEC_Operation), Type is uint32_t.
*
* TEEC_NONE The Parameter is not used
*
* TEEC_VALUE_INPUT The Parameter is a TEEC_Value tagged as input.
*
* TEEC_VALUE_OUTPUT The Parameter is a TEEC_Value tagged as output.
*
* TEEC_VALUE_INOUT The Parameter is a TEEC_Value tagged as both as
* input and output, i.e., for which both the
* behaviors of TEEC_VALUE_INPUT and
* TEEC_VALUE_OUTPUT apply.
*
* TEEC_MEMREF_TEMP_INPUT The Parameter is a TEEC_TempMemoryReference
* describing a region of memory which needs to be
* temporarily registered for the duration of the
* Operation and is tagged as input.
*
* TEEC_MEMREF_TEMP_OUTPUT Same as TEEC_MEMREF_TEMP_INPUT, but the Memory
* Reference is tagged as output. The
* Implementation may update the size field to
* reflect the required output size in some use
* cases.
*
* TEEC_MEMREF_TEMP_INOUT A Temporary Memory Reference tagged as both
* input and output, i.e., for which both the
* behaviors of TEEC_MEMREF_TEMP_INPUT and
* TEEC_MEMREF_TEMP_OUTPUT apply.
*
* TEEC_MEMREF_WHOLE The Parameter is a Registered Memory Reference
* that refers to the entirety of its parent Shared
* Memory block. The parameter structure is a
* TEEC_MemoryReference. In this structure, the
* Implementation MUST read only the parent field
* and MAY update the size field when the operation
* completes.
*
* TEEC_MEMREF_PARTIAL_INPUT A Registered Memory Reference structure that
* refers to a partial region of its parent Shared
* Memory block and is tagged as input.
*
* TEEC_MEMREF_PARTIAL_OUTPUT Registered Memory Reference structure that
* refers to a partial region of its parent Shared
* Memory block and is tagged as output.
*
* TEEC_MEMREF_PARTIAL_INOUT The Registered Memory Reference structure that
* refers to a partial region of its parent Shared
* Memory block and is tagged as both input and
* output, i.e., for which both the behaviors of
* TEEC_MEMREF_PARTIAL_INPUT and
* TEEC_MEMREF_PARTIAL_OUTPUT apply.
*/
#define TEEC_NONE 0x00000000
#define TEEC_VALUE_INPUT 0x00000001
#define TEEC_VALUE_OUTPUT 0x00000002
#define TEEC_VALUE_INOUT 0x00000003
#define TEEC_MEMREF_TEMP_INPUT 0x00000005
#define TEEC_MEMREF_TEMP_OUTPUT 0x00000006
#define TEEC_MEMREF_TEMP_INOUT 0x00000007
#define TEEC_MEMREF_WHOLE 0x0000000C
#define TEEC_MEMREF_PARTIAL_INPUT 0x0000000D
#define TEEC_MEMREF_PARTIAL_OUTPUT 0x0000000E
#define TEEC_MEMREF_PARTIAL_INOUT 0x0000000F
/**
* Flag constants indicating the data transfer direction of memory in
* TEEC_Parameter. TEEC_MEM_INPUT signifies data transfer direction from the
* client application to the TEE. TEEC_MEM_OUTPUT signifies data transfer
* direction from the TEE to the client application. Type is uint32_t.
*
* TEEC_MEM_INPUT The Shared Memory can carry data from the client
* application to the Trusted Application.
* TEEC_MEM_OUTPUT The Shared Memory can carry data from the Trusted
* Application to the client application.
* TEEC_MEM_DMABUF The Shared Memory is allocated with the dma buf api and
* not necessarily user mapped. The handle will be then the
* fd instead of the buffer
* TEEC_MEM_KAPI Shared memory is required from another Linux module.
* Dma buf file descriptor is not created.
*/
#define TEEC_MEM_INPUT 0x00000001
#define TEEC_MEM_OUTPUT 0x00000002
#define TEEC_MEM_DMABUF 0x00010000
#define TEEC_MEM_KAPI 0x00020000
/**
* Return values. Type is TEEC_Result
*
* TEEC_SUCCESS The operation was successful.
* TEEC_ERROR_GENERIC Non-specific cause.
* TEEC_ERROR_ACCESS_DENIED Access privileges are not sufficient.
* TEEC_ERROR_CANCEL The operation was canceled.
* TEEC_ERROR_ACCESS_CONFLICT Concurrent accesses caused conflict.
* TEEC_ERROR_EXCESS_DATA Too much data for the requested operation was
* passed.
* TEEC_ERROR_BAD_FORMAT Input data was of invalid format.
* TEEC_ERROR_BAD_PARAMETERS Input parameters were invalid.
* TEEC_ERROR_BAD_STATE Operation is not valid in the current state.
* TEEC_ERROR_ITEM_NOT_FOUND The requested data item is not found.
* TEEC_ERROR_NOT_IMPLEMENTED The requested operation should exist but is not
* yet implemented.
* TEEC_ERROR_NOT_SUPPORTED The requested operation is valid but is not
* supported in this implementation.
* TEEC_ERROR_NO_DATA Expected data was missing.
* TEEC_ERROR_OUT_OF_MEMORY System ran out of resources.
* TEEC_ERROR_BUSY The system is busy working on something else.
* TEEC_ERROR_COMMUNICATION Communication with a remote party failed.
* TEEC_ERROR_SECURITY A security fault was detected.
* TEEC_ERROR_SHORT_BUFFER The supplied buffer is too short for the
* generated output.
* TEEC_ERROR_TARGET_DEAD Trusted Application has panicked
* during the operation.
*/
/**
* Standard defined error codes.
*/
#define TEEC_SUCCESS 0x00000000
#define TEEC_ERROR_GENERIC 0xFFFF0000
#define TEEC_ERROR_ACCESS_DENIED 0xFFFF0001
#define TEEC_ERROR_CANCEL 0xFFFF0002
#define TEEC_ERROR_ACCESS_CONFLICT 0xFFFF0003
#define TEEC_ERROR_EXCESS_DATA 0xFFFF0004
#define TEEC_ERROR_BAD_FORMAT 0xFFFF0005
#define TEEC_ERROR_BAD_PARAMETERS 0xFFFF0006
#define TEEC_ERROR_BAD_STATE 0xFFFF0007
#define TEEC_ERROR_ITEM_NOT_FOUND 0xFFFF0008
#define TEEC_ERROR_NOT_IMPLEMENTED 0xFFFF0009
#define TEEC_ERROR_NOT_SUPPORTED 0xFFFF000A
#define TEEC_ERROR_NO_DATA 0xFFFF000B
#define TEEC_ERROR_OUT_OF_MEMORY 0xFFFF000C
#define TEEC_ERROR_BUSY 0xFFFF000D
#define TEEC_ERROR_COMMUNICATION 0xFFFF000E
#define TEEC_ERROR_SECURITY 0xFFFF000F
#define TEEC_ERROR_SHORT_BUFFER 0xFFFF0010
#define TEEC_ERROR_EXTERNAL_CANCEL 0xFFFF0011
#define TEEC_ERROR_TARGET_DEAD 0xFFFF3024
/**
* Function error origins, of type TEEC_ErrorOrigin. These indicate where in
* the software stack a particular return value originates from.
*
* TEEC_ORIGIN_API The error originated within the TEE Client API
* implementation.
* TEEC_ORIGIN_COMMS The error originated within the underlying
* communications stack linking the rich OS with
* the TEE.
* TEEC_ORIGIN_TEE The error originated within the common TEE code.
* TEEC_ORIGIN_TRUSTED_APP The error originated within the Trusted Application
* code.
*/
#define TEEC_ORIGIN_API 0x00000001
#define TEEC_ORIGIN_COMMS 0x00000002
#define TEEC_ORIGIN_TEE 0x00000003
#define TEEC_ORIGIN_TRUSTED_APP 0x00000004
/**
* Session login methods, for use in TEEC_OpenSession() as parameter
* connectionMethod. Type is uint32_t.
*
* TEEC_LOGIN_PUBLIC No login data is provided.
* TEEC_LOGIN_USER Login data about the user running the Client
* Application process is provided.
* TEEC_LOGIN_GROUP Login data about the group running the Client
* Application process is provided.
* TEEC_LOGIN_APPLICATION Login data about the running Client Application
* itself is provided.
*/
#define TEEC_LOGIN_PUBLIC 0x00000000
#define TEEC_LOGIN_USER 0x00000001
#define TEEC_LOGIN_GROUP 0x00000002
#define TEEC_LOGIN_APPLICATION 0x00000004
/**
* Encode the paramTypes according to the supplied types.
*
* @param p0 The first param type.
* @param p1 The second param type.
* @param p2 The third param type.
* @param p3 The fourth param type.
*/
#define TEEC_PARAM_TYPES(p0, p1, p2, p3) \
((p0) | ((p1) << 4) | ((p2) << 8) | ((p3) << 12))
/**
* Get the i_th param type from the paramType.
*
* @param p The paramType.
* @param i The i-th parameter to get the type for.
*/
#define TEEC_PARAM_TYPE_GET(p, i) (((p) >> (i * 4)) & 0xF)
typedef uint32_t TEEC_Result;
/**
* struct TEEC_Context - Represents a connection between a client application
* and a TEE.
*
* Context identifier can be a handle (when opened from user land)
* or a structure pointer (when opened from kernel land).
* Identifier is defined as an union to match type sizes on all architectures.
*/
typedef struct {
char devname[256];
union {
struct tee_context *ctx;
int fd;
};
} TEEC_Context;
/**
* This type contains a Universally Unique Resource Identifier (UUID) type as
* defined in RFC4122. These UUID values are used to identify Trusted
* Applications.
*/
typedef struct {
uint32_t timeLow;
uint16_t timeMid;
uint16_t timeHiAndVersion;
uint8_t clockSeqAndNode[8];
} TEEC_UUID;
/**
* In terms of compatible kernel, the data struct shared by client application
* and TEE driver should be restructrued in "compatible" rules. To keep GP's
* standard in compatibility mode, the anonymous padding members are filled
* in the struct definition below.
*/
/**
* struct TEEC_SharedMemory - Memory to transfer data between a client
* application and trusted code.
*
* @param buffer The memory buffer which is to be, or has been, shared
* with the TEE.
* @param size The size, in bytes, of the memory buffer.
* @param flags Bit-vector which holds properties of buffer.
* The bit-vector can contain either or both of the
* TEEC_MEM_INPUT and TEEC_MEM_OUTPUT flags.
*
* A shared memory block is a region of memory allocated in the context of the
* client application memory space that can be used to transfer data between
* that client application and a trusted application. The user of this struct
* is responsible to populate the buffer pointer.
*/
typedef struct {
union {
void *buffer;
uint64_t padding_ptr;
};
union {
size_t size;
uint64_t padding_sz;
};
uint32_t flags;
/*
* Implementation-Defined, must match what the kernel driver have
*
* Identifier can store a handle (int) or a structure pointer (void *).
* Define this union to match case where sizeof(int)!=sizeof(void *).
*/
uint32_t reserved;
union {
int fd;
void *ptr;
uint64_t padding_d;
} d;
uint64_t registered;
} TEEC_SharedMemory;
/**
* struct TEEC_TempMemoryReference - Temporary memory to transfer data between
* a client application and trusted code, only used for the duration of the
* operation.
*
* @param buffer The memory buffer which is to be, or has been shared with
* the TEE.
* @param size The size, in bytes, of the memory buffer.
*
* A memory buffer that is registered temporarily for the duration of the
* operation to be called.
*/
typedef struct {
union {
void *buffer;
uint64_t padding_ptr;
};
union {
size_t size;
uint64_t padding_sz;
};
} TEEC_TempMemoryReference;
/**
* struct TEEC_RegisteredMemoryReference - use a pre-registered or
* pre-allocated shared memory block of memory to transfer data between
* a client application and trusted code.
*
* @param parent Points to a shared memory structure. The memory reference
* may utilize the whole shared memory or only a part of it.
* Must not be NULL
*
* @param size The size, in bytes, of the memory buffer.
*
* @param offset The offset, in bytes, of the referenced memory region from
* the start of the shared memory block.
*
*/
typedef struct {
union {
TEEC_SharedMemory *parent;
uint64_t padding_ptr;
};
union {
size_t size;
uint64_t padding_sz;
};
union {
size_t offset;
uint64_t padding_off;
};
} TEEC_RegisteredMemoryReference;
/**
* struct TEEC_Value - Small raw data container
*
* Instead of allocating a shared memory buffer this structure can be used
* to pass small raw data between a client application and trusted code.
*
* @param a The first integer value.
*
* @param b The second second value.
*/
typedef struct {
uint32_t a;
uint32_t b;
} TEEC_Value;
/**
* union TEEC_Parameter - Memory container to be used when passing data between
* client application and trusted code.
*
* Either the client uses a shared memory reference, parts of it or a small raw
* data container.
*
* @param tmpref A temporary memory reference only valid for the duration
* of the operation.
*
* @param memref The entire shared memory or parts of it.
*
* @param value The small raw data container to use
*/
typedef union {
TEEC_TempMemoryReference tmpref;
TEEC_RegisteredMemoryReference memref;
TEEC_Value value;
} TEEC_Parameter;
/**
* struct TEEC_Session - Represents a connection between a client application
* and a trusted application.
*
* Session identifier can be a handle (when opened from user land) or a
* structure pointer (when opened from kernel land).
* Identifier is defined as an union to match type sizes on all architectures.
*/
typedef union {
int fd;
struct tee_session *session;
} TEEC_Session;
/**
* struct TEEC_Operation - Holds information and memory references used in
* TEEC_InvokeCommand().
*
* @param started Client must initialize to zero if it needs to cancel
* an operation about to be performed.
* @param paramTypes Type of data passed. Use TEEC_PARAMS_TYPE macro to
* create the correct flags.
* 0 means TEEC_NONE is passed for all params.
* @param params Array of parameters of type TEEC_Parameter.
* @param session Internal pointer to the last session used by
* TEEC_InvokeCommand with this operation.
*
*/
typedef struct {
uint32_t started;
uint32_t paramTypes;
TEEC_Parameter params[TEEC_CONFIG_PAYLOAD_REF_COUNT];
/* Implementation-Defined */
union {
TEEC_Session *session;
uint64_t padding_ptr;
};
TEEC_SharedMemory memRefs[TEEC_CONFIG_PAYLOAD_REF_COUNT];
uint64_t flags;
} TEEC_Operation;
#ifdef __cplusplus
extern "C" {
#endif
/**
* TEEC_InitializeContext() - Initializes a context holding connection
* information on the specific TEE, designated by the name string.
* @param name A zero-terminated string identifying the TEE to connect to.
* If name is set to NULL, the default TEE is connected to. NULL
* is the only supported value in this version of the API
* implementation.
*
* @param context The context structure which is to be initialized.
*
* @return TEEC_SUCCESS The initialization was successful.
* @return TEEC_Result Something failed.
*/
TEEC_Result TEEC_InitializeContext(const char *name, TEEC_Context *context);
/**
* TEEC_FinalizeContext() - Destroys a context holding connection information
* on the specific TEE.
*
* This function destroys an initialized TEE context, closing the connection
* between the client application and the TEE. This function must only be
* called when all sessions related to this TEE context have been closed and
* all shared memory blocks have been released.
*
* @param context The context to be destroyed.
*/
void TEEC_FinalizeContext(TEEC_Context *context);
/**
* TEEC_OpenSession() - Opens a new session with the specified trusted
* application.
*
* @param context The initialized TEE context structure in which
* scope to open the session.
* @param session The session to initialize.
* @param destination A structure identifying the trusted application
* with which to open a session.
*
* @param connectionMethod The connection method to use.
* @param connectionData Any data necessary to connect with the chosen
* connection method. Not supported, should be set to
* NULL.
* @param operation An operation structure to use in the session. May
* be set to NULL to signify no operation structure
* needed.
*
* @param returnOrigin A parameter which will hold the error origin if
* this function returns any value other than
* TEEC_SUCCESS.
*
* @return TEEC_SUCCESS OpenSession successfully opened a new session.
* @return TEEC_Result Something failed.
*
*/
TEEC_Result TEEC_OpenSession(TEEC_Context *context,
TEEC_Session *session,
const TEEC_UUID *destination,
uint32_t connectionMethod,
const void *connectionData,
TEEC_Operation *operation,
uint32_t *returnOrigin);
/**
* TEEC_CloseSession() - Closes the session which has been opened with the
* specific trusted application.
*
* @param session The opened session to close.
*/
void TEEC_CloseSession(TEEC_Session *session);
/**
* TEEC_InvokeCommand() - Executes a command in the specified trusted
* application.
*
* @param session A handle to an open connection to the trusted
* application.
* @param commandID Identifier of the command in the trusted application
* to invoke.
* @param operation An operation structure to use in the invoke command.
* May be set to NULL to signify no operation structure
* needed.
* @param returnOrigin A parameter which will hold the error origin if this
* function returns any value other than TEEC_SUCCESS.
*
* @return TEEC_SUCCESS OpenSession successfully opened a new session.
* @return TEEC_Result Something failed.
*/
TEEC_Result TEEC_InvokeCommand(TEEC_Session *session,
uint32_t commandID,
TEEC_Operation *operation,
uint32_t *returnOrigin);
/**
* TEEC_RegisterSharedMemory() - Register a block of existing memory as a
* shared block within the scope of the specified context.
*
* @param context The initialized TEE context structure in which scope to
* open the session.
* @param sharedMem pointer to the shared memory structure to register.
*
* @return TEEC_SUCCESS The registration was successful.
* @return TEEC_ERROR_OUT_OF_MEMORY Memory exhaustion.
* @return TEEC_Result Something failed.
*/
TEEC_Result TEEC_RegisterSharedMemory(TEEC_Context *context,
TEEC_SharedMemory *sharedMem);
/**
* TEEC_AllocateSharedMemory() - Allocate shared memory for TEE.
*
* @param context The initialized TEE context structure in which scope to
* open the session.
* @param sharedMem Pointer to the allocated shared memory.
*
* @return TEEC_SUCCESS The registration was successful.
* @return TEEC_ERROR_OUT_OF_MEMORY Memory exhaustion.
* @return TEEC_Result Something failed.
*/
TEEC_Result TEEC_AllocateSharedMemory(TEEC_Context *context,
TEEC_SharedMemory *sharedMem);
/**
* TEEC_ReleaseSharedMemory() - Free or deregister the shared memory.
*
* @param sharedMem Pointer to the shared memory to be freed.
*/
void TEEC_ReleaseSharedMemory(TEEC_SharedMemory *sharedMemory);
/**
* TEEC_RequestCancellation() - Request the cancellation of a pending open
* session or command invocation.
*
* @param operation Pointer to an operation previously passed to open session
* or invoke.
*/
void TEEC_RequestCancellation(TEEC_Operation *operation);
/**
* Register a pre-allocated Trusted Application This is mainly intended for
* OS-FREE contexts or when a filesystem is not available.
*
* @param ta Pointer to the trusted application binary
* @param size The size of the TA binary
*
* @return TEEC_SUCCESS if successful.
* @return TEEC_Result something failed.
*/
TEEC_Result TEEC_RegisterTA(const void *ta, const size_t size);
/**
* Unregister a pre-allocated Trusted Application This is mainly intended for
* OS-FREE contexts or when a filesystem is not available.
*
* @param ta Pointer to the trusted application binary
*/
void TEEC_UnregisterTA(const void *ta);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,139 @@
/*
* Copyright (c) 2014, STMicroelectronics International N.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 TEEC_TRACE_H
#define TEEC_TRACE_H
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#ifndef BINARY_PREFIX
#error "BINARY_PREFIX not defined"
#endif
/*
* Trace levels.
*
* ERROR is used when some kind of error has happened, this is most likely the
* print you will use most of the time when you report some kind of error.
*
* INFO is used when you want to print some 'normal' text to the user.
* This is the default level.
*
* DEBUG is used to print extra information to enter deeply in the module.
*
* FLOW is used to print the execution flox, typically the in/out of functions.
*
* */
#define DEBUGLEVEL_0 1
#define TRACE_ERROR 1
#define TRACE_INFO 2
#define TRACE_DEBUG 3
#define TRACE_FLOW 4
#if defined(DEBUGLEVEL_0) && !defined(DEBUGLEVEL)
#define DEBUGLEVEL TRACE_ERROR
#endif
#if defined(DEBUGLEVEL_1) && !defined(DEBUGLEVEL)
#define DEBUGLEVEL TRACE_ERROR
#endif
#if defined(DEBUGLEVEL_2) && !defined(DEBUGLEVEL)
#define DEBUGLEVEL TRACE_INFO
#endif
#if defined(DEBUGLEVEL_3) && !defined(DEBUGLEVEL)
#define DEBUGLEVEL TRACE_DEBUG
#endif
#if defined(DEBUGLEVEL_4) && !defined(DEBUGLEVEL)
#define DEBUGLEVEL TRACE_FLOW
#endif
#ifndef DEBUGLEVEL
/* Default debug level. */
#define DEBUGLEVEL TRACE_INFO
#endif
/*
* This define make sure that parameters are checked in the same manner as it
* is done in the normal printf function.
*/
#define __PRINTFLIKE(__fmt, __varargs) __attribute__\
((__format__(__printf__, __fmt, __varargs)))
int _dprintf(const char *function, int flen, int line, int level,
const char *prefix, const char *fmt, ...) __PRINTFLIKE(6, 7);
#define dprintf(level, x...) do { \
if ((level) <= DEBUGLEVEL) { \
_dprintf(__func__, strlen(__func__), __LINE__, level, \
BINARY_PREFIX, x); \
} \
} while (0)
#define EMSG(fmt, ...) dprintf(TRACE_ERROR, fmt "\n", ##__VA_ARGS__)
#define IMSG(fmt, ...) dprintf(TRACE_INFO, fmt "\n", ##__VA_ARGS__)
#define DMSG(fmt, ...) dprintf(TRACE_DEBUG, fmt "\n", ##__VA_ARGS__)
#define FMSG(fmt, ...) dprintf(TRACE_FLOW, fmt "\n", ##__VA_ARGS__)
#define INMSG(fmt, ...) FMSG("> " fmt, ##__VA_ARGS__)
#define OUTMSG(fmt, ...) FMSG("< " fmt, ##__VA_ARGS__)
#define OUTRMSG(r) \
do { \
if (r) \
EMSG("Function returns with [%d]", r); \
OUTMSG("r=[%d]", r); \
return r; \
} while (0)
#define dprintf_raw(level, x...) do { \
if ((level) <= DEBUGLEVEL) \
_dprintf(0, 0, 0, (level), BINARY_PREFIX, x); \
} while (0)
#define EMSG_RAW(fmt, ...) dprintf_raw(TRACE_ERROR, fmt, ##__VA_ARGS__)
#define IMSG_RAW(fmt, ...) dprintf_raw(TRACE_INFO, fmt, ##__VA_ARGS__)
#define DMSG_RAW(fmt, ...) dprintf_raw(TRACE_DEBUG, fmt, ##__VA_ARGS__)
#define FMSG_RAW(fmt, ...) dprintf_raw(TRACE_FLOW, fmt, ##__VA_ARGS__)
/*
* This function will hex and ascii dump a buffer.
*
* Note that this function will only print if debug flag
* DEBUGLEVEL is INFO or FLOOD.
*
* @param bname Information string describing the buffer.
* @param buffer Pointer to the buffer.
* @param blen Length of the buffer.
*
* @return void
*/
void dump_buffer(const char *bname, const uint8_t *buffer, size_t blen);
#endif

View file

@ -0,0 +1,47 @@
include ../flags.mk
OUT_DIR ?= ${CURDIR}/../$(O)/tee-supplicant
.PHONY: all tee-supplicant clean
all: tee-supplicant
################################################################################
# Teec configuration
################################################################################
PACKAGE_NAME := tee-supplicant
TEES_SRCS := tee_supplicant.c \
teec_ta_load.c \
tee_supp_fs.c \
handle.c
TEES_SRC_DIR := src
TEES_OBJ_DIR := $(OUT_DIR)
TEES_OBJS := $(patsubst %.c,$(TEES_OBJ_DIR)/%.o, $(TEES_SRCS))
TEES_INCLUDES := ${CURDIR}/../libteec/include \
${CURDIR}/src \
${CURDIR}/../public \
TEES_CFLAGS := $(addprefix -I, $(TEES_INCLUDES)) $(CFLAGS) \
-DDEBUGLEVEL_$(CFG_TEE_SUPP_LOG_LEVEL) \
-DBINARY_PREFIX=\"TEES\"
TEES_FILE := $(OUT_DIR)/$(PACKAGE_NAME)
TEES_LDFLAGS := -L$(OUT_DIR)/../libteec -lteec
tee-supplicant: $(TEES_FILE)
$(TEES_FILE): $(TEES_OBJS)
@echo " LD $@"
$(VPREFIX)$(CC) -o $@ $+ $(TEES_LDFLAGS)
@echo ""
$(TEES_OBJ_DIR)/%.o: $(TEES_SRC_DIR)/%.c
$(VPREFIX)mkdir -p $(dir $@)
@echo " CC $<"
$(VPREFIX)$(CC) $(TEES_CFLAGS) -c $< -o $@
################################################################################
# Cleaning up configuration
################################################################################
clean:
$(RM) $(OUT_DIR)

View file

@ -0,0 +1,154 @@
/*
* Copyright (c) 2014, Linaro Limited
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include <string.h>
#include "handle.h"
/*
* Define the initial capacity of the database. It should be a low number
* multiple of 2 since some databases a likely to only use a few handles.
* Since the algorithm is to doubles up when growing it shouldn't cause a
* noticable overhead on large databases.
*/
#define HANDLE_DB_INITIAL_MAX_PTRS 4
static void mutex_lock(struct handle_db *db)
{
if (db->mu)
pthread_mutex_lock(db->mu);
}
static void mutex_unlock(struct handle_db *db)
{
if (db->mu)
pthread_mutex_unlock(db->mu);
}
void handle_db_set_mutex(struct handle_db *db, pthread_mutex_t *mu)
{
db->mu = mu;
}
void handle_db_destroy(struct handle_db *db)
{
if (db) {
mutex_lock(db);
free(db->ptrs);
db->ptrs = NULL;
db->max_ptrs = 0;
mutex_unlock(db);
}
}
int handle_get(struct handle_db *db, void *ptr)
{
size_t n;
void *p;
size_t new_max_ptrs;
int ret;
if (!db || !ptr)
return -1;
mutex_lock(db);
/* Try to find an empty location */
for (n = 0; n < db->max_ptrs; n++) {
if (!db->ptrs[n]) {
db->ptrs[n] = ptr;
ret = n;
goto out;
}
}
/* No location available, grow the ptrs array */
if (db->max_ptrs)
new_max_ptrs = db->max_ptrs * 2;
else
new_max_ptrs = HANDLE_DB_INITIAL_MAX_PTRS;
p = realloc(db->ptrs, new_max_ptrs * sizeof(void *));
if (!p) {
ret = -1;
goto out;
}
db->ptrs = p;
memset(db->ptrs + db->max_ptrs, 0,
(new_max_ptrs - db->max_ptrs) * sizeof(void *));
db->max_ptrs = new_max_ptrs;
/* Since n stopped at db->max_ptrs there is an empty location there */
db->ptrs[n] = ptr;
ret = n;
out:
mutex_unlock(db);
return ret;
}
void *handle_put(struct handle_db *db, int handle)
{
void *p;
if (!db || handle < 0)
return NULL;
mutex_lock(db);
if ((size_t)handle >= db->max_ptrs) {
p = NULL;
goto out;
}
p = db->ptrs[handle];
db->ptrs[handle] = NULL;
out:
mutex_unlock(db);
return p;
}
void *handle_lookup(struct handle_db *db, int handle)
{
void *p;
if (!db || handle < 0)
return NULL;
mutex_lock(db);
if ((size_t)handle >= db->max_ptrs) {
p = NULL;
goto out;
}
p = db->ptrs[handle];
out:
mutex_unlock(db);
return p;
}

View file

@ -0,0 +1,78 @@
/*
* Copyright (c) 2014, Linaro Limited
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 HANDLE_H
#define HANDLE_H
#include <stdint.h>
#include <pthread.h>
struct handle_db {
void **ptrs;
size_t max_ptrs;
pthread_mutex_t *mu;
};
#define HANDLE_DB_INITIALIZER { NULL, 0, NULL }
#define HANDLE_DB_INITIALIZER_WITH_MUTEX(mu) { NULL, 0, (mu) }
/*
* Assigns a mutex for the database. If mu != NULL the mutex will be
* acquired before each access to the database and released when
* the operation is done.
*/
void handle_db_set_mutex(struct handle_db *db, pthread_mutex_t *mu);
/*
* Frees all internal data structures of the database, but does not free
* the db pointer. The database is safe to reuse after it's destroyed, it
* just be empty again. The assigned mutex is also preserved.
*/
void handle_db_destroy(struct handle_db *db);
/*
* Allocates a new handle and assigns the supplied pointer to it,
* ptr must not be NULL.
* The function returns
* >= 0 on success and
* -1 on failure
*/
int handle_get(struct handle_db *db, void *ptr);
/*
* Deallocates a handle. Returns the assiciated pointer of the handle
* the the handle was valid or NULL if it's invalid.
*/
void *handle_put(struct handle_db *db, int handle);
/*
* Returns the assiciated pointer of the handle if the handle is a valid
* handle.
* Returns NULL on failure.
*/
void *handle_lookup(struct handle_db *db, int handle);
#endif /*HANDLE_H*/

View file

@ -0,0 +1,504 @@
/*
* Copyright (c) 2014, STMicroelectronics International N.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <stdint.h>
#include <dirent.h>
#include <unistd.h>
#include <string.h>
#include <tee_supp_fs.h>
#include <handle.h>
/*
* Operations and defines shared with TEE.
*/
#define TEE_FS_OPEN 1
#define TEE_FS_CLOSE 2
#define TEE_FS_READ 3
#define TEE_FS_WRITE 4
#define TEE_FS_SEEK 5
#define TEE_FS_UNLINK 6
#define TEE_FS_RENAME 7
#define TEE_FS_TRUNC 8
#define TEE_FS_MKDIR 9
#define TEE_FS_OPENDIR 10
#define TEE_FS_CLOSEDIR 11
#define TEE_FS_READDIR 12
#define TEE_FS_RMDIR 13
#define TEE_FS_ACCESS 14
#define TEE_FS_LINK 15
/*
* Open flags, defines shared with TEE.
*/
#define TEE_FS_O_RDONLY 0x1
#define TEE_FS_O_WRONLY 0x2
#define TEE_FS_O_RDWR 0x4
#define TEE_FS_O_CREAT 0x8
#define TEE_FS_O_EXCL 0x10
#define TEE_FS_O_APPEND 0x20
/*
* Seek flags, defines shared with TEE.
*/
#define TEE_FS_SEEK_SET 0x1
#define TEE_FS_SEEK_END 0x2
#define TEE_FS_SEEK_CUR 0x4
/*
* Mkdir flags, defines shared with TEE.
*/
#define TEE_FS_S_IWUSR 0x1
#define TEE_FS_S_IRUSR 0x2
/*
* Access flags, X_OK not supported, defines shared with TEE.
*/
#define TEE_FS_R_OK 0x1
#define TEE_FS_W_OK 0x2
#define TEE_FS_F_OK 0x4
/* Path to all secure storage files. */
#define TEE_FS_SUBPATH "/data"
#define TEE_FS_PATH "/data/tee/"
#ifndef PATH_MAX
#define PATH_MAX 255
#endif
#define TEE_FS_FILENAME_MAX_LENGTH 150
/*
* Structure for file related RPC calls
*
* @op The operation like open, close, read, write etc
* @flags Flags to the operation shared with secure world
* @arg Argument to operation
* @fd NW file descriptor
* @len Length of buffer at the end of this struct
* @res Result of the operation
*/
struct tee_fs_rpc {
int op;
int flags;
int arg;
int fd;
uint32_t len;
int res;
};
static pthread_mutex_t dir_handle_db_mutex = PTHREAD_MUTEX_INITIALIZER;
static struct handle_db dir_handle_db =
HANDLE_DB_INITIALIZER_WITH_MUTEX(&dir_handle_db_mutex);
/* Function to convert TEE open flags to UNIX IO */
static int tee_fs_conv_oflags(int in)
{
int flags = 0;
if (in & TEE_FS_O_RDONLY)
flags |= O_RDONLY;
if (in & TEE_FS_O_WRONLY)
flags |= O_WRONLY;
if (in & TEE_FS_O_RDWR)
flags |= O_RDWR;
if (in & TEE_FS_O_CREAT)
flags |= O_CREAT;
if (in & TEE_FS_O_EXCL)
flags |= O_EXCL;
if (in & TEE_FS_O_APPEND)
flags |= O_APPEND;
return flags;
}
/* Function to convert TEE seek flags to UNIX IO */
static int tee_fs_conv_whence(int in)
{
int flags = 0;
if (in & TEE_FS_SEEK_SET)
flags |= SEEK_SET;
if (in & TEE_FS_SEEK_END)
flags |= SEEK_END;
if (in & TEE_FS_SEEK_CUR)
flags |= SEEK_CUR;
return flags;
}
/* Function to convert TEE open flags to UNIX IO */
static mode_t tee_fs_conv_mkdflags(int in)
{
int flags = 0;
if (in & TEE_FS_S_IWUSR)
flags |= S_IWUSR;
if (in & TEE_FS_S_IRUSR)
flags |= S_IRUSR;
return flags;
}
static int tee_fs_conv_accessflags(int in)
{
int flags = 0;
if (in & TEE_FS_R_OK)
flags |= R_OK;
if (in & TEE_FS_W_OK)
flags |= W_OK;
if (in & TEE_FS_F_OK)
flags |= F_OK;
return flags;
}
static size_t tee_fs_get_absolute_filename(char *file, char *out,
size_t out_size)
{
int s;
if (!file || !out || (out_size <= sizeof(TEE_FS_PATH)))
return 0;
s = snprintf(out, out_size, "%s%s", TEE_FS_PATH, file);
if (s < 0 || (size_t)s >= out_size)
return 0;
/* Safe to cast since we have checked that sizes are OK */
return (size_t)s;
}
static int tee_fs_open(struct tee_fs_rpc *fsrpc)
{
char abs_filename[PATH_MAX];
char *filename = (char *)(fsrpc + 1);
int flags;
size_t filesize = tee_fs_get_absolute_filename(filename, abs_filename,
sizeof(abs_filename));
if (!filesize)
return -1; /* Corresponds to error using open */
flags = tee_fs_conv_oflags(fsrpc->flags);
fsrpc->fd = open(abs_filename, flags, S_IRUSR | S_IWUSR);
return fsrpc->fd;
}
static int tee_fs_close(struct tee_fs_rpc *fsrpc)
{
return close(fsrpc->fd);
}
static int tee_fs_read(struct tee_fs_rpc *fsrpc)
{
void *data = (void *)(fsrpc + 1);
return read(fsrpc->fd, data, fsrpc->len);
}
static int tee_fs_write(struct tee_fs_rpc *fsrpc)
{
void *data = (void *)(fsrpc + 1);
return write(fsrpc->fd, data, fsrpc->len);
}
static int tee_fs_seek(struct tee_fs_rpc *fsrpc)
{
int wh = tee_fs_conv_whence(fsrpc->flags);
fsrpc->res = lseek(fsrpc->fd, fsrpc->arg, wh);
return fsrpc->res;
}
static int tee_fs_unlink(struct tee_fs_rpc *fsrpc)
{
char abs_filename[PATH_MAX];
char *filename = (char *)(fsrpc + 1);
int ret = -1; /* Corresponds to error using unlink */
size_t filesize = tee_fs_get_absolute_filename(filename, abs_filename,
sizeof(abs_filename));
if (filesize)
ret = unlink(abs_filename);
return ret;
}
static int tee_fs_link(struct tee_fs_rpc *fsrpc)
{
char old_fn[PATH_MAX];
char new_fn[PATH_MAX];
char *filenames = (char *)(fsrpc + 1);
int ret = -1; /* Corresponds to error value for link */
/*
* During a link operation secure world sends the two NULL terminated
* filenames as a single concatenated string, as for example:
* "old.txt\0new.txt\0"
* Therefore we start by finding the offset to where the new filename
* begins.
*/
size_t offset_new_fn = strlen(filenames) + 1;
size_t filesize = tee_fs_get_absolute_filename(filenames, old_fn,
sizeof(old_fn));
if (!filesize)
goto exit;
filesize = tee_fs_get_absolute_filename(filenames + offset_new_fn,
new_fn, sizeof(new_fn));
if (filesize)
ret = link(old_fn, new_fn);
exit:
return ret;
}
static int tee_fs_rename(struct tee_fs_rpc *fsrpc)
{
char old_fn[PATH_MAX];
char new_fn[PATH_MAX];
char *filenames = (char *)(fsrpc + 1);
int ret = -1; /* Corresponds to error value for rename */
/*
* During a rename operation secure world sends the two NULL terminated
* filenames as a single concatenated string, as for example:
* "old.txt\0new.txt\0"
* Therefore we start by finding the offset to where the new filename
* begins.
*/
size_t offset_new_fn = strlen(filenames) + 1;
size_t filesize = tee_fs_get_absolute_filename(filenames, old_fn,
sizeof(old_fn));
if (!filesize)
goto exit;
filesize = tee_fs_get_absolute_filename(filenames + offset_new_fn,
new_fn, sizeof(new_fn));
if (filesize)
ret = rename(old_fn, new_fn);
exit:
return ret;
}
static int tee_fs_truncate(struct tee_fs_rpc *fsrpc)
{
return ftruncate(fsrpc->fd, fsrpc->arg);
}
static int tee_fs_mkdir(struct tee_fs_rpc *fsrpc)
{
char abs_dirname[PATH_MAX];
char *dirname = (char *)(fsrpc + 1);
mode_t mode;
int ret = -1; /* Same as mkir on error */
size_t filesize = tee_fs_get_absolute_filename(dirname, abs_dirname,
sizeof(abs_dirname));
if (filesize) {
mode = tee_fs_conv_mkdflags(fsrpc->flags);
ret = mkdir(abs_dirname, mode);
}
return ret;
}
static int tee_fs_opendir(struct tee_fs_rpc *fsrpc)
{
char abs_dirname[PATH_MAX];
char *dirname = (char *)(fsrpc + 1);
DIR *dir;
int handle = -1;
size_t filesize = tee_fs_get_absolute_filename(dirname, abs_dirname,
sizeof(abs_dirname));
if (!filesize)
goto exit;
dir = opendir(abs_dirname);
if (!dir)
goto exit;
handle = handle_get(&dir_handle_db, dir);
if (handle < 0)
closedir(dir);
exit:
return handle;
}
static int tee_fs_closedir(struct tee_fs_rpc *fsrpc)
{
DIR *dir = handle_put(&dir_handle_db, fsrpc->arg);
return closedir(dir);
}
static int tee_fs_readdir(struct tee_fs_rpc *fsrpc)
{
char *dirname = (char *)(fsrpc + 1);
DIR *dir = handle_lookup(&dir_handle_db, fsrpc->arg);
struct dirent *dirent;
size_t len;
do
dirent = readdir(dir);
while (dirent != NULL && dirent->d_name[0] == '.');
if (dirent == NULL) {
fsrpc->len = 0;
return -1;
}
len = strlen(dirent->d_name);
if (len > PATH_MAX)
return -1;
len++;
memcpy(dirname, dirent->d_name, len);
fsrpc->len = len;
return 0;
}
static int tee_fs_rmdir(struct tee_fs_rpc *fsrpc)
{
char abs_dirname[PATH_MAX];
char *dirname = (char *)(fsrpc + 1);
int ret = -1; /* Corresponds to the error value for rmdir */
size_t filesize = tee_fs_get_absolute_filename(dirname, abs_dirname,
sizeof(abs_dirname));
if (filesize)
ret = rmdir(abs_dirname);
return ret;
}
static int tee_fs_access(struct tee_fs_rpc *fsrpc)
{
char abs_filename[PATH_MAX];
char *filename = (char *)(fsrpc + 1);
int flags;
int ret = -1; /* Corresponds to the error value for access */
size_t filesize = tee_fs_get_absolute_filename(filename, abs_filename,
sizeof(abs_filename));
if (filesize) {
flags = tee_fs_conv_accessflags(fsrpc->flags);
ret = access(abs_filename, flags);
}
return ret;
}
int tee_supp_fs_init(void)
{
struct stat st;
mkdir(TEE_FS_SUBPATH, 0700);
mkdir(TEE_FS_PATH, 0700);
if (stat(TEE_FS_PATH, &st) != 0)
return -1;
return 0;
}
int tee_supp_fs_process(void *cmd, size_t cmd_size)
{
struct tee_fs_rpc *fsrpc = cmd;
int ret = -1;
if (cmd_size < sizeof(struct tee_fs_rpc))
return ret;
if (cmd == NULL)
return ret;
switch (fsrpc->op) {
case TEE_FS_OPEN:
ret = tee_fs_open(fsrpc);
break;
case TEE_FS_CLOSE:
ret = tee_fs_close(fsrpc);
break;
case TEE_FS_READ:
ret = tee_fs_read(fsrpc);
break;
case TEE_FS_WRITE:
ret = tee_fs_write(fsrpc);
break;
case TEE_FS_SEEK:
ret = tee_fs_seek(fsrpc);
break;
case TEE_FS_UNLINK:
ret = tee_fs_unlink(fsrpc);
break;
case TEE_FS_RENAME:
ret = tee_fs_rename(fsrpc);
break;
case TEE_FS_TRUNC:
ret = tee_fs_truncate(fsrpc);
break;
case TEE_FS_MKDIR:
ret = tee_fs_mkdir(fsrpc);
break;
case TEE_FS_OPENDIR:
ret = tee_fs_opendir(fsrpc);
break;
case TEE_FS_CLOSEDIR:
ret = tee_fs_closedir(fsrpc);
break;
case TEE_FS_READDIR:
ret = tee_fs_readdir(fsrpc);
break;
case TEE_FS_RMDIR:
ret = tee_fs_rmdir(fsrpc);
break;
case TEE_FS_ACCESS:
ret = tee_fs_access(fsrpc);
break;
case TEE_FS_LINK:
ret = tee_fs_link(fsrpc);
default:
break;
}
fsrpc->res = ret;
return ret;
}

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2014, STMicroelectronics International N.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 TEE_SUPP_FS_H
#define TEE_SUPP_FS_H
#include <stddef.h>
int tee_supp_fs_init(void);
int tee_supp_fs_process(void *cmd, size_t cmd_size);
#endif

View file

@ -0,0 +1,487 @@
/*
* Copyright (c) 2014, STMicroelectronics International N.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <sys/queue.h>
#include <unistd.h>
#include <teec_trace.h>
#include <teec_rpc.h>
#include <teec_ta_load.h>
#include <tee_supp_fs.h>
#include <teec.h>
#include <cutils/log.h>
#define TEE_RPC_BUFFER_NUMBER 5
/* Flags of the shared memory. Also defined in tee_service.h in the kernel. */
/*
* Maximum size of the device name
*/
#define TEEC_MAX_DEVNAME_SIZE 256
char devname1[TEEC_MAX_DEVNAME_SIZE];
char devname2[TEEC_MAX_DEVNAME_SIZE];
struct tee_rpc_cmd {
union {
void *buffer;
uint64_t padding_buf;
};
uint32_t size;
uint32_t type;
int fd;
int reserved;
};
struct tee_rpc_invoke {
uint32_t cmd;
uint32_t res;
uint32_t nbr_bf;
uint32_t reserved;
struct tee_rpc_cmd cmds[TEE_RPC_BUFFER_NUMBER];
};
struct tee_rpc_ta {
TEEC_UUID uuid;
uint32_t supp_ta_handle;
};
static int read_request(int fd, struct tee_rpc_invoke *request);
static void write_response(int fd, struct tee_rpc_invoke *request);
static void free_param(TEEC_SharedMemory *shared_mem);
struct share_mem_entry {
TEEC_SharedMemory shared_mem;
TAILQ_ENTRY(share_mem_entry) link;
};
static TAILQ_HEAD(, share_mem_entry) shared_memory_list =
TAILQ_HEAD_INITIALIZER(shared_memory_list);
static void free_all_shared_memory(void)
{
struct share_mem_entry *entry;
DMSG(">");
while (!TAILQ_EMPTY(&shared_memory_list)) {
entry = TAILQ_FIRST(&shared_memory_list);
TAILQ_REMOVE(&shared_memory_list, entry, link);
free_param(&entry->shared_mem);
free(entry);
}
DMSG("<");
}
static void free_shared_memory(int fd)
{
struct share_mem_entry *entry;
TAILQ_FOREACH(entry, &shared_memory_list, link)
if (entry->shared_mem.d.fd == fd)
break;
if (!entry) {
EMSG("Cannot find fd=%d\n", fd);
return;
}
free_param(&entry->shared_mem);
TAILQ_REMOVE(&shared_memory_list, entry, link);
free(entry);
}
static TEEC_SharedMemory *add_shared_memory(int fd, size_t size)
{
struct tee_shm_io shm;
TEEC_SharedMemory *shared_mem;
struct share_mem_entry *entry;
entry = calloc(1, sizeof(struct share_mem_entry));
if (!entry)
return NULL;
shared_mem = &entry->shared_mem;
memset((void *)&shm, 0, sizeof(shm));
shm.buffer = NULL;
shm.size = size;
shm.registered = 0;
shm.fd_shm = 0;
shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
if (ioctl(fd, TEE_ALLOC_SHM_IOC, &shm) != 0) {
EMSG("Ioctl(TEE_ALLOC_SHM_IOC) failed! (%s)", strerror(errno));
shared_mem = NULL;
goto out;
}
shared_mem->size = size;
shared_mem->d.fd = shm.fd_shm;
shared_mem->buffer = mmap(NULL, size,
PROT_READ | PROT_WRITE, MAP_SHARED,
shared_mem->d.fd, 0);
if (shared_mem->buffer == (void *)MAP_FAILED) {
EMSG("mmap(%zu) failed - Error = %s", size, strerror(errno));
close(shared_mem->d.fd);
shared_mem = NULL;
goto out;
}
TAILQ_INSERT_TAIL(&shared_memory_list, entry, link);
out:
if (!shared_mem)
free(entry);
return shared_mem;
}
/* Get parameter allocated by secure world */
static int get_param(int fd, struct tee_rpc_invoke *inv, const uint32_t idx,
TEEC_SharedMemory *shared_mem)
{
struct tee_shm_io shm;
if (idx >= inv->nbr_bf)
return -1;
memset((void *)&shm, 0, sizeof(shm));
shm.buffer = inv->cmds[idx].buffer;
shm.size = inv->cmds[idx].size;
shm.registered = 0;
shm.fd_shm = 0;
shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
if (ioctl(fd, TEE_GET_FD_FOR_RPC_SHM_IOC, &shm) != 0) {
EMSG("Ioctl(TEE_ALLOC_SHM_IOC) failed! (%s)", strerror(errno));
return -1;
}
memset(shared_mem, 0, sizeof(TEEC_SharedMemory));
shared_mem->size = shm.size;
shared_mem->flags = shm.flags;
shared_mem->d.fd = shm.fd_shm;
DMSG("size %u fd_shm %d", (int)shared_mem->size, shared_mem->d.fd);
shared_mem->buffer = mmap(NULL, shared_mem->size,
PROT_READ | PROT_WRITE, MAP_SHARED,
shared_mem->d.fd, 0);
if (shared_mem->buffer == (void *)MAP_FAILED) {
dprintf(TRACE_ERROR, "mmap(%d, %p) failed - Error = %s\n",
inv->cmds[idx].size, inv->cmds[idx].buffer,
strerror(errno));
close(shared_mem->d.fd);
return -1;
}
/* Erase value, since we don't want to send back input memory to TEE. */
inv->cmds[idx].buffer = 0;
return 0;
}
/* Allocate new parameter to be used in RPC communication */
static TEEC_SharedMemory *alloc_param(int fd, struct tee_rpc_invoke *inv,
const uint32_t idx, size_t size)
{
TEEC_SharedMemory *shared_mem;
if (idx >= inv->nbr_bf) {
EMSG("idx %d >= inv->nbr_bf %d", idx, inv->nbr_bf);
return NULL;
}
if (inv->cmds[idx].buffer != NULL) {
EMSG("cmd[idx].buffer != NULL");
return NULL;
}
shared_mem = add_shared_memory(fd, size);
if (shared_mem == 0) {
EMSG("add_shared_memory() returned NULL");
return NULL;
}
inv->cmds[idx].buffer = shared_mem->buffer;
inv->cmds[idx].size = size;
inv->cmds[idx].type = TEE_RPC_BUFFER;
inv->cmds[idx].fd = shared_mem->d.fd;
return shared_mem;
}
/* Release parameter recieved from get_param or alloc_param */
static void free_param(TEEC_SharedMemory *shared_mem)
{
INMSG("%p %u (%p)", shared_mem->buffer,
(int)shared_mem->size, shared_mem);
if (munmap(shared_mem->buffer, shared_mem->size) != 0)
EMSG("munmap(%p, %u) failed - Error = %s",
shared_mem->buffer, (int)shared_mem->size,
strerror(errno));
close(shared_mem->d.fd);
OUTMSG();
}
static void process_fs(int fd, struct tee_rpc_invoke *inv)
{
TEEC_SharedMemory shared_mem;
INMSG();
if (get_param(fd, inv, 0, &shared_mem)) {
inv->res = TEEC_ERROR_BAD_PARAMETERS;
return;
}
tee_supp_fs_process(shared_mem.buffer, shared_mem.size);
inv->res = TEEC_SUCCESS;;
free_param(&shared_mem);
OUTMSG();
}
static void load_ta(int fd, struct tee_rpc_invoke *inv)
{
void *ta = NULL;
int ta_found = 0;
size_t size = 0;
struct tee_rpc_ta *cmd;
TEEC_SharedMemory shared_mem;
INMSG();
if (get_param(fd, inv, 0, &shared_mem)) {
inv->res = TEEC_ERROR_BAD_PARAMETERS;
return;
}
cmd = (struct tee_rpc_ta *)shared_mem.buffer;
ta_found = TEECI_LoadSecureModule(NULL, &cmd->uuid, &ta, &size);
/* Tracked by 6408 */
if (ta_found != TA_BINARY_FOUND)
ta_found = TEECI_LoadSecureModule(devname2, &cmd->uuid, &ta, &size);
if (ta_found != TA_BINARY_FOUND)
ta_found = TEECI_LoadSecureModule_ext(&cmd->uuid, &ta, &size);
if (ta_found == TA_BINARY_FOUND) {
TEEC_SharedMemory *ta_shm = alloc_param(fd, inv, 1, size);
if (!ta_shm) {
inv->res = TEEC_ERROR_OUT_OF_MEMORY;
} else {
inv->res = TEEC_SUCCESS;
memcpy(ta_shm->buffer, ta, size);
/* Fd will come back from TEE for unload. */
cmd->supp_ta_handle = ta_shm->d.fd;
}
free(ta);
} else {
EMSG(" TA not found");
inv->res = TEEC_ERROR_ITEM_NOT_FOUND;
}
free_param(&shared_mem);
OUTMSG();
}
static void free_ta(struct tee_rpc_invoke *inv)
{
INMSG();
free_shared_memory(inv->cmds[0].fd);
inv->nbr_bf = 0;
inv->res = TEEC_SUCCESS;
OUTMSG();
}
static void get_ree_time(int fd, struct tee_rpc_invoke *inv)
{
struct TEE_Time {
uint32_t seconds;
uint32_t millis;
};
struct timeval tv;
TEEC_SharedMemory shared_mem;
struct TEE_Time *tee_time;
INMSG();
if (get_param(fd, inv, 0, &shared_mem)) {
inv->res = TEEC_ERROR_BAD_PARAMETERS;
return;
}
tee_time = (struct TEE_Time *)shared_mem.buffer;
gettimeofday(&tv, NULL);
tee_time->seconds = tv.tv_sec;
tee_time->millis = tv.tv_usec / 1000;
DMSG("%ds:%dms", tee_time->seconds, tee_time->millis);
inv->res = TEEC_SUCCESS;
/* Unmap the memory. */
free_param(&shared_mem);
OUTMSG();
}
int main(int argc, char *argv[])
{
int fd;
int n = 0;
char devpath[TEEC_MAX_DEVNAME_SIZE];
struct tee_rpc_invoke request;
int ret;
sprintf(devpath, "/dev/opteearmtz00");
sprintf(devname1, "optee_armtz");
sprintf(devname2, "teetz");
while (--argc) {
n++;
if (strncmp(argv[n], "opteearmtz00", 12) == 0) {
snprintf(devpath, TEEC_MAX_DEVNAME_SIZE, "%s", "/dev/opteearmtz00");
snprintf(devname1, TEEC_MAX_DEVNAME_SIZE, "%s", "optee_armtz");
snprintf(devname2, TEEC_MAX_DEVNAME_SIZE, "%s", "teetz");
} else {
EMSG("Invalid argument #%d", n);
exit(EXIT_FAILURE);
}
}
fd = open(devpath, O_RDWR);
if (fd < 0) {
EMSG("error opening [%s]", devpath);
exit(EXIT_FAILURE);
}
if (tee_supp_fs_init() != 0) {
EMSG("error tee_supp_fs_init");
exit(EXIT_FAILURE);
}
IMSG("tee-supplicant running on %s", devpath);
/* major failure on read kills supplicant, malformed data will not */
do {
DMSG("looping");
ret = read_request(fd, &request);
if (ret == 0) {
switch (request.cmd) {
case TEE_RPC_LOAD_TA:
load_ta(fd, &request);
break;
case TEE_RPC_FREE_TA:
free_ta(&request);
break;
case TEE_RPC_GET_TIME:
get_ree_time(fd, &request);
break;
case TEE_RPC_FS:
process_fs(fd, &request);
break;
default:
EMSG("Cmd [0x%" PRIx32 "] not supported",
request.cmd);
/* Not supported. */
break;
}
write_response(fd, &request);
}
} while (ret >= 0);
free_all_shared_memory();
close(fd);
return EXIT_SUCCESS;
}
static int read_request(int fd, struct tee_rpc_invoke *request)
{
ssize_t res = 0;
if (fd < 0) {
EMSG("invalid fd");
return -1;
}
res = read(fd, request, sizeof(*request));
if (res < 0)
return -1;
if ((size_t)res < sizeof(*request) - sizeof(request->cmds)) {
EMSG("error reading from driver");
return 1;
}
if (sizeof(*request) - sizeof(request->cmds) +
sizeof(request->cmds[0]) * request->nbr_bf != (size_t)res) {
DMSG("length read does not equal expected length");
return 1;
}
return 0;
}
static void write_response(int fd, struct tee_rpc_invoke *request)
{
size_t writesize;
size_t res;
if (fd < 0) {
EMSG("invalid fd");
return;
}
writesize = sizeof(*request) - sizeof(request->cmds) +
sizeof(request->cmds[0]) * request->nbr_bf;
res = write(fd, request, writesize);
if (res != writesize)
EMSG("error writing to device (%zu)", res);
}

View file

@ -0,0 +1,39 @@
/*
* Copyright (c) 2014, STMicroelectronics International N.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 TEEC_RPC_H
#define TEEC_RPC_H
#define TEE_RPC_LOAD_TA 0x10000001
#define TEE_RPC_FREE_TA 0x10000009
#define TEE_RPC_RPMB_CMD 0x1000000A
#define TEE_RPC_FS 0x10000010
#define TEE_RPC_GET_TIME 0x10000011
#define TEE_RPC_BUFFER 0x00000001
#define TEE_RPC_VALUE 0x00000002
#endif

View file

@ -0,0 +1,232 @@
/*
* Copyright (c) 2014, STMicroelectronics International N.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <dirent.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <teec_trace.h>
#include <teec_ta_load.h>
#include <cutils/log.h>
#include <errno.h>
#ifndef TEEC_LOAD_PATH
#define TEEC_LOAD_PATH "/lib"
#endif
#ifndef PATH_MAX
#define PATH_MAX 255
#endif
struct tee_rpc_cmd {
void *buffer;
uint32_t size;
uint32_t type;
int fd;
};
/*
* Based on the uuid this function will try to find a TA-binary on the
* filesystem and return it back to the caller in the parameter ta.
*
* @param: destination The uuid of the TA we are searching for.
* @param: ta A pointer which this function will allocate and copy
* the TA from the filesystem to the pointer itself. It is
* the callers responsibility to free the pointer.
* @param: ta_size The size of the TA found on file system. It will be 0
* if no TA was not found.
*
* @return 0 if TA was found, otherwise -1.
*/
int TEECI_LoadSecureModule(const char* dev_path,
const TEEC_UUID *destination, void **ta,
size_t *ta_size)
{
char fname[PATH_MAX];
FILE *file = NULL;
int n;
if (!ta_size || !ta || !destination) {
printf("wrong inparameter to TEECI_LoadSecureModule\n");
return TA_BINARY_NOT_FOUND;
}
if(dev_path != NULL){
n = snprintf(fname, PATH_MAX,
"%s/%s/%08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x.ta",
TEEC_LOAD_PATH, dev_path,
destination->timeLow,
destination->timeMid,
destination->timeHiAndVersion,
destination->clockSeqAndNode[0],
destination->clockSeqAndNode[1],
destination->clockSeqAndNode[2],
destination->clockSeqAndNode[3],
destination->clockSeqAndNode[4],
destination->clockSeqAndNode[5],
destination->clockSeqAndNode[6],
destination->clockSeqAndNode[7]);
}
else{
n = snprintf(fname, PATH_MAX,
"%s/%08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x.ta",
"/system/bin",
destination->timeLow,
destination->timeMid,
destination->timeHiAndVersion,
destination->clockSeqAndNode[0],
destination->clockSeqAndNode[1],
destination->clockSeqAndNode[2],
destination->clockSeqAndNode[3],
destination->clockSeqAndNode[4],
destination->clockSeqAndNode[5],
destination->clockSeqAndNode[6],
destination->clockSeqAndNode[7]);
}
DMSG("Attempt to load %s\n", fname);
ALOGE("Attempt to load %s\n", fname);
if ((n < 0) || (n >= PATH_MAX)) {
EMSG("wrong TA path [%s]", fname);
return TA_BINARY_NOT_FOUND;
}
file = fopen(fname, "r");
if (file == NULL) {
DMSG("failed to open the ta %s TA-file", fname);
return TA_BINARY_NOT_FOUND;
}
if (fseek(file, 0, SEEK_END) != 0) {
fclose(file);
return TA_BINARY_NOT_FOUND;
}
*ta_size = ftell(file);
if (fseek(file, 0, SEEK_SET) != 0) {
fclose(file);
return TA_BINARY_NOT_FOUND;
}
*ta = malloc(*ta_size);
if (*ta == NULL) {
printf("OOM: failed allocating ta\n");
fclose(file);
return TA_BINARY_NOT_FOUND;
}
if (*ta_size != fread(*ta, 1, *ta_size, file)) {
printf("error fread TA file\n");
free(*ta);
fclose(file);
return TA_BINARY_NOT_FOUND;
}
fclose(file);
return TA_BINARY_FOUND;
}
int TEECI_LoadSecureModule_ext(
const TEEC_UUID *destination, void **ta,
size_t *ta_size)
{
char fname[PATH_MAX];
FILE *file = NULL;
int n;
if (!ta_size || !ta || !destination) {
ALOGE("wrong inparameter to TEECI_LoadSecureModule\n");
return TA_BINARY_NOT_FOUND;
}
n = snprintf(fname, PATH_MAX,
"%08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x.ta",
destination->timeLow,
destination->timeMid,
destination->timeHiAndVersion,
destination->clockSeqAndNode[0],
destination->clockSeqAndNode[1],
destination->clockSeqAndNode[2],
destination->clockSeqAndNode[3],
destination->clockSeqAndNode[4],
destination->clockSeqAndNode[5],
destination->clockSeqAndNode[6],
destination->clockSeqAndNode[7]);
DMSG("Attempt to load %s\n", fname);
ALOGW("Attempt to load %s\n", fname);
if ((n < 0) || (n >= PATH_MAX)) {
ALOGE("wrong TA path [%s]", fname);
return TA_BINARY_NOT_FOUND;
}
file = fopen(fname, "r");
if (file == NULL) {
ALOGE("failed to open the ta %s TA-file, errno=%d", fname, errno);
return TA_BINARY_NOT_FOUND;
}
ALOGW("%s %d\n", __FILE__, __LINE__);
if (fseek(file, 0, SEEK_END) != 0) {
fclose(file);
return TA_BINARY_NOT_FOUND;
}
ALOGW("%s %d\n", __FILE__, __LINE__);
*ta_size = ftell(file);
//makesure the size not 8byte align
ALOGW("%s %d\n", __FILE__, __LINE__);
if (fseek(file, 0, SEEK_SET) != 0) {
fclose(file);
return TA_BINARY_NOT_FOUND;
}
ALOGW("%s %d\n", __FILE__, __LINE__);
*ta = malloc(*ta_size);
if (*ta == NULL) {
printf("OOM: failed allocating ta\n");
fclose(file);
return TA_BINARY_NOT_FOUND;
}
ALOGW("%s %d\n", __FILE__, __LINE__);
if (*ta_size != fread(*ta, 1, *ta_size, file)) {
printf("error fread TA file\n");
free(*ta);
fclose(file);
return TA_BINARY_NOT_FOUND;
}
fclose(file);
ALOGW("%s %d\n", __FILE__, __LINE__);
return TA_BINARY_FOUND;
}

View file

@ -0,0 +1,55 @@
/*
* Copyright (c) 2014, STMicroelectronics International N.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 _TEEC_TA_LOAD_H
#define _TEEC_TA_LOAD_H
#include <tee_client_api.h>
#define TA_BINARY_FOUND 0
#define TA_BINARY_NOT_FOUND -1
/**
* Based on the uuid this function will try to find a TA-binary on the
* filesystem and return it back to the caller in the parameter ta.
*
* @param: destination The uuid of the TA we are searching for.
* @param: ta A pointer which this function will allocate and copy
* the TA from the filesystem to the pointer itself. It is
* the callers responsibility to free the pointer.
* @param: ta_size The size of the TA found on file system. It will be 0
* if no TA was not found.
*
* @return 0 if TA was found, otherwise -1.
*/
int TEECI_LoadSecureModule(const char *name,
const TEEC_UUID *destination, void **ta,
size_t *ta_size);
int TEECI_LoadSecureModule_ext(
const TEEC_UUID *destination, void **ta,
size_t *ta_size);
#endif

View file

@ -1,2 +1,7 @@
LOCAL_PATH:= $(call my-dir)
include $(LOCAL_PATH)/widevine_L$(BOARD_WIDEVINE_OEMCRYPTO_LEVEL)/Android.mk
ifeq ($(SECURE_OS_OPTEE), yes)
include $(LOCAL_PATH)/adapt_optee/widevine_L$(BOARD_WIDEVINE_OEMCRYPTO_LEVEL)/Android.mk
else
include $(LOCAL_PATH)/adapt_semelis/widevine_L$(BOARD_WIDEVINE_OEMCRYPTO_LEVEL)/Android.mk
endif

View file

@ -38,7 +38,6 @@ LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
LOCAL_PROPRIETARY_MODULE := true
#LOCAL_STRIP_MODULE := true
LOCAL_MULTILIB := 32
LOCAL_MODULE_TAGS := optional
include $(BUILD_PREBUILT)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -3,7 +3,6 @@ LOCAL_PATH:= $(call my-dir)
##################################################
include $(CLEAR_VARS)
ifeq ($(TARGET_ARCH),arm)
LOCAL_MODULE := com.google.widevine.software.drm.xml
LOCAL_SRC_FILES := $(LOCAL_MODULE)
@ -39,7 +38,7 @@ LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
LOCAL_PROPRIETARY_MODULE := true
#LOCAL_STRIP_MODULE := true
LOCAL_MULTILIB := 32
LOCAL_MODULE_TAGS := optional
include $(BUILD_PREBUILT)
@ -52,10 +51,36 @@ LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
LOCAL_PROPRIETARY_MODULE := true
#LOCAL_STRIP_MODULE := true
LOCAL_MULTILIB := 32
LOCAL_MODULE_TAGS := optional
include $(BUILD_PREBUILT)
#####################################################################
#libdrmdecrypt.so
include $(CLEAR_VARS)
LOCAL_MODULE := libdrmdecrypt
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
LOCAL_PROPRIETARY_MODULE := true
#LOCAL_STRIP_MODULE := true
LOCAL_MODULE_TAGS := optional
LOCAL_MULTILIB := 32
include $(BUILD_PREBUILT)
#####################################################################
#libwvm.so
include $(CLEAR_VARS)
LOCAL_MODULE := libwvm
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
LOCAL_PROPRIETARY_MODULE := true
#LOCAL_STRIP_MODULE := true
LOCAL_MODULE_TAGS := optional
LOCAL_MULTILIB := 32
include $(BUILD_PREBUILT)
#####################################################################
#libwvdrmengine.so
include $(CLEAR_VARS)
@ -65,105 +90,30 @@ LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
LOCAL_PROPRIETARY_MODULE := true
#LOCAL_STRIP_MODULE := true
LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_SHARED_LIBRARIES)/mediadrm
#LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_SHARED_LIBRARIES)/mediadrm
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_RELATIVE_PATH := mediadrm
LOCAL_MODULE_TAGS := optional
LOCAL_MULTILIB := 32
include $(BUILD_PREBUILT)
#####################################################################
# liboemcrypto.a, lib1
#libdrmwvmplugin.so
include $(CLEAR_VARS)
LOCAL_PREBUILT_LIBS := \
liboemcrypto.a \
libdrmwvmcommon.a \
libwvmcommon.a \
libwvocs_L$(BOARD_WIDEVINE_OEMCRYPTO_LEVEL).a \
libwvdecryptcommon.a
LOCAL_MODULE_TAGS := optional
include $(BUILD_MULTI_PREBUILT)
#####################################################################
# libdrmwvmplugin.so
include $(CLEAR_VARS)
LOCAL_WHOLE_STATIC_LIBRARIES := \
libdrmframeworkcommon \
libdrmwvmcommon \
libwvocs_L$(BOARD_WIDEVINE_OEMCRYPTO_LEVEL)
LOCAL_SHARED_LIBRARIES := \
libbinder \
libutils \
libcutils \
libstlport \
libz \
libwvdrm_L$(BOARD_WIDEVINE_OEMCRYPTO_LEVEL) \
libWVStreamControlAPI_L$(BOARD_WIDEVINE_OEMCRYPTO_LEVEL) \
libdl
ifeq ($(BOARD_WIDEVINE_OEMCRYPTO_LEVEL),1)
LOCAL_SHARED_LIBRARIES += \
libtee_client
endif
LOCAL_MODULE := libdrmwvmplugin
LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_SHARED_LIBRARIES)/drm
LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_LIBRARIES += liboemcrypto
LOCAL_PRELINK_MODULE := false
include $(BUILD_SHARED_LIBRARY)
#####################################################################
# libwvm.so
include $(CLEAR_VARS)
LOCAL_WHOLE_STATIC_LIBRARIES := \
libwvmcommon
LOCAL_SHARED_LIBRARIES := \
libstlport \
libstagefright \
libWVStreamControlAPI_L$(BOARD_WIDEVINE_OEMCRYPTO_LEVEL) \
libdrmframework \
libcutils \
liblog \
libutils
ifeq ($(BOARD_WIDEVINE_OEMCRYPTO_LEVEL),1)
LOCAL_SHARED_LIBRARIES += \
libtee_client
endif
LOCAL_MODULE := libwvm
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_LIBRARIES += liboemcrypto
LOCAL_PRELINK_MODULE := false
include $(BUILD_SHARED_LIBRARY)
#####################################################################
#libdrmdecrypt.so
include $(CLEAR_VARS)
LOCAL_WHOLE_STATIC_LIBRARIES := \
libwvdecryptcommon
LOCAL_SHARED_LIBRARIES := \
libstagefright_foundation \
liblog \
libcutils \
libcrypto
ifeq ($(BOARD_WIDEVINE_OEMCRYPTO_LEVEL),1)
LOCAL_SHARED_LIBRARIES += \
libtee_client
endif
LOCAL_MODULE := libdrmdecrypt
#LOCAL_STRIP_MODULE := true
#LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_SHARED_LIBRARIES)/drm
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_RELATIVE_PATH := drm
LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_LIBRARIES += liboemcrypto
LOCAL_PRELINK_MODULE := false
LOCAL_MULTILIB := 32
include $(BUILD_PREBUILT)
include $(BUILD_SHARED_LIBRARY)
#####################################################################
#liboemcrypto.so
@ -176,7 +126,7 @@ LOCAL_SRC_FILES := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
#LOCAL_PROPRIETARY_MODULE copies library to vendor/lib
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_TAGS := optional
LOCAL_MULTILIB := 32
include $(BUILD_PREBUILT)
endif# liboemcrypto
endif

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,132 @@
WIDEVINE_SUPPORTED_ARCH := arm x86
LOCAL_PATH:= $(call my-dir)
##################################################
include $(CLEAR_VARS)
LOCAL_MODULE := com.google.widevine.software.drm.xml
LOCAL_SRC_FILES := $(LOCAL_MODULE)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := ETC
# This will install the file in /system/etc/permissions
#
LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/permissions
include $(BUILD_PREBUILT)
########################
# Dummy library used to indicate availability of widevine drm
include $(CLEAR_VARS)
LOCAL_MODULE := com.google.widevine.software.drm
LOCAL_MODULE_SUFFIX := .jar
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
include $(BUILD_PREBUILT)
#####################################################################
#libWVStreamControlAPI_LX.so
include $(CLEAR_VARS)
LOCAL_MODULE := libWVStreamControlAPI_L$(BOARD_WIDEVINE_OEMCRYPTO_LEVEL)
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
LOCAL_PROPRIETARY_MODULE := true
#LOCAL_STRIP_MODULE := true
LOCAL_MULTILIB := 32
LOCAL_MODULE_TAGS := optional
include $(BUILD_PREBUILT)
#####################################################################
#libwvdrm_LX.so
include $(CLEAR_VARS)
LOCAL_MODULE := libwvdrm_L$(BOARD_WIDEVINE_OEMCRYPTO_LEVEL)
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
LOCAL_PROPRIETARY_MODULE := true
#LOCAL_STRIP_MODULE := true
LOCAL_MULTILIB := 32
LOCAL_MODULE_TAGS := optional
include $(BUILD_PREBUILT)
#####################################################################
#libdrmdecrypt.so
include $(CLEAR_VARS)
LOCAL_MODULE := libdrmdecrypt
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
LOCAL_PROPRIETARY_MODULE := true
#LOCAL_STRIP_MODULE := true
LOCAL_MODULE_TAGS := optional
LOCAL_MULTILIB := 32
include $(BUILD_PREBUILT)
#####################################################################
#libwvm.so
include $(CLEAR_VARS)
LOCAL_MODULE := libwvm
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
LOCAL_PROPRIETARY_MODULE := true
#LOCAL_STRIP_MODULE := true
LOCAL_MODULE_TAGS := optional
LOCAL_MULTILIB := 32
include $(BUILD_PREBUILT)
#####################################################################
#libwvdrmengine.so
include $(CLEAR_VARS)
LOCAL_MODULE := libwvdrmengine
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
LOCAL_PROPRIETARY_MODULE := true
#LOCAL_STRIP_MODULE := true
#LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_SHARED_LIBRARIES)/mediadrm
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_RELATIVE_PATH := mediadrm
LOCAL_MODULE_TAGS := optional
LOCAL_MULTILIB := 32
include $(BUILD_PREBUILT)
#####################################################################
#libdrmwvmplugin.so
include $(CLEAR_VARS)
LOCAL_MODULE := libdrmwvmplugin
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
LOCAL_PROPRIETARY_MODULE := true
#LOCAL_STRIP_MODULE := true
#LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_SHARED_LIBRARIES)/drm
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_RELATIVE_PATH := drm
LOCAL_MODULE_TAGS := optional
LOCAL_MULTILIB := 32
include $(BUILD_PREBUILT)
#####################################################################
#liboemcrypto.so
ifeq ($(BOARD_WIDEVINE_OEMCRYPTO_LEVEL),1)
include $(CLEAR_VARS)
LOCAL_MODULE := liboemcrypto
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
#LOCAL_PROPRIETARY_MODULE copies library to vendor/lib
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_TAGS := optional
LOCAL_MULTILIB := 32
include $(BUILD_PREBUILT)
endif# liboemcrypto

View file

@ -0,0 +1,53 @@
# 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.
#
# If you don't need to do a full clean build but would like to touch
# a file or delete some intermediate files, add a clean step to the end
# of the list. These steps will only be run once, if they haven't been
# run before.
#
# E.g.:
# $(call add-clean-step, touch -c external/sqlite/sqlite3.h)
# $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates)
#
# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with
# files that are missing or have been moved.
#
# Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory.
# Use $(OUT_DIR) to refer to the "out" directory.
#
# If you need to re-do something that's already mentioned, just copy
# the command and add it to the bottom of the list. E.g., if a change
# that you made last week required touching a file and a change you
# made today requires touching the same file, just copy the old
# touch step and add it to the end of the list.
#
# ************************************************
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
# ************************************************
# For example:
#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates)
#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates)
#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f)
#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib/drm $(PRODUCT_OUT)/system/lib/libwv* $(PRODUCT_OUT)/system/lib/libWV*)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/cdm_protos_intermediates)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libcdm_intermediates)
# ************************************************
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
# ************************************************

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2011 Google, Inc. All Rights Reserved
-->
<permissions>
<library name="com.google.widevine.software.drm"
file="/system/framework/com.google.widevine.software.drm.jar"/>
</permissions>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,132 @@
WIDEVINE_SUPPORTED_ARCH := arm x86
LOCAL_PATH:= $(call my-dir)
##################################################
include $(CLEAR_VARS)
LOCAL_MODULE := com.google.widevine.software.drm.xml
LOCAL_SRC_FILES := $(LOCAL_MODULE)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := ETC
# This will install the file in /system/etc/permissions
#
LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/permissions
include $(BUILD_PREBUILT)
########################
# Dummy library used to indicate availability of widevine drm
include $(CLEAR_VARS)
LOCAL_MODULE := com.google.widevine.software.drm
LOCAL_MODULE_SUFFIX := .jar
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
include $(BUILD_PREBUILT)
#####################################################################
#libWVStreamControlAPI_LX.so
include $(CLEAR_VARS)
LOCAL_MODULE := libWVStreamControlAPI_L$(BOARD_WIDEVINE_OEMCRYPTO_LEVEL)
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
LOCAL_PROPRIETARY_MODULE := true
#LOCAL_STRIP_MODULE := true
LOCAL_MULTILIB := 32
LOCAL_MODULE_TAGS := optional
include $(BUILD_PREBUILT)
#####################################################################
#libwvdrm_LX.so
include $(CLEAR_VARS)
LOCAL_MODULE := libwvdrm_L$(BOARD_WIDEVINE_OEMCRYPTO_LEVEL)
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
LOCAL_PROPRIETARY_MODULE := true
#LOCAL_STRIP_MODULE := true
LOCAL_MULTILIB := 32
LOCAL_MODULE_TAGS := optional
include $(BUILD_PREBUILT)
#####################################################################
#libdrmdecrypt.so
include $(CLEAR_VARS)
LOCAL_MODULE := libdrmdecrypt
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
LOCAL_PROPRIETARY_MODULE := true
#LOCAL_STRIP_MODULE := true
LOCAL_MODULE_TAGS := optional
LOCAL_MULTILIB := 32
include $(BUILD_PREBUILT)
#####################################################################
#libwvm.so
include $(CLEAR_VARS)
LOCAL_MODULE := libwvm
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
LOCAL_PROPRIETARY_MODULE := true
#LOCAL_STRIP_MODULE := true
LOCAL_MODULE_TAGS := optional
LOCAL_MULTILIB := 32
include $(BUILD_PREBUILT)
#####################################################################
#libwvdrmengine.so
include $(CLEAR_VARS)
LOCAL_MODULE := libwvdrmengine
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
LOCAL_PROPRIETARY_MODULE := true
#LOCAL_STRIP_MODULE := true
#LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_SHARED_LIBRARIES)/mediadrm
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_RELATIVE_PATH := mediadrm
LOCAL_MODULE_TAGS := optional
LOCAL_MULTILIB := 32
include $(BUILD_PREBUILT)
#####################################################################
#libdrmwvmplugin.so
include $(CLEAR_VARS)
LOCAL_MODULE := libdrmwvmplugin
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
LOCAL_PROPRIETARY_MODULE := true
#LOCAL_STRIP_MODULE := true
#LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_SHARED_LIBRARIES)/drm
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_RELATIVE_PATH := drm
LOCAL_MODULE_TAGS := optional
LOCAL_MULTILIB := 32
include $(BUILD_PREBUILT)
#####################################################################
#liboemcrypto.so
ifeq ($(BOARD_WIDEVINE_OEMCRYPTO_LEVEL),1)
include $(CLEAR_VARS)
LOCAL_MODULE := liboemcrypto
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
#LOCAL_PROPRIETARY_MODULE copies library to vendor/lib
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_TAGS := optional
LOCAL_MULTILIB := 32
include $(BUILD_PREBUILT)
endif# liboemcrypto

View file

@ -0,0 +1,53 @@
# 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.
#
# If you don't need to do a full clean build but would like to touch
# a file or delete some intermediate files, add a clean step to the end
# of the list. These steps will only be run once, if they haven't been
# run before.
#
# E.g.:
# $(call add-clean-step, touch -c external/sqlite/sqlite3.h)
# $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates)
#
# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with
# files that are missing or have been moved.
#
# Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory.
# Use $(OUT_DIR) to refer to the "out" directory.
#
# If you need to re-do something that's already mentioned, just copy
# the command and add it to the bottom of the list. E.g., if a change
# that you made last week required touching a file and a change you
# made today requires touching the same file, just copy the old
# touch step and add it to the end of the list.
#
# ************************************************
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
# ************************************************
# For example:
#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates)
#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates)
#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f)
#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib/drm $(PRODUCT_OUT)/system/lib/libwv* $(PRODUCT_OUT)/system/lib/libWV*)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/cdm_protos_intermediates)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libcdm_intermediates)
# ************************************************
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
# ************************************************

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2011 Google, Inc. All Rights Reserved
-->
<permissions>
<library name="com.google.widevine.software.drm"
file="/system/framework/com.google.widevine.software.drm.jar"/>
</permissions>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show more