12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103 |
- /* SPDX-License-Identifier: GPL-2.0-only */
- /*
- * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
- */
- #include "smcinvoke_object.h"
- #include <include/linux/IClientEnv.h>
- #include <include/smci/uid/CAppClient.h>
- #include <include/smci/uid/CAppLoader.h>
- #include <include/smci/interface/IAppClient.h>
- #include <include/smci/interface/IAppController.h>
- #include <include/smci/interface/IAppLoader.h>
- #include <include/smci/interface/IOpener.h>
- #include "hdcp_main.h"
- #include "hdcp_smcinvoke.h"
- #include "hdcp1.h"
- #include "hdcp1_ops.h"
- #include "hdcp2p2.h"
- static int hdcp1_verify_key(struct hdcp1_smcinvoke_handle *handle)
- {
- int ret = 0;
- if (!handle) {
- pr_err("invalid HDCP 1.x handle\n");
- return -EINVAL;
- }
- if (!(handle->hdcp_state & HDCP_STATE_APP_LOADED)) {
- pr_err("%s app not loaded\n", HDCP1_APP_NAME);
- return -EINVAL;
- }
- ret = hdcp1_verify(handle->hdcp1_app_obj, 1);
- if (ret)
- pr_err("hdcp1_verify failed error:%d\n", ret);
- return ret;
- }
- static int hdcp1_key_set(struct hdcp1_smcinvoke_handle *handle,
- uint32_t *aksv_msb, uint32_t *aksv_lsb)
- {
- int ret = 0;
- uint8_t *ksvRes = NULL;
- size_t ksvResLen = 0;
- ksvRes = kzalloc(HDCP1_AKSV_SIZE, GFP_KERNEL);
- if (!ksvRes)
- return -EINVAL;
- if (aksv_msb == NULL || aksv_lsb == NULL) {
- pr_err("invalid aksv\n");
- return -EINVAL;
- }
- if (!handle) {
- pr_err("invalid HDCP 1.x handle\n");
- return -EINVAL;
- }
- if (!(handle->hdcp_state & HDCP_STATE_APP_LOADED)) {
- pr_err("hdcp1 app not loaded\n");
- return -EINVAL;
- }
- ret = hdcp1_set_key(handle->hdcp1_app_obj, ksvRes, HDCP1_AKSV_SIZE,
- &ksvResLen);
- if (ret) {
- pr_err("hdcp1_set_key failed ret=%d\n", ret);
- return -ENOKEY;
- }
- /* copy bytes into msb and lsb */
- *aksv_msb = ksvRes[0] << 24 | ksvRes[1] << 16 | ksvRes[2] << 8 | ksvRes[3];
- *aksv_lsb = ksvRes[4] << 24 | ksvRes[5] << 16 | ksvRes[6] << 8 | ksvRes[7];
- ret = hdcp1_validate_aksv(*aksv_msb, *aksv_lsb);
- if (ret)
- pr_err("aksv validation failed (%d)\n", ret);
- return ret;
- }
- int load_app(char *app_name, struct Object *app_obj,
- struct Object *app_controller_obj)
- {
- int ret = 0;
- uint8_t *buffer = NULL;
- struct qtee_shm shm = {0};
- size_t size = 0;
- struct Object client_env = {NULL, NULL};
- struct Object app_loader = {NULL, NULL};
- buffer = firmware_request_from_smcinvoke(app_name, &size, &shm);
- if (buffer == NULL) {
- pr_err("firmware_request_from_smcinvoke failed\n");
- return -EINVAL;
- }
- ret = get_client_env_object(&client_env);
- if (ret) {
- pr_err("get_client_env_object failed :%d\n", ret);
- client_env.invoke = NULL;
- client_env.context = NULL;
- goto error;
- }
- ret = IClientEnv_open(client_env, CAppLoader_UID, &app_loader);
- if (ret) {
- pr_err("IClientEnv_open failed :%d\n", ret);
- app_loader.invoke = NULL;
- app_loader.context = NULL;
- goto error;
- }
- ret = IAppLoader_loadFromBuffer(app_loader, (const void *)buffer, size,
- app_controller_obj);
- if (ret) {
- pr_err("IAppLoader_loadFromBuffer failed :%d\n", ret);
- app_controller_obj->invoke = NULL;
- app_controller_obj->context = NULL;
- goto error;
- }
- ret = IAppController_getAppObject(*app_controller_obj, app_obj);
- if (ret) {
- pr_err("IAppController_getAppObject failed :%d\n", ret);
- goto error;
- }
- error:
- qtee_shmbridge_free_shm(&shm);
- Object_ASSIGN_NULL(app_loader);
- Object_ASSIGN_NULL(client_env);
- return ret;
- }
- static int hdcp1_app_load(struct hdcp1_smcinvoke_handle *handle)
- {
- int ret = 0;
- if (!handle) {
- pr_err("invalid input\n");
- ret = -EINVAL;
- goto error;
- }
- if (handle->hdcp_state & HDCP_STATE_APP_LOADED)
- goto error;
- ret = load_app(HDCP1_APP_NAME, &(handle->hdcp1_app_obj),
- &(handle->hdcp1_appcontroller_obj));
- if (ret) {
- pr_err("hdcp1 TA load failed :%d\n", ret);
- goto error;
- }
- if (Object_isNull(handle->hdcp1_app_obj)) {
- pr_err("hdcp1_app_obj is NULL\n");
- ret = -EINVAL;
- goto error;
- }
- ret = load_app(HDCP1OPS_APP_NAME, &(handle->hdcp1ops_app_obj),
- &(handle->hdcp1ops_appcontroller_obj));
- if (ret) {
- pr_err("hdcp1ops TA load failed :%d\n", ret);
- goto error;
- }
- if (Object_isNull(handle->hdcp1ops_app_obj)) {
- pr_err("hdcp1ops_app_obj is NULL\n");
- ret = -EINVAL;
- goto error;
- }
- handle->hdcp_state |= HDCP_STATE_APP_LOADED;
- error:
- return ret;
- }
- static void hdcp1_app_unload(struct hdcp1_smcinvoke_handle *handle)
- {
- if (!handle || !handle->hdcp1_app_obj.context) {
- pr_err("invalid handle\n");
- return;
- }
- if (!(handle->hdcp_state & HDCP_STATE_APP_LOADED)) {
- pr_warn("hdcp1 app not loaded\n");
- return;
- }
- Object_ASSIGN_NULL(handle->hdcp1_app_obj);
- Object_ASSIGN_NULL(handle->hdcp1_appcontroller_obj);
- Object_ASSIGN_NULL(handle->hdcp1ops_app_obj);
- Object_ASSIGN_NULL(handle->hdcp1ops_appcontroller_obj);
- handle->hdcp_state &= ~HDCP_STATE_APP_LOADED;
- pr_debug("%s app unloaded\n", HDCP1_APP_NAME);
- }
- void *hdcp1_init_smcinvoke(void)
- {
- struct hdcp1_smcinvoke_handle *handle =
- kzalloc(sizeof(struct hdcp1_smcinvoke_handle), GFP_KERNEL);
- if (!handle)
- goto error;
- error:
- return handle;
- }
- bool hdcp1_feature_supported_smcinvoke(void *data)
- {
- int ret = 0;
- bool supported = false;
- struct hdcp1_smcinvoke_handle *handle = data;
- if (!handle) {
- pr_err("invalid handle\n");
- goto error;
- }
- if (handle->feature_supported) {
- supported = true;
- goto error;
- }
- ret = hdcp1_app_load(handle);
- if (!ret && (handle->hdcp_state & HDCP_STATE_APP_LOADED)) {
- if (!hdcp1_verify_key(handle)) {
- pr_debug("HDCP 1.x supported\n");
- handle->feature_supported = true;
- supported = true;
- }
- hdcp1_app_unload(handle);
- }
- error:
- return supported;
- }
- int hdcp1_set_enc_smcinvoke(void *data, bool enable)
- {
- int ret = 0;
- struct hdcp1_smcinvoke_handle *handle = data;
- if (!handle || !handle->hdcp1_app_obj.context) {
- pr_err("invalid HDCP 1.x handle\n");
- return -EINVAL;
- }
- if (!handle->feature_supported) {
- pr_err("HDCP 1.x not supported\n");
- return -EINVAL;
- }
- if (!(handle->hdcp_state & HDCP_STATE_APP_LOADED)) {
- pr_err("%s app not loaded\n", HDCP1_APP_NAME);
- return -EINVAL;
- }
- ret = hdcp1_set_encryption(handle->hdcp1_app_obj, enable);
- if (ret)
- pr_err("hdcp1_set_encryption failed :%d\n", ret);
- return ret;
- }
- int hdcp1_ops_notify_smcinvoke(void *data, void *topo, bool is_authenticated)
- {
- int ret = 0;
- struct hdcp1_smcinvoke_handle *handle = data;
- if (!handle || !handle->hdcp1ops_app_obj.context) {
- pr_err("invalid HDCP 1.x ops handle\n");
- return -EINVAL;
- }
- if (!handle->feature_supported) {
- pr_err("HDCP 1.x not supported\n");
- return -EINVAL;
- }
- if (!(handle->hdcp_state & HDCP_STATE_APP_LOADED)) {
- pr_err("%s app not loaded\n", HDCP1OPS_APP_NAME);
- return -EINVAL;
- }
- ret = hdcp1_ops_notify_topology_change(handle->hdcp1ops_app_obj);
- if (ret)
- pr_err("hdcp1_ops_notify_topology_change failed, ret=%d\n", ret);
- return ret;
- }
- int hdcp1_start_smcinvoke(void *data, u32 *aksv_msb, u32 *aksv_lsb)
- {
- int ret = 0;
- struct hdcp1_smcinvoke_handle *handle = data;
- if (!aksv_msb || !aksv_lsb) {
- pr_err("invalid aksv output buffer\n");
- ret = -EINVAL;
- goto error;
- }
- if (!handle) {
- pr_err("invalid handle\n");
- ret = -EINVAL;
- goto error;
- }
- if (!handle->feature_supported) {
- pr_err("feature not supported\n");
- ret = -EINVAL;
- goto error;
- }
- if (handle->hdcp_state & HDCP_STATE_APP_LOADED) {
- pr_debug("%s app already loaded\n", HDCP1_APP_NAME);
- goto error;
- }
- ret = hdcp1_app_load(handle);
- if (ret)
- goto error;
- ret = hdcp1_key_set(handle, aksv_msb, aksv_lsb);
- if (ret)
- goto key_error;
- pr_debug("success\n");
- return ret;
- key_error:
- hdcp1_app_unload(handle);
- error:
- return ret;
- }
- void hdcp1_stop_smcinvoke(void *data)
- {
- struct hdcp1_smcinvoke_handle *hdcp1_handle = data;
- if (!hdcp1_handle) {
- pr_err("invalid HDCP 1.x handle\n");
- return;
- }
- if (!(hdcp1_handle->hdcp_state & HDCP_STATE_APP_LOADED)) {
- pr_err("hdcp1 app not loaded\n");
- return;
- }
- Object_ASSIGN_NULL(hdcp1_handle->hdcp1_app_obj);
- Object_ASSIGN_NULL(hdcp1_handle->hdcp1_appcontroller_obj);
- Object_ASSIGN_NULL(hdcp1_handle->hdcp1ops_app_obj);
- Object_ASSIGN_NULL(hdcp1_handle->hdcp1ops_appcontroller_obj);
- hdcp1_handle->hdcp_state &= ~HDCP_STATE_APP_LOADED;
- }
- void *hdcp2_init_smcinvoke(u32 device_type)
- {
- struct hdcp2_smcinvoke_handle *handle =
- kzalloc(sizeof(struct hdcp2_smcinvoke_handle), GFP_KERNEL);
- if (!handle)
- goto error;
- handle->device_type = device_type;
- error:
- return handle;
- }
- void hdcp2_deinit_smcinvoke(void *ctx)
- {
- kfree_sensitive(ctx);
- }
- int hdcp_get_version(struct hdcp2_smcinvoke_handle *handle)
- {
- int ret = 0;
- uint32_t app_major_version = 0;
- uint32_t appversion = 0;
- if (handle->hdcp_state & HDCP_STATE_APP_LOADED) {
- pr_err("hdcp2p2 TA already loaded\n");
- goto error;
- }
- ret = hdcp2p2_version(handle->hdcp2_app_obj, &appversion);
- if (ret) {
- pr_err("hdcp2p2_version failed :%d\n", ret);
- goto error;
- }
- app_major_version = HCDP_TXMTR_GET_MAJOR_VERSION(appversion);
- pr_debug("hdp2p2 app major version %d, app version %d\n", app_major_version,
- appversion);
- error:
- return ret;
- }
- int hdcp2_app_init(struct hdcp2_smcinvoke_handle *handle)
- {
- int ret = 0;
- uint32_t app_minor_version = 0;
- uint32_t clientversion = 0;
- uint32_t appversion = 0;
- if (handle->hdcp_state & HDCP_STATE_APP_LOADED) {
- pr_err("hdcp2p2 TA already loaded\n");
- goto error;
- }
- clientversion = HDCP_CLIENT_MAKE_VERSION(HDCP_CLIENT_MAJOR_VERSION,
- HDCP_CLIENT_MINOR_VERSION,
- HDCP_CLIENT_PATCH_VERSION);
- ret = hdcp2p2_init(handle->hdcp2_app_obj, clientversion, &appversion);
- if (ret) {
- pr_err("hdcp2p2_init failed:%d\n", ret);
- goto error;
- }
- app_minor_version = HCDP_TXMTR_GET_MINOR_VERSION(appversion);
- if (app_minor_version != HDCP_CLIENT_MINOR_VERSION) {
- pr_err("client-app minor version mismatch app(%d), client(%d)\n",
- app_minor_version, HDCP_CLIENT_MINOR_VERSION);
- ret = -1;
- goto error;
- }
- pr_err("client version major(%d), minor(%d), patch(%d)\n",
- HDCP_CLIENT_MAJOR_VERSION, HDCP_CLIENT_MINOR_VERSION,
- HDCP_CLIENT_PATCH_VERSION);
- pr_err("app version major(%d), minor(%d), patch(%d)\n",
- HCDP_TXMTR_GET_MAJOR_VERSION(appversion),
- HCDP_TXMTR_GET_MINOR_VERSION(appversion),
- HCDP_TXMTR_GET_PATCH_VERSION(appversion));
- error:
- return ret;
- }
- int hdcp2_app_tx_init(struct hdcp2_smcinvoke_handle *handle)
- {
- int ret = 0;
- uint32_t ctxhandle = 0;
- if (!(handle->hdcp_state & HDCP_STATE_SESSION_INIT)) {
- pr_err("session not initialized\n");
- ret = -EINVAL;
- goto error;
- }
- if (handle->hdcp_state & HDCP_STATE_TXMTR_INIT) {
- pr_err("txmtr already initialized\n");
- goto error;
- }
- ret = hdcp2p2_tx_init(handle->hdcp2_app_obj, handle->session_id, &ctxhandle);
- if (ret) {
- pr_err("hdcp2p2_tx_init failed :%d\n", ret);
- goto error;
- }
- handle->tz_ctxhandle = ctxhandle;
- handle->hdcp_state |= HDCP_STATE_TXMTR_INIT;
- error:
- return ret;
- }
- int hdcp2_app_tx_deinit(struct hdcp2_smcinvoke_handle *handle)
- {
- int ret = 0;
- if (!(handle->hdcp_state & HDCP_STATE_APP_LOADED)) {
- pr_err("hdcp2p2 TA not loaded\n");
- ret = -EINVAL;
- goto error;
- }
- if (!(handle->hdcp_state & HDCP_STATE_TXMTR_INIT)) {
- pr_err("txmtr not initialized\n");
- ret = -EINVAL;
- goto error;
- }
- ret = hdcp2p2_tx_deinit(handle->hdcp2_app_obj, handle->tz_ctxhandle);
- if (ret) {
- pr_err("hdcp2p2_tx_deinit failed :%d\n", ret);
- goto error;
- }
- handle->hdcp_state &= ~HDCP_STATE_TXMTR_INIT;
- error:
- return ret;
- }
- static int hdcp2_app_load(struct hdcp2_smcinvoke_handle *handle)
- {
- int ret = 0;
- if (!handle) {
- pr_err("invalid input\n");
- ret = -EINVAL;
- goto error;
- }
- if (handle->hdcp_state & HDCP_STATE_APP_LOADED) {
- pr_err("hdcp2p2 TA already loaded\n");
- goto error;
- }
- ret = load_app(HDCP2P2_APP_NAME, &(handle->hdcp2_app_obj),
- &(handle->hdcp2_appcontroller_obj));
- if (ret) {
- pr_err("hdcp2p2 TA load_app failed :%d\n", ret);
- goto error;
- }
- if (Object_isNull(handle->hdcp2_app_obj)) {
- pr_err("hdcp2p2 app object is NULL\n");
- ret = -EINVAL;
- goto error;
- }
- ret = load_app(HDCPSRM_APP_NAME, &(handle->hdcpsrm_app_obj),
- &(handle->hdcpsrm_appcontroller_obj));
- if (ret == 16) {
- pr_err("hdcpsrm TA already loaded\n");
- } else if (ret) {
- pr_err("hdcpsrm TA load failed :%d\n", ret);
- goto error;
- }
- if (Object_isNull(handle->hdcpsrm_app_obj)) {
- pr_err("hdcpsrm app object is NULL\n");
- ret = -EINVAL;
- goto error;
- }
- ret = hdcp_get_version(handle);
- if (ret) {
- pr_err("library get version failed\n");
- goto error;
- }
- ret = hdcp2_app_init(handle);
- if (ret) {
- pr_err("app init failed\n");
- goto error;
- }
- handle->hdcp_state |= HDCP_STATE_APP_LOADED;
- error:
- return ret;
- }
- static int hdcp2_app_unload(struct hdcp2_smcinvoke_handle *handle)
- {
- int ret = 0;
- ret = hdcp2p2_deinit(handle->hdcp2_app_obj);
- if (ret) {
- pr_err("hdcp2p2_deinit failed:%d\n", ret);
- goto error;
- }
- Object_ASSIGN_NULL(handle->hdcp2_app_obj);
- Object_ASSIGN_NULL(handle->hdcp2_appcontroller_obj);
- Object_ASSIGN_NULL(handle->hdcpsrm_app_obj);
- Object_ASSIGN_NULL(handle->hdcpsrm_appcontroller_obj);
- handle->hdcp_state &= ~HDCP_STATE_APP_LOADED;
- error:
- return ret;
- }
- static int hdcp2_verify_key(struct hdcp2_smcinvoke_handle *handle)
- {
- int ret = 0;
- if (!(handle->hdcp_state & HDCP_STATE_APP_LOADED)) {
- pr_err("%s app not loaded\n", HDCP2P2_APP_NAME);
- ret = -EINVAL;
- goto error;
- }
- ret = hdcp2p2_verify_key(handle->hdcp2_app_obj);
- if (ret) {
- pr_err("hdcp2p2_verify_key failed:%d\n", ret);
- goto error;
- }
- error:
- return ret;
- }
- static int hdcp2_app_session_init(struct hdcp2_smcinvoke_handle *handle)
- {
- int ret = 0;
- uint32_t sessionId = 0;
- if (!(handle->hdcp_state & HDCP_STATE_APP_LOADED)) {
- pr_err("hdcp2p2 app not loaded\n");
- ret = -EINVAL;
- goto error;
- }
- if (handle->hdcp_state & HDCP_STATE_SESSION_INIT) {
- pr_err("session already initialized\n");
- goto error;
- }
- if (Object_isNull(handle->hdcp2_app_obj)) {
- pr_err("hdcp2_app_obj is NULL\n");
- goto error;
- }
- ret = hdcp2p2_session_init(handle->hdcp2_app_obj, handle->device_type,
- &sessionId);
- if (ret) {
- pr_err("hdcp2p2_session_init failed ret:%d\n", ret);
- goto error;
- }
- handle->session_id = sessionId;
- handle->hdcp_state |= HDCP_STATE_SESSION_INIT;
- error:
- return ret;
- }
- static int hdcp2_app_session_deinit(struct hdcp2_smcinvoke_handle *handle)
- {
- int ret = 0;
- if (!(handle->hdcp_state & HDCP_STATE_APP_LOADED)) {
- pr_err("hdcp2p2 app not loaded\n");
- ret = -EINVAL;
- goto error;
- }
- if (!(handle->hdcp_state & HDCP_STATE_SESSION_INIT)) {
- pr_err("session not initialized\n");
- ret = -EINVAL;
- goto error;
- }
- ret = hdcp2p2_session_deinit(handle->hdcp2_app_obj, handle->session_id);
- if (ret) {
- pr_err("hdcp2p2_session_deinit failed:%d\n", ret);
- goto error;
- }
- handle->hdcp_state &= ~HDCP_STATE_SESSION_INIT;
- error:
- return ret;
- }
- int hdcp2_app_start_smcinvoke(void *ctx, uint32_t req_len)
- {
- struct hdcp2_smcinvoke_handle *handle = NULL;
- int ret = 0;
- handle = (struct hdcp2_smcinvoke_handle *)ctx;
- if (!handle) {
- pr_err("Invalid handle\n");
- ret = -EINVAL;
- goto error;
- }
- handle->app_data.request.data = kmalloc(MAX_RX_MESSAGE_SIZE, GFP_KERNEL);
- if (!handle->app_data.request.data) {
- ret = -EINVAL;
- goto error;
- }
- handle->app_data.response.data = kmalloc(MAX_TX_MESSAGE_SIZE, GFP_KERNEL);
- if (!handle->app_data.response.data) {
- ret = -EINVAL;
- goto error;
- }
- ret = hdcp2_app_load(handle);
- if (ret)
- goto error;
- ret = hdcp2_app_session_init(handle);
- if (ret)
- goto error;
- ret = hdcp2_app_tx_init(handle);
- if (ret)
- goto error;
- error:
- return ret;
- }
- int hdcp2_app_start_auth_smcinvoke(void *ctx, uint32_t req_len)
- {
- struct hdcp2_smcinvoke_handle *handle = NULL;
- int ret = 0;
- size_t resMsgOut = 0;
- uint32_t timeout = 0;
- uint32_t flag = 0;
- uint32_t ctxhandle = 0;
- uint8_t resMsg[MAX_TX_MESSAGE_SIZE] = {0};
- handle = ctx;
- if (!handle) {
- pr_err("Invalid handle\n");
- ret = -EINVAL;
- goto error;
- }
- handle->app_data.request.length = req_len;
- if (!(handle->hdcp_state & HDCP_STATE_SESSION_INIT)) {
- pr_err("session not initialized\n");
- ret = -EINVAL;
- goto error;
- }
- if (!(handle->hdcp_state & HDCP_STATE_TXMTR_INIT)) {
- pr_err("txmtr not initialized\n");
- ret = -EINVAL;
- goto error;
- }
- ret = hdcp2p2_start_auth(handle->hdcp2_app_obj, handle->tz_ctxhandle,
- resMsg, MAX_TX_MESSAGE_SIZE, &resMsgOut, &timeout,
- &flag, &ctxhandle);
- if (ret) {
- pr_err("hdcp2p2_start_auth failed :%d\n", ret);
- goto error;
- }
- memcpy(handle->app_data.response.data, resMsg, resMsgOut);
- handle->app_data.response.length = resMsgOut;
- handle->app_data.timeout = timeout;
- handle->app_data.repeater_flag = false;
- handle->tz_ctxhandle = ctxhandle;
- error:
- return ret;
- }
- int hdcp2_app_process_msg_smcinvoke(void *ctx, uint32_t req_len)
- {
- struct hdcp2_smcinvoke_handle *handle = NULL;
- int ret = 0;
- size_t resMsgLen = 0;
- uint32_t timeout = 0;
- uint32_t flag = 0;
- uint32_t state = 0;
- uint8_t resMsg[MAX_TX_MESSAGE_SIZE] = {0};
- handle = ctx;
- if (!handle) {
- pr_err("Invalid handle\n");
- ret = -EINVAL;
- goto error;
- }
- handle->app_data.request.length = req_len;
- if (!handle->app_data.request.data) {
- pr_err("invalid request buffer\n");
- ret = -EINVAL;
- goto error;
- }
- ret = hdcp2p2_rcvd_msg(
- handle->hdcp2_app_obj, handle->app_data.request.data,
- handle->app_data.request.length, handle->tz_ctxhandle, resMsg,
- MAX_TX_MESSAGE_SIZE, &resMsgLen, &timeout, &flag, &state);
- if (ret) {
- pr_err("hdcp2p2_rcvd_msg failed :%d\n", ret);
- goto error;
- }
- memcpy(handle->app_data.response.data, resMsg, resMsgLen);
- /* check if it's a repeater */
- if (flag == HDCP_TXMTR_SUBSTATE_WAITING_FOR_RECIEVERID_LIST)
- handle->app_data.repeater_flag = true;
- handle->app_data.response.length = resMsgLen;
- handle->app_data.timeout = timeout;
- error:
- return ret;
- }
- int hdcp2_app_timeout_smcinvoke(void *ctx, uint32_t req_len)
- {
- struct hdcp2_smcinvoke_handle *handle = NULL;
- int ret = 0;
- uint32_t timeout = 0;
- size_t resMsgLenOut = 0;
- uint8_t resMsg[MAX_TX_MESSAGE_SIZE] = {0};
- handle = ctx;
- if (!handle) {
- pr_err("Invalid handle\n");
- ret = -EINVAL;
- goto error;
- }
- handle->app_data.request.length = req_len;
- ret = hdcp2p2_send_timeout(handle->hdcp2_app_obj, handle->tz_ctxhandle,
- resMsg, MAX_TX_MESSAGE_SIZE, &resMsgLenOut,
- &timeout);
- if (ret) {
- pr_err("hdcp2p2_send_timeout failed :%d\n", ret);
- goto error;
- }
- memcpy(handle->app_data.response.data, resMsg, resMsgLenOut);
- handle->app_data.response.length = resMsgLenOut;
- handle->app_data.timeout = timeout;
- error:
- return ret;
- }
- int hdcp2_app_enable_encryption_smcinvoke(void *ctx, uint32_t req_len)
- {
- struct hdcp2_smcinvoke_handle *handle = NULL;
- int ret = 0;
- handle = ctx;
- if (!handle) {
- pr_err("Invalid handle\n");
- ret = -EINVAL;
- goto error;
- }
- handle->app_data.request.length = req_len;
- /*
- * wait at least 200ms before enabling encryption
- * as per hdcp2p2 specifications.
- */
- msleep(SLEEP_SET_HW_KEY_MS);
- ret = hdcp2p2_set_hw_key(handle->hdcp2_app_obj, handle->tz_ctxhandle);
- if (ret) {
- pr_err("hdcp2p2_set_hw_key failed:%d\n", ret);
- goto error;
- }
- handle->hdcp_state |= HDCP_STATE_AUTHENTICATED;
- error:
- return ret;
- }
- int hdcp2_app_query_stream_smcinvoke(void *ctx, uint32_t req_len)
- {
- struct hdcp2_smcinvoke_handle *handle = NULL;
- int ret = 0;
- uint32_t timeout = 0;
- size_t resMsgLenOut = 0;
- uint8_t resMsg[MAX_TX_MESSAGE_SIZE] = {0};
- handle = ctx;
- if (!handle) {
- pr_err("Invalid handle\n");
- ret = -EINVAL;
- goto error;
- }
- handle->app_data.request.length = req_len;
- ret = hdcp2p2_query_stream_type(
- handle->hdcp2_app_obj, handle->tz_ctxhandle, resMsg,
- MAX_TX_MESSAGE_SIZE, &resMsgLenOut, &timeout);
- if (ret) {
- pr_err("hdcp2p2_query_stream_type failed :%d\n", ret);
- goto error;
- }
- memcpy(handle->app_data.response.data, resMsg, resMsgLenOut);
- handle->app_data.response.length = resMsgLenOut;
- handle->app_data.timeout = timeout;
- error:
- return ret;
- }
- int hdcp2_app_stop_smcinvoke(void *ctx)
- {
- struct hdcp2_smcinvoke_handle *handle = NULL;
- int ret = 0;
- handle = ctx;
- if (!handle) {
- pr_err("Invalid handle\n");
- ret = -EINVAL;
- goto end;
- }
- ret = hdcp2_app_tx_deinit(handle);
- if (ret)
- goto end;
- ret = hdcp2_app_session_deinit(handle);
- if (ret)
- goto end;
- ret = hdcp2_app_unload(handle);
- kfree(handle->app_data.request.data);
- kfree(handle->app_data.response.data);
- end:
- return ret;
- }
- bool hdcp2_feature_supported_smcinvoke(void *ctx)
- {
- struct hdcp2_smcinvoke_handle *handle = NULL;
- int ret = 0;
- bool supported = false;
- handle = ctx;
- if (!handle) {
- pr_err("invalid input\n");
- ret = -EINVAL;
- goto error;
- }
- if (handle->feature_supported) {
- supported = true;
- goto error;
- }
- ret = hdcp2_app_load(handle);
- if (!ret) {
- if (!hdcp2_verify_key(handle)) {
- pr_debug("HDCP 2.2 supported\n");
- handle->feature_supported = true;
- supported = true;
- }
- hdcp2_app_unload(handle);
- }
- error:
- return supported;
- }
- int hdcp2_force_encryption_smcinvoke(void *ctx, uint32_t enable)
- {
- struct hdcp2_smcinvoke_handle *handle = NULL;
- int ret = 0;
- handle = ctx;
- if (!handle) {
- pr_err("Invalid handle\n");
- ret = -EINVAL;
- goto error;
- }
- if (handle->hdcp_state == HDCP_STATE_AUTHENTICATED)
- msleep(SLEEP_FORCE_ENCRYPTION_MS);
- ret = hdcp2p2_force_encryption(handle->hdcp2_app_obj, handle->tz_ctxhandle,
- enable);
- if (ret) {
- pr_err("hdcp2p2_force_encryption failed :%d\n", ret);
- goto error;
- }
- error:
- return ret;
- }
- int hdcp2_open_stream_smcinvoke(void *ctx, uint8_t vc_payload_id,
- uint8_t stream_number, uint32_t *stream_id)
- {
- struct hdcp2_smcinvoke_handle *handle = NULL;
- int ret = 0;
- uint32_t streamid = 0;
- handle = ctx;
- if (!handle) {
- pr_err("Invalid handle\n");
- ret = -EINVAL;
- goto error;
- }
- if (!(handle->hdcp_state & HDCP_STATE_SESSION_INIT)) {
- pr_err("session not initialized\n");
- ret = -EINVAL;
- goto error;
- }
- if (!(handle->hdcp_state & HDCP_STATE_TXMTR_INIT)) {
- pr_err("txmtr not initialized\n");
- ret = -EINVAL;
- goto error;
- }
- ret = hdcp2p2_session_open_stream(handle->hdcp2_app_obj,
- handle->session_id, vc_payload_id,
- stream_number, 0, &streamid);
- if (ret) {
- pr_err("hdcp2p2_session_open_stream failed :%d\n", ret);
- goto error;
- }
- *stream_id = streamid;
- error:
- return ret;
- }
- int hdcp2_close_stream_smcinvoke(void *ctx, uint32_t stream_id)
- {
- struct hdcp2_smcinvoke_handle *handle = NULL;
- int ret = 0;
- handle = ctx;
- if (!handle) {
- pr_err("Invalid handle\n");
- ret = -EINVAL;
- goto error;
- }
- if (!(handle->hdcp_state & HDCP_STATE_SESSION_INIT)) {
- pr_err("session not initialized\n");
- ret = -EINVAL;
- goto error;
- }
- if (!(handle->hdcp_state & HDCP_STATE_TXMTR_INIT)) {
- pr_err("txmtr not initialized\n");
- ret = -EINVAL;
- goto error;
- }
- ret = hdcp2p2_session_close_stream(handle->hdcp2_app_obj,
- handle->session_id, stream_id);
- if (ret) {
- pr_err("hdcp2p2_session_close_stream failed :%d\n", ret);
- goto error;
- }
- error:
- return ret;
- }
- int hdcp2_update_app_data_smcinvoke(void *ctx, struct hdcp2_app_data *app_data)
- {
- struct hdcp2_smcinvoke_handle *handle = NULL;
- int ret = 0;
- handle = ctx;
- if (!handle || !app_data) {
- pr_err("Invalid handle\n");
- return -EINVAL;
- }
- app_data->request.data = handle->app_data.request.data;
- app_data->request.length = handle->app_data.request.length;
- app_data->response.data = handle->app_data.response.data;
- app_data->response.length = handle->app_data.response.length;
- app_data->timeout = handle->app_data.timeout;
- app_data->repeater_flag = handle->app_data.repeater_flag;
- return ret;
- }
|