47 #ifdef INCLUDE_FREESAT 48 #include <openssl/sha.h> 49 #include <openssl/rsa.h> 50 #include <openssl/evp.h> 51 #include <openssl/x509.h> 54 #ifdef INCLUDE_CI_PLUS 61 #define MAX_WAI_LEN 256 65 #define RSA_SALT_SIZE 16 66 #define RSA_SIGNATURE_SIZE (1024 / 8) 67 #define MAX_VERSION_LEN 12 68 #define MAX_RSA_KEY_SIZE 1024 76 static MHEG5Int currentICStatus = -1;
78 static U8BIT guidanceMessage[MAX_PROMPT * 4 + 1];
87 #ifdef INCLUDE_FREESAT 88 static U16BIT EncodeBase64(U8BIT *data, U16BIT len, U8BIT *result);
108 MHEG5Bool rtn_val = MHEG5TRUE;
110 assert( buffer != NULL && length != 0);
113 if (strncmp((
char *)buffer, (
char *)
"dvb://", 6) == 0)
117 else if (strncmp((
char *)buffer, (
char *)
"rec://svc/", 10) == 0)
122 if (strncmp((
char *)buffer, (
char *)
"def", 3) == 0)
124 MHEG5GetDefaultService(multiplexRef);
127 else if (strncmp((
char *)buffer, (
char *)
"cur", 3) == 0)
131 TRACE(TSTRM, (
"svc/cur is default service %d", multiplexRef->service_id))
135 else if (strncmp((
char *)buffer, (
char *)
"lcn/", 4) == 0 &&
141 lcn = MHEG5parseLcn( buffer + 4, buffer + length - 10 );
147 multiplexRef->original_network_id = dvbLocator.original_network_id;
148 multiplexRef->transport_stream_id = dvbLocator.transport_stream_id;
149 multiplexRef->service_id = dvbLocator.service_id;
153 rtn_val = MHEG5FALSE;
156 #ifdef INCLUDE_FREESAT 157 else if (strncmp((
char *)buffer, (
char *)
"fsi/", 4) == 0 &&
164 fsi = MHEG5parseLcn( buffer + 4, buffer + length - 10 );
167 (DVB_MhegGetFSILocator(fsi, &dvbLocator) == MHERR_OK))
170 multiplexRef->original_network_id = dvbLocator.original_network_id;
171 multiplexRef->transport_stream_id = dvbLocator.transport_stream_id;
172 multiplexRef->service_id = dvbLocator.service_id;
176 rtn_val = MHEG5FALSE;
182 rtn_val = MHEG5FALSE;
187 rtn_val = MHEG5FALSE;
189 TRACE(TSTRM, (
"name=%s -> srv_id=0x%x (%d)", buffer, multiplexRef->service_id, multiplexRef->service_id))
210 S32BIT serviceIndex = -1;
213 if (serviceReference->data && serviceReference->len &&
214 MHEG5parseUrl(serviceReference->data, serviceReference->len, &multiplexRef))
217 dvbLocator.original_network_id = multiplexRef.original_network_id;
218 dvbLocator.transport_stream_id = multiplexRef.transport_stream_id;
219 dvbLocator.service_id = multiplexRef.service_id;
221 TRACE(TTUNE, (
"net_id=%d trns_id=%d serv_id=%d",
222 dvbLocator.original_network_id, dvbLocator.transport_stream_id, dvbLocator.service_id))
229 TRACE(TTUNE, (
" %.*s --> index=%x", serviceReference->len, serviceReference->data, serviceIndex));
252 *InfoResultVal = MHEG5FALSE;
261 *InfoResultVal = MHEG5TRUE;
263 tmp.len = nbInfo.zlen;
264 tmp.data = nbInfo.zptr;
312 MHEG5Int *origNetworkID, MHEG5Int *transportStreamID,
316 MHEG5Bool rc = MHEG5FALSE;
320 *networkID = location.network_id;
321 *origNetworkID = location.original_network_id;
322 *transportStreamID = location.transport_stream_id;
323 *serviceID = location.service_id;
330 *transportStreamID = 0;
337 #ifdef INCLUDE_CI_PLUS 402 DVB_MhegSetVideoAlignment(ASPECT_MODE_4_3);
426 void MHEG5getICStatus(MHEG5Int *icStatus)
428 if (currentICStatus == -1)
435 case NW_LINK_INACTIVE:
438 case NW_LINK_DISABLED:
445 *icStatus = currentICStatus;
455 void MHEG5clearICStatus(
void)
458 currentICStatus = -1;
461 void MHEG5changedICStatus(
void)
464 currentICStatus = -1;
473 void MHEG5isConnectionEnabled(MHEG5Bool *enabled)
476 #ifdef INCLUDE_FREESAT 477 S32BIT service_index;
478 service_index = MHEG5GetCurrentServiceIndex();
479 DVB_MhegIsConnectionAllowed(service_index, &isAllowed);
485 *enabled = MHEG5TRUE;
489 *enabled = MHEG5FALSE;
499 MHEG5Bool MHEG5IsPinRequired(
void)
501 MHEG5Bool required = MHEG5TRUE;
502 #ifdef INCLUDE_FREESAT 504 DVB_MhegGetPINRequirement(&status);
505 if ( status == MHEG5_ICS_PIN_REQ_NEVER )
507 required = MHEG5FALSE;
510 E_ICSPinSupport support;
512 if (support != MHEG5_ICS_PIN_SUPPORT_ENABLED)
514 required = MHEG5FALSE;
516 TRACE(TICS,(
"PIN support %d %d",support,required))
529 MHEG5Bool MHEG5promptForGuidance(
MHEG5String *restriction, MHEG5Bool show)
547 out = guidanceMessage;
549 if (restriction != NULL)
554 len = restriction->len;
561 byte = restriction->data[index];
569 else if (byte <= 0x7f)
571 if (count < MAX_PROMPT)
577 else if ((byte & 0xe0) == 0xc0)
583 else if ((byte & 0xf0) == 0xe0)
589 else if ((byte & 0xf8) == 0xf0)
597 if (byte >= 0x40 && byte <= 0x5e)
600 if (index + (U16BIT)2 < (U16BIT)len)
603 index += 2 + restriction->data[index + 2];
611 else if (byte >= 0x60 && byte <= 0x7e)
624 if ((byte & 0xc0) == 0x80)
638 if ((byte & 0xc0) == 0x80)
652 if ((byte & 0xc0) == 0x80)
658 if (count < MAX_PROMPT)
665 else if (ch <= 0x7ff)
667 *out++ = 0xc0 | (U8BIT)(ch >> 6);
668 *out++ = 0x80 | (U8BIT)(ch & 0x3f);
670 else if (ch <= 0xffff)
672 *out++ = 0xe0 | (U8BIT)(ch >> 12);
673 *out++ = 0x80 | ((ch >> 6) & 0x3f);
674 *out++ = 0x80 | (ch & 0x3f);
678 *out++ = 0xe0 | (U8BIT)(ch >> 18);
679 *out++ = 0x80 | ((ch >> 12) & 0x3f);
680 *out++ = 0x80 | ((ch >> 6) & 0x3f);
681 *out++ = 0x80 | (ch & 0x3f);
697 if ((((byte & 0x80) == 0x00) && (byte != 0x00)) ||
698 ((byte & 0xe0) == 0xc0) ||
699 ((byte & 0xf0) == 0xe0) ||
700 ((byte & 0xf8) == 0xf0))
718 #ifndef INCLUDE_FREESAT 727 MHEG5Bool MHEG5GetPINSupport(MHEG5Int *support)
729 E_ICSPinSupport pinSupport;
733 success = MHEG5FALSE;
740 case MHEG5_ICS_PIN_SUPPORT_NONE:
744 case MHEG5_ICS_PIN_SUPPORT_DISABLED:
748 case MHEG5_ICS_PIN_SUPPORT_ENABLED:
769 MHEG5Bool MHEG5GetPINRequirement(MHEG5Int *status)
771 E_ICSPinReq pinStatus;
774 success = MHEG5FALSE;
776 DVB_MhegGetPINRequirement(&pinStatus);
779 case MHEG5_ICS_PIN_REQ_NEVER:
783 case MHEG5_ICS_PIN_REQ_GUIDANCE_ONLY:
787 case MHEG5_ICS_PIN_REQ_ALWAYS:
805 MHEG5Bool MHEG5GetFSIServiceReference(MHEG5Int serviceIndex, MHEG5Int *fsi,
MHEG5String *fsiString)
807 MHEG5Byte fsiChars[5];
811 if (DVB_MhegGetFSIServiceReference(serviceIndex, &fsiBuffer) == MHERR_OK)
814 if (fsiBuffer > 0x7ff || fsiBuffer < 1)
820 fsiChars[4] =
'0' + fsiBuffer % 10;
821 fsiChars[3] =
'0' + fsiBuffer / 10;
822 fsiChars[2] =
'0' + fsiBuffer / 100;
823 fsiChars[1] =
'0' + fsiBuffer / 1000;
824 fsiChars[0] =
'0' + fsiBuffer / 10000;
826 for (i = 0; i < 5; i++)
828 if (fsiChars[i] ==
'0')
838 fsiString->data = STR_DataAlloc( fsiString->len );
839 memcpy(fsiString->data,
"rec://svc/fsi/", 14);
840 memcpy(fsiString->data + 14, &fsiChars[i], fsiString->len - 14);
859 MHEG5Bool MHEG5ValidatePIN(
MHEG5String *pin, MHEG5Int *status)
861 E_ICSPinStatus pinStatus;
864 success = MHEG5FALSE;
866 DVB_MhegValidatePIN(pin->data, &pinStatus);
869 case MHEG5_ICS_PIN_STATUS_NOT_REQUIRED:
873 case MHEG5_ICS_PIN_STATUS_OK:
877 case MHEG5_ICS_PIN_STATUS_INVALID:
911 unsigned int siglen = RSA_SIGNATURE_SIZE;
916 char verstr[MAX_VERSION_LEN];
918 U32BIT reslen, offset;
927 workspace = MHEG5getMem(RSA_SALT_SIZE + data->len + SHA_DIGEST_LENGTH + MAX_RSA_KEY_SIZE + RSA_SIGNATURE_SIZE);
928 if (workspace != NULL)
931 ws_data = ws_salt + RSA_SALT_SIZE;
932 ws_digest = ws_data + data->len;
933 ws_key = ws_digest + SHA_DIGEST_LENGTH;
934 ws_signature = ws_key + MAX_RSA_KEY_SIZE;
937 for (i = 0; i < 10; i++)
943 DVB_MhegGetMACAddress(ws_salt + 10);
946 memcpy(ws_data, data->data, data->len);
949 EVP_DigestInit(&ctx, EVP_sha1());
950 EVP_DigestUpdate(&ctx, workspace, RSA_SALT_SIZE + data->len);
951 EVP_DigestFinal(&ctx, ws_digest, NULL);
954 DVB_MhegGetPrivateKey(ws_key, MAX_RSA_KEY_SIZE, &keylen, &version);
955 if (keylen <= MAX_RSA_KEY_SIZE)
957 bio = BIO_new_mem_buf(ws_key, keylen);
960 rsa = d2i_RSAPrivateKey_bio(bio, NULL);
963 if (rsa != NULL && RSA_size(rsa) == RSA_SIGNATURE_SIZE)
966 rc = RSA_sign(NID_sha1, ws_digest, SHA_DIGEST_LENGTH,
967 ws_signature, &siglen, rsa);
982 sprintf(verstr,
"%u", version);
983 reslen = strlen(verstr) + 1 + 24 + 1 + 172;
985 result->len = reslen;
986 result->data = (U8BIT *)STR_DataAlloc(result->len + 1);
987 if (result->data != NULL)
989 strcpy((
char *)result->data, verstr);
990 offset = strlen(verstr);
991 result->data[offset] =
':';
993 offset += EncodeBase64(ws_salt, RSA_SALT_SIZE,
994 result->data + offset);
995 result->data[offset] =
':';
997 offset += EncodeBase64(ws_signature, siglen,
998 result->data + offset);
999 result->data[offset] =
'\0';
1003 if (workspace != NULL)
1005 MHEG5freeMem(workspace);
1018 static U16BIT EncodeBase64(U8BIT *data, U16BIT len, U8BIT *result)
1020 static char *base64 =
1021 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 1022 "abcdefghijklmnopqrstuvwxyz" 1026 for (i = 0; i < len; i += 3)
1028 result[i / 3 * 4 ] = base64[(data[i ] >> 2) & 0x3f];
1029 result[i / 3 * 4 + 1] = base64[(data[i ] << 4 | data[i + 1] >> 4) & 0x3f];
1030 result[i / 3 * 4 + 2] = base64[(data[i + 1] << 2 | data[i + 2] >> 6) & 0x3f];
1031 result[i / 3 * 4 + 3] = base64[(data[i + 2]) & 0x3f];
1038 result[i / 3 * 4 ] = base64[(data[i ] >> 2) & 0x3f];
1039 result[i / 3 * 4 + 1] = base64[(data[i ] << 4 | data[i + 1] >> 4) & 0x3f];
1040 result[i / 3 * 4 + 2] = base64[(data[i + 1] << 2) & 0x3f];
1041 result[i / 3 * 4 + 3] =
'=';
1044 result[i / 3 * 4 ] = base64[(data[i ] >> 2) & 0x3f];
1045 result[i / 3 * 4 + 1] = base64[(data[i ] << 4) & 0x3f];
1046 result[i / 3 * 4 + 2] =
'=';
1047 result[i / 3 * 4 + 3] =
'=';
1054 return (len + 2) / 3 * 4;
1064 #ifdef INCLUDE_CONNECTED_TV
Implement MHEG5 engine control functions (i.e. start/stop etc)
unsigned long MHEG5random(void)
Calculate and return a psuedo random number.
void MHEG5sendAppEngineEvent(E_ENGINE_EVENT engine_event)
Store an Engine event in the asynchronous event queue.
Interface functions to DSM-CC instance for MHEG5.
MHEG5Int MHEG5GetServiceIndex(MHEG5String *serviceReference)
Ref:[1] - 3.10.6.1 and [1] - 3.10.6.3 Get the serviceIndex, a positive integer which is used to refer...
void MG_SetSubtitleMode(MHEG5Bool subtitleOn)
Set the current subtitle display mode to be either On or Off, Should only have an impact if subtitles...
E_MhegErr DVB_MhegApplicationLaunch(U8BIT *location, U8BIT *args)
Hands control of execution to another application of an arbitrary type.
void MHEG5SuppressMHEGGraphics(MHEG5Bool request)
Request that the external application toggles between showing MHEG graphics or subtitles This functio...
Implement the MHEG5 Stream Class Stream Class Defines the behaviour of a composition of continuous me...
E_MhegErr DVB_MhegIndexToDvbLocation(S32BIT serviceIndex, S_DvbLocation *pDvbLocation)
Convert Service index into full DVB location information. This being networkID, origNetworkID, transportStreamID, serviceID.
E_MhegErr DVB_MhegGetPINSupport(E_ICSPinSupport *support)
Returns the PIN support in the receiver. This MUST be a non-blocking function, returning results imme...
E_MhegErr DVB_MhegPromptForGuidance(U8BIT *restriction, BOOLEAN show)
This function asks the external application to obtain permission from the user to present IP-delivere...
E_MhegErr DVB_MhegLcnToDvbLocator(U32BIT lcn, S_DvbLocator *pDvbLocator)
Convert Logical channel number into DVB locator information.
MHEG5Bool MHEG5RequestMPEGDecoder(MHEG5Bool request)
Requests exclusive access to a MPEG decoder and video plane to display I-frames. The MPEG decoder sha...
MHEG5Bool MHEG5streamGetCurrentService(S_DVB_LOCATOR *multiplexRef)
Return the current service (i.e. the service corresponding to the currently running Video...
MHEG5Bool MHEG5parseUrl(U8BIT *buffer, U32BIT length, S_DVB_LOCATOR *multiplexRef)
Parse a DAVIC style multiplex reference or UK-DTT inherritance format URL. This can be one of the fol...
MHEG5String MHEG5stringCopy(MHEG5String source)
<Function description>="">
BOOLEAN MH5GlueSiqNetBootInfo(S_STRING *nbinfo)
Get current MHEG net boot info existance and nb info string.
DVB Video functions are required by MHEG5 engine. All required functions should be non-blocking...
string parsing utility functions for MHEG5
E_MhegErr DVB_MhegSuppressMHEGGraphics(BOOLEAN suppress)
Toggle between displaying MHEG graphics and subtitles on platforms that do not support them both symu...
DVB Service information functions are required by MHEG5 engine. All required functions should be non-...
This file defines the profile for the MHEG engine.
void MHEG5TuneIndexInfo(MHEG5Int tuneInfo)
Sets the way the application expects the receiver is to perform all subsequence application initiated...
MHEG5String MHEG5GetBootInfo(MHEG5Bool *InfoResultVal)
Tell whether a network_boot_info sub-descriptor has been found and received. If so, returns the value of the NB_info field of the network_boot_info sub-descriptor. This function is used by the GetBootInfo resident program. See UK1.06 profile section 3.10.7.3.
Event handling. Implementation of a combined queue for events and actions. This is the eventsystem wh...
void DVB_MhegSetAspectRatio(E_ASPECT_RATIO aspect)
Set display aspect ratio.
MHEG5Int MHEG5GetDisplayAspectRatio(void)
Find the setting of the attached display's aspect ratio This function is used by the GetDisplayAspect...
E_MhegErr DVB_MhegRequestMPEGDecoder(E_DecoderRequest request, BOOLEAN *pResult)
This function requests exclusive access to a MPEG decoder and video plane to display I-frames...
Mheg5 logging and debug printing.
Common Interface functions required by MHEG5 engine.
MHEG5Bool MHEG5GetBasicSI(MHEG5Int serviceIndex, MHEG5Int *networkID, MHEG5Int *origNetworkID, MHEG5Int *transportStreamID, MHEG5Int *serviceID)
Returns a series of integers representing basic Service Information (SI) about a service. The service is identified by means of a receiver specific "ServiceIndex". This integer can be determined by means of the SI_GetServiceIndex resident program (see 3.10.6.1, "SI_GetServiceIndex", on page 3-20). This function is used by the SI_TuneIndexInfo resident program. See UK1.06 profile section 3.10.6.3.
void MHEG5restoreReceiverDefaults(void)
Restore receiver defaults as described in section 3.12.10 of the 1.06 profile.
MHEG5Bool MHEG5parseDvbUrl(U8BIT *buffer, U32BIT length, S_DVB_LOCATOR *dvb_loc)
Parse a DAVIC style multiplex reference or UK-DTT inherritance format URL. This can be one of the fol...
E_ASPECT_RATIO DVB_MhegGetDisplayAspectRatio(void)
Get display aspect ratio.
void MHEG5setInputEventRegister(MHEG5Int inputEventRegister)
Change the input event register. This indicates which keypresses the MHEG-5 engine requires to be pas...
This file describes the interface to an MHEG5 component for CI. For example, MHEG5_StartCIApplication...
E_NW_LINK_STATUS STB_NWGetLinkStatus(void)
Get the ethernet link status.
Video Scaling / Positioning functionality.
E_MhegErr DVB_MhegDvbLocatorToIndex(S_DvbLocator *pDvbLocator, S32BIT *pServiceIndex)
Get a DVB implementation dependant service index - an integer greater or equal to 0...