MHEG5  18.9.0
MHEG5 Documentation
mh5misc.c
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright © 2014 The DTVKit Open Software Foundation Ltd (www.dtvkit.org)
3  * Copyright © 2004 Ocean Blue Software Ltd
4  * Copyright © 2000 Koninklijke Philips Electronics N.V
5  *
6  * This file is part of a DTVKit Software Component
7  * You are permitted to copy, modify or distribute this file subject to the terms
8  * of the DTVKit 1.0 Licence which can be found in licence.txt or at www.dtvkit.org
9  *
10  * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
11  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
12  * OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
13  *
14  * If you or your organisation is not a member of DTVKit then you have access
15  * to this source code outside of the terms of the licence agreement
16  * and you are expected to delete this and any associated files immediately.
17  * Further information on DTVKit, membership and terms can be found at www.dtvkit.org
18  *******************************************************************************/
26 /*---includes for this file--------------------------------------------------*/
27 #include <string.h>
28 #include "mh5base.h"
29 #include "mh5profile.h"
30 #include "mh5misc.h"
31 #include "mh5debug.h"
32 #include "mh5parse.h"
33 #include "mh5stream.h"
34 #include "mh5memory.h"
35 #include "mg_video.h"
36 #include "dvb_video.h"
37 #include "glue_main.h"
38 #include "dvb_service.h"
39 #ifndef CI_PLUS_ONLY
40  #include "glue_dsmcc.h"
41 #endif
42 #include "mh5control.h"
43 
44 #ifdef INCLUDE_IC
45 #include "mh5queue.h"
46 #include "stb_net.h"
47 #ifdef INCLUDE_FREESAT
48 #include <openssl/sha.h>
49 #include <openssl/rsa.h>
50 #include <openssl/evp.h>
51 #include <openssl/x509.h>
52 #endif /* INCLUDE_FREESAT */
53 #endif /* INCLUDE_IC */
54 #ifdef INCLUDE_CI_PLUS
55 #include "mheg5_ci.h"
56 #include "dvb_ci.h"
57 #endif
58 
59 /*---constant definitions for this file--------------------------------------*/
60 #define MAX_NDX_MAP 8
61 #define MAX_WAI_LEN 256
62 
63 #define MAX_PROMPT 50
64 
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
69 
70 
71 /*---local typedef structs for this file-------------------------------------*/
72 
73 /*---local (static) variable declarations for this file----------------------*/
74 
75 #ifdef INCLUDE_IC
76 static MHEG5Int currentICStatus = -1;
77 #ifdef INCLUDE_ICS
78 static U8BIT guidanceMessage[MAX_PROMPT * 4 + 1];
79 #endif
80 #endif
81 
82 
83 /*---local function definitions----------------------------------------------*/
84 
85 /*---global function definitions---------------------------------------------*/
86 
87 #ifdef INCLUDE_FREESAT
88 static U16BIT EncodeBase64(U8BIT *data, U16BIT len, U8BIT *result);
89 #endif
90 
91 extern void MHEG5setInputEventRegister(MHEG5Int inputEventRegister);
92 
107 {
108  MHEG5Bool rtn_val = MHEG5TRUE;
109 
110  assert( buffer != NULL && length != 0);
111 
112  /* URL is dvb://<original network id>.[<transport stream id>].<service id> */
113  if (strncmp((char *)buffer, (char *)"dvb://", 6) == 0)
114  {
115  rtn_val = MHEG5parseDvbUrl( buffer + 6, length - 6, multiplexRef );
116  }
117  else if (strncmp((char *)buffer, (char *)"rec://svc/", 10) == 0)
118  {
119  buffer += 10;
120 
121  /* URL is rec://svc/def */
122  if (strncmp((char *)buffer, (char *)"def", 3) == 0)
123  {
124  MHEG5GetDefaultService(multiplexRef);
125  }
126  /* URL is rec://svc/cur */
127  else if (strncmp((char *)buffer, (char *)"cur", 3) == 0)
128  {
129  if (!MHEG5streamGetCurrentService(multiplexRef))
130  {
131  TRACE(TSTRM, ("svc/cur is default service %d", multiplexRef->service_id))
132  }
133  }
134  /* URL is rec://svc/lcn/<LCN> */
135  else if (strncmp((char *)buffer, (char *)"lcn/", 4) == 0 &&
136  length > 14)
137  {
138  S_DvbLocator dvbLocator;
139  int lcn;
140 
141  lcn = MHEG5parseLcn( buffer + 4, buffer + length - 10 );
142 
143  if ((lcn != -1) &&
144  (DVB_MhegLcnToDvbLocator(lcn, &dvbLocator) == MHERR_OK))
145  {
146  /* URL was valid. Copy into the multiplex reference */
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;
150  }
151  else
152  {
153  rtn_val = MHEG5FALSE;
154  }
155  }
156 #ifdef INCLUDE_FREESAT
157  else if (strncmp((char *)buffer, (char *)"fsi/", 4) == 0 &&
158  length > 14)
159  {
160  S_DvbLocator dvbLocator;
161  int fsi;
162 
163  /*reusing the LCN parser for FSI (both just a decimal number)*/
164  fsi = MHEG5parseLcn( buffer + 4, buffer + length - 10 );
165 
166  if ((fsi != -1) &&
167  (DVB_MhegGetFSILocator(fsi, &dvbLocator) == MHERR_OK))
168  {
169  /* URL was valid. Copy into the multiplex reference */
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;
173  }
174  else
175  {
176  rtn_val = MHEG5FALSE;
177  }
178  }
179 #endif
180  else
181  {
182  rtn_val = MHEG5FALSE;
183  }
184  }
185  else
186  {
187  rtn_val = MHEG5FALSE;
188  }
189  TRACE(TSTRM, ("name=%s -> srv_id=0x%x (%d)", buffer, multiplexRef->service_id, multiplexRef->service_id))
190 
191  return rtn_val;
192 }
193 
207 {
208  S_DvbLocator dvbLocator;
209  S_DVB_LOCATOR multiplexRef;
210  S32BIT serviceIndex = -1;
211 
212  /* Convert from URL string to multiplex reference */
213  if (serviceReference->data && serviceReference->len &&
214  MHEG5parseUrl(serviceReference->data, serviceReference->len, &multiplexRef))
215  {
216  /* Copy multiplex reference to dvb locator */
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;
220  /* Get the service index from the controlling environment */
221  TRACE(TTUNE, ("net_id=%d trns_id=%d serv_id=%d",
222  dvbLocator.original_network_id, dvbLocator.transport_stream_id, dvbLocator.service_id))
223  if (DVB_MhegDvbLocatorToIndex(&dvbLocator, &serviceIndex) != MHERR_OK)
224  {
225  serviceIndex = -1;
226  }
227  }
228 
229  TRACE(TTUNE, (" %.*s --> index=%x", serviceReference->len, serviceReference->data, serviceIndex));
230 
231  return serviceIndex;
232 }
233 
234 #ifndef CI_PLUS_ONLY
235 
245 {
246  MHEG5String result;
247  S_STRING nbInfo;
248 
249  if (!MH5GlueSiqNetBootInfo(&nbInfo))
250  {
251  /* Boot info was not found */
252  *InfoResultVal = MHEG5FALSE;
253  result.len = 0;
254  result.data = NULL;
255  }
256  else
257  {
258  MHEG5String tmp;
259 
260  /* Boot info was found */
261  *InfoResultVal = MHEG5TRUE;
262 
263  tmp.len = nbInfo.zlen;
264  tmp.data = nbInfo.zptr;
265 
266  result = MHEG5stringCopy(tmp);
267  }
268  return result;
269 }
270 
271 #endif
272 
273 
281 {
283  {
284  return 1;
285  }
286  else
287  {
288  return 2;
289  }
290 }
291 
311 MHEG5Bool MHEG5GetBasicSI(MHEG5Int serviceIndex, MHEG5Int *networkID,
312  MHEG5Int *origNetworkID, MHEG5Int *transportStreamID,
313  MHEG5Int *serviceID)
314 {
315  S_DvbLocation location;
316  MHEG5Bool rc = MHEG5FALSE;
317 
318  if (DVB_MhegIndexToDvbLocation((U32BIT) serviceIndex, &location) == MHERR_OK)
319  {
320  *networkID = location.network_id;
321  *origNetworkID = location.original_network_id;
322  *transportStreamID = location.transport_stream_id;
323  *serviceID = location.service_id;
324  rc = MHEG5TRUE;
325  }
326  else
327  {
328  *networkID = 0;
329  *origNetworkID = 0;
330  *transportStreamID = 0;
331  *serviceID = 0;
332  }
333 
334  return rc;
335 }
336 
337 #ifdef INCLUDE_CI_PLUS
338 
351 {
352  BOOLEAN result;
353 
354  if (request)
355  {
357  }
358  else
359  {
361  }
362 
363  if (result)
364  {
365  return MHEG5TRUE;
366  }
367 
368  return MHEG5FALSE;
369 }
370 
383 {
384  /* Currently we just pass the request on to the external app
385  We may want to be more clever in the future*/
387 }
388 
389 #endif /* INCLUDE_CI_PLUS */
390 
391 
398 {
400 
401  /* Widescreen Alignment - default centre cutout (4:3) */
403 
404  /* Subtitle Mode */
406 
407 #ifndef CI_PLUS_ONLY
409 #endif /* CI_PLUS_ONLY*/
410 
411  /* Reset the input event register to 0, indicating that MHEG-5 will
412  * not process up, down, left, right, select and digits.
413  */
415 }
416 
417 #ifdef INCLUDE_IC
418 
426 void MHEG5getICStatus(MHEG5Int *icStatus)
427 {
428  if (currentICStatus == -1)
429  {
430  switch (STB_NWGetLinkStatus())
431  {
432  case NW_LINK_ACTIVE:
433  currentICStatus = 0;
434  break;
435  case NW_LINK_INACTIVE:
436  currentICStatus = 1;
437  break;
438  case NW_LINK_DISABLED:
439  default:
440  currentICStatus = 2;
441  break;
442  }
443  }
444 
445  *icStatus = currentICStatus;
446 }
447 
455 void MHEG5clearICStatus(void)
456 {
457  /* Set status to "unknown" */
458  currentICStatus = -1;
459 }
460 
461 void MHEG5changedICStatus(void)
462 {
463  /* Set status to "unknown" */
464  currentICStatus = -1;
465  MHEG5sendAppEngineEvent( EE_IC_STATUS_CHANGED );
466 }
467 
473 void MHEG5isConnectionEnabled(MHEG5Bool *enabled)
474 {
475  BOOLEAN isAllowed;
476 #ifdef INCLUDE_FREESAT
477  S32BIT service_index;
478  service_index = MHEG5GetCurrentServiceIndex();
479  DVB_MhegIsConnectionAllowed(service_index, &isAllowed);
480 #else
481  isAllowed = TRUE;
482 #endif
483  if (isAllowed && (STB_NWGetLinkStatus() == NW_LINK_ACTIVE))
484  {
485  *enabled = MHEG5TRUE;
486  }
487  else
488  {
489  *enabled = MHEG5FALSE;
490  }
491 }
492 
493 #ifdef INCLUDE_ICS
494 
499 MHEG5Bool MHEG5IsPinRequired(void)
500 {
501  MHEG5Bool required = MHEG5TRUE;
502 #ifdef INCLUDE_FREESAT
503  E_ICSPinReq status;
504  DVB_MhegGetPINRequirement(&status);
505  if ( status == MHEG5_ICS_PIN_REQ_NEVER )
506  {
507  required = MHEG5FALSE;
508  }
509 #else
510  E_ICSPinSupport support;
511  DVB_MhegGetPINSupport(&support);
512  if (support != MHEG5_ICS_PIN_SUPPORT_ENABLED)
513  {
514  required = MHEG5FALSE;
515  }
516  TRACE(TICS,("PIN support %d %d",support,required))
517 #endif
518  return required;
519 }
520 
521 
529 MHEG5Bool MHEG5promptForGuidance(MHEG5String *restriction, MHEG5Bool show)
530 {
531  U8BIT *out;
532  U8BIT byte;
533  U32BIT len;
534  U16BIT index, count;
535  U32BIT ch = 0;
536  enum
537  {
538  S_START,
539  S_MARKUP,
540  S_UTF_END,
541  S_UTF_3,
542  S_UTF_4,
543  S_DROP,
544  S_RESYNC
545  } state;
546 
547  out = guidanceMessage;
548 
549  if (restriction != NULL)
550  {
551  index = 0;
552  count = 0;
553  state = S_START;
554  len = restriction->len;
555 
556  /* Copy restriction to local buffer while removing unrecognised character
557  * and markup sequences.
558  */
559  while (index < len)
560  {
561  byte = restriction->data[index];
562  switch (state)
563  {
564  case S_START:
565  if (byte == 0x1b)
566  {
567  state = S_MARKUP;
568  }
569  else if (byte <= 0x7f)
570  {
571  if (count < MAX_PROMPT)
572  {
573  *out++ = byte;
574  ++count;
575  }
576  }
577  else if ((byte & 0xe0) == 0xc0)
578  {
579  /* 2-byte UTF-8 sequence */
580  ch = byte & 0x1f;
581  state = S_UTF_END;
582  }
583  else if ((byte & 0xf0) == 0xe0)
584  {
585  /* 3-byte UTF-8 sequence */
586  ch = byte & 0x0f;
587  state = S_UTF_3;
588  }
589  else if ((byte & 0xf8) == 0xf0)
590  {
591  /* 4-byte UTF-8 sequence */
592  ch = byte & 0x07;
593  state = S_UTF_4;
594  }
595  break;
596  case S_MARKUP:
597  if (byte >= 0x40 && byte <= 0x5e)
598  {
599  /* Sequence 0x1b T N b1 b2 ... bN */
600  if (index + (U16BIT)2 < (U16BIT)len)
601  {
602  /* Skip sequence */
603  index += 2 + restriction->data[index + 2];
604  state = S_START;
605  }
606  else
607  {
608  state = S_DROP;
609  }
610  }
611  else if (byte >= 0x60 && byte <= 0x7e)
612  {
613  /* Sequence 0x1b T - skip */
614  ++index;
615  state = S_START;
616  }
617  else
618  {
619  /* Unknown escape sequence */
620  state = S_RESYNC;
621  }
622  break;
623  case S_UTF_3:
624  if ((byte & 0xc0) == 0x80)
625  {
626  /* 2nd byte from the end */
627  ch <<= 6;
628  ch |= byte & 0x3f;
629  state = S_UTF_END;
630  }
631  else
632  {
633  /* Invalid UTF-8 sequence */
634  state = S_RESYNC;
635  }
636  break;
637  case S_UTF_4:
638  if ((byte & 0xc0) == 0x80)
639  {
640  /* 3rd byte from the end */
641  ch <<= 6;
642  ch |= byte & 0x3f;
643  state = S_UTF_3;
644  }
645  else
646  {
647  /* Invalid UTF-8 sequence */
648  state = S_RESYNC;
649  }
650  break;
651  case S_UTF_END:
652  if ((byte & 0xc0) == 0x80)
653  {
654  /* Last UTF-8 byte */
655  ch <<= 6;
656  ch |= byte & 0x3f;
657 
658  if (count < MAX_PROMPT)
659  {
660  /* Re-encode character */
661  if (ch <= 0x7f)
662  {
663  *out++ = (U8BIT)ch;
664  }
665  else if (ch <= 0x7ff)
666  {
667  *out++ = 0xc0 | (U8BIT)(ch >> 6);
668  *out++ = 0x80 | (U8BIT)(ch & 0x3f);
669  }
670  else if (ch <= 0xffff)
671  {
672  *out++ = 0xe0 | (U8BIT)(ch >> 12);
673  *out++ = 0x80 | ((ch >> 6) & 0x3f);
674  *out++ = 0x80 | (ch & 0x3f);
675  }
676  else
677  {
678  *out++ = 0xe0 | (U8BIT)(ch >> 18);
679  *out++ = 0x80 | ((ch >> 12) & 0x3f);
680  *out++ = 0x80 | ((ch >> 6) & 0x3f);
681  *out++ = 0x80 | (ch & 0x3f);
682  }
683  ++count;
684  }
685  state = S_START;
686  }
687  else
688  {
689  /* Invalid UTF-8 sequence */
690  state = S_RESYNC;
691  }
692  break;
693  case S_DROP:
694  /* Just drop everything */
695  break;
696  case S_RESYNC:
697  if ((((byte & 0x80) == 0x00) && (byte != 0x00)) ||
698  ((byte & 0xe0) == 0xc0) ||
699  ((byte & 0xf0) == 0xe0) ||
700  ((byte & 0xf8) == 0xf0))
701  {
702  /* Valid first UTF-8 byte: make sure the character is
703  * re-processed and start again.
704  */
705  --index;
706  state = S_START;
707  }
708  break;
709  }
710  ++index;
711  }
712  }
713  *out = '\0';
714 
715  return (DVB_MhegPromptForGuidance(guidanceMessage, show ? TRUE : FALSE) == MHERR_OK)? MHEG5TRUE : MHEG5FALSE;
716 }
717 
718 #ifndef INCLUDE_FREESAT
719 
727 MHEG5Bool MHEG5GetPINSupport(MHEG5Int *support)
728 {
729  E_ICSPinSupport pinSupport;
730  MHEG5Bool success;
731  E_MhegErr err;
732 
733  success = MHEG5FALSE;
734 
735  err = DVB_MhegGetPINSupport(&pinSupport);
736  if (err == MHERR_OK)
737  {
738  switch (pinSupport)
739  {
741  *support = -1;
742  success = MHEG5TRUE;
743  break;
745  *support = 0;
746  success = MHEG5TRUE;
747  break;
749  *support = 1;
750  success = MHEG5TRUE;
751  break;
752  default:
753  ;
754  }
755  }
756 
757  return success;
758 }
759 
760 #else /* INCLUDE_FREESAT */
761 
769 MHEG5Bool MHEG5GetPINRequirement(MHEG5Int *status)
770 {
771  E_ICSPinReq pinStatus;
772  MHEG5Bool success;
773 
774  success = MHEG5FALSE;
775 
776  DVB_MhegGetPINRequirement(&pinStatus);
777  switch (pinStatus)
778  {
780  *status = 0;
781  success = MHEG5TRUE;
782  break;
784  *status = 1;
785  success = MHEG5TRUE;
786  break;
788  *status = 2;
789  success = MHEG5TRUE;
790  break;
791  default:
792  ;
793  }
794 
795  return success;
796 }
797 
805 MHEG5Bool MHEG5GetFSIServiceReference(MHEG5Int serviceIndex, MHEG5Int *fsi, MHEG5String *fsiString)
806 {
807  MHEG5Byte fsiChars[5];
808  U16BIT fsiBuffer;
809  int i;
810 
811  if (DVB_MhegGetFSIServiceReference(serviceIndex, &fsiBuffer) == MHERR_OK)
812  {
813  /*one more check that the returned FSI is within the valid range*/
814  if (fsiBuffer > 0x7ff || fsiBuffer < 1)
815  {
816  return MHEG5FALSE;
817  }
818 
819  fsiString->len = 19;
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;
825 
826  for (i = 0; i < 5; i++)
827  {
828  if (fsiChars[i] == '0')
829  {
830  fsiString->len--;
831  }
832  else
833  {
834  break;
835  }
836  }
837 
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);
841  *fsi = fsiBuffer;
842  }
843  else
844  {
845  return MHEG5FALSE;
846  }
847 
848  return MHEG5TRUE;
849 }
850 
859 MHEG5Bool MHEG5ValidatePIN(MHEG5String *pin, MHEG5Int *status)
860 {
861  E_ICSPinStatus pinStatus;
862  MHEG5Bool success;
863 
864  success = MHEG5FALSE;
865 
866  DVB_MhegValidatePIN(pin->data, &pinStatus);
867  switch (pinStatus)
868  {
870  *status = -1;
871  success = MHEG5TRUE;
872  break;
874  *status = 0;
875  success = MHEG5TRUE;
876  break;
878  *status = 1;
879  success = MHEG5TRUE;
880  break;
881  default:
882  ;
883  }
884 
885  return success;
886 }
887 
897 MHEG5Bool MHEG5ComputePrivateSignature(MHEG5String *data, MHEG5String *result)
898 {
899  /* workspace */
900  U8BIT *workspace;
901  U8BIT *ws_salt;
902  U8BIT *ws_data;
903  U8BIT *ws_digest;
904  U8BIT *ws_key;
905  U8BIT *ws_signature;
906 
907  /* OpenSSL */
908  EVP_MD_CTX ctx;
909  BIO *bio;
910  RSA *rsa;
911  unsigned int siglen = RSA_SIGNATURE_SIZE;
912  int rc;
913 
914  /* General */
915  U32BIT version;
916  char verstr[MAX_VERSION_LEN];
917  U16BIT keylen;
918  U32BIT reslen, offset;
919  U16BIT i;
920  BOOLEAN success;
921 
922  success = FALSE;
923  result->data = NULL;
924  result->len = 0;
925 
926  /* Workspace = salt + data + digest + key + signature */
927  workspace = MHEG5getMem(RSA_SALT_SIZE + data->len + SHA_DIGEST_LENGTH + MAX_RSA_KEY_SIZE + RSA_SIGNATURE_SIZE);
928  if (workspace != NULL)
929  {
930  ws_salt = workspace;
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;
935 
936  /* Generate salt - "high quality" random not required */
937  for (i = 0; i < 10; i++)
938  {
939  ws_salt[i] = (U8BIT)MHEG5random();
940  }
941 
942  /* Append MAC address */
943  DVB_MhegGetMACAddress(ws_salt + 10);
944 
945  /* Append data */
946  memcpy(ws_data, data->data, data->len);
947 
948  /* Generate SHA-1 hash */
949  EVP_DigestInit(&ctx, EVP_sha1());
950  EVP_DigestUpdate(&ctx, workspace, RSA_SALT_SIZE + data->len);
951  EVP_DigestFinal(&ctx, ws_digest, NULL);
952 
953  /* Sign hash (encrypt using private key) */
954  DVB_MhegGetPrivateKey(ws_key, MAX_RSA_KEY_SIZE, &keylen, &version);
955  if (keylen <= MAX_RSA_KEY_SIZE)
956  {
957  bio = BIO_new_mem_buf(ws_key, keylen);
958  if (bio != NULL)
959  {
960  rsa = d2i_RSAPrivateKey_bio(bio, NULL);
961 
962  /* Make sure it's a 1024-bit key */
963  if (rsa != NULL && RSA_size(rsa) == RSA_SIGNATURE_SIZE)
964  {
965  /* Calculate signature */
966  rc = RSA_sign(NID_sha1, ws_digest, SHA_DIGEST_LENGTH,
967  ws_signature, &siglen, rsa);
968  if (rc == 1)
969  {
970  success = TRUE;
971  }
972  RSA_free(rsa);
973  }
974  BIO_free(bio);
975  }
976  }
977  }
978 
979  if (success)
980  {
981  /* Create result string */
982  sprintf(verstr, "%u", version);
983  reslen = strlen(verstr) + 1 + 24 + 1 + 172;
984 
985  result->len = reslen;
986  result->data = (U8BIT *)STR_DataAlloc(result->len + 1);
987  if (result->data != NULL)
988  {
989  strcpy((char *)result->data, verstr);
990  offset = strlen(verstr);
991  result->data[offset] = ':';
992  offset++;
993  offset += EncodeBase64(ws_salt, RSA_SALT_SIZE,
994  result->data + offset);
995  result->data[offset] = ':';
996  offset++;
997  offset += EncodeBase64(ws_signature, siglen,
998  result->data + offset);
999  result->data[offset] = '\0';
1000  }
1001  }
1002 
1003  if (workspace != NULL)
1004  {
1005  MHEG5freeMem(workspace);
1006  }
1007 
1008  return MHEG5TRUE;
1009 }
1010 
1018 static U16BIT EncodeBase64(U8BIT *data, U16BIT len, U8BIT *result)
1019 {
1020  static char *base64 =
1021  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1022  "abcdefghijklmnopqrstuvwxyz"
1023  "0123456789+/=";
1024  U16BIT i;
1025 
1026  for (i = 0; i < len; i += 3)
1027  {
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];
1032  }
1033 
1034  i -= 3;
1035  switch (len - i)
1036  {
1037  case 2:
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] = '=';
1042  break;
1043  case 1:
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] = '=';
1048  break;
1049  case 0:
1050  /* all done */
1051  break;
1052  }
1053 
1054  return (len + 2) / 3 * 4;
1055 }
1056 
1057 #endif /* INCLUDE_FREESAT */
1058 
1059 #endif /* INCLUDE_ICS */
1060 
1061 #endif /* INCLUDE_IC */
1062 
1063 
1064 #ifdef INCLUDE_CONNECTED_TV
1065 /*******************************************************************************
1066 *@begin
1067 * NAME: MHEG5ApplicationLaunch
1068 * Causes a new (non-MHEG-5) application to be started.
1069 *
1070 * Returns : Nothing
1071 *
1072 * Parameter Flow Description
1073 * ------------------------------------------------------------------------------
1074 * location IN Location of the application to run
1075 * args IN Application arguments (encoded string)
1076 *
1077 * Externals Flow Usage
1078 * ------------------------------------------------------------------------------
1079 *
1080 * Additional information:
1081 *
1082 *@end
1083 *******************************************************************************/
1084 void MHEG5ApplicationLaunch(MHEG5String *location, MHEG5String *args)
1085 {
1086  DVB_MhegApplicationLaunch(location->data, args->data);
1087 }
1088 #endif /* INCLUDE_CONNECTED_TV */
#define RSA_SALT_SIZE
Definition: mh5misc.c:65
Implement MHEG5 engine control functions (i.e. start/stop etc)
void DVB_MhegSetVideoAlignment(E_VIDEO_ASPECT_MODE mode)
unsigned long MHEG5random(void)
Calculate and return a psuedo random number.
Definition: mh5base.c:1071
Basis MHEG5 data types.
void MHEG5sendAppEngineEvent(E_ENGINE_EVENT engine_event)
Store an Engine event in the asynchronous event queue.
Definition: mh5queue.c:1633
U16BIT network_id
Definition: dvb_service.h:70
U16BIT original_network_id
Definition: dvb_service.h:64
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...
Definition: mh5misc.c:206
void MG_SetSubtitleMode(MHEG5Bool subtitleOn)
Set the current subtitle display mode to be either On or Off, Should only have an impact if subtitles...
Definition: mg_video.c:89
const char * data
Definition: mh5gate.c:56
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...
unsigned char * STR_DataAlloc(unsigned int size)
Definition: glue_memory.c:596
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.
#define MHEG5getMem
Definition: glue_memory.h:93
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.
Miscellaneous.
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...
Definition: mh5stream.c:1098
U16BIT transport_stream_id
Definition: dvb_service.h:66
void MHEG5GetDefaultService(S_DVB_LOCATOR *dvb_locator)
Definition: glue_main.c:1186
U8BIT * zptr
Definition: dtvstring.h:31
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...
Definition: mh5misc.c:106
U16BIT transport_stream_id
Definition: dvblocator.h:33
E_MhegErr
Definition: mherrors.h:28
MHEG5String MHEG5stringCopy(MHEG5String source)
<Function description>="">
Definition: mh5base.c:574
BOOLEAN MH5GlueSiqNetBootInfo(S_STRING *nbinfo)
Get current MHEG net boot info existance and nb info string.
Definition: glue_dsmcc.c:556
U16BIT original_network_id
Definition: dvblocator.h:32
uint8_t U8BIT
Definition: techtype.h:82
long MHEG5Int
Definition: mh5base.h:73
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-...
#define MHEG5freeMem
Definition: glue_memory.h:94
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...
Definition: mh5control.c:882
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.
Definition: mh5misc.c:244
short MHEG5Bool
Definition: mh5base.h:71
unsigned char MHEG5Byte
Definition: mh5base.h:74
#define MAX_PROMPT
Definition: mh5misc.c:63
E_ICSPinSupport
Definition: dvb_ics.h:45
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.
MHEG5Byte * data
Definition: mh5base.h:85
int len
Definition: mh5gate.c:57
E_ICSPinReq
Definition: dvb_ics.h:52
int32_t S32BIT
Definition: techtype.h:87
#define MHEG5TRUE
Definition: mh5base.h:49
MHEG5Int MHEG5GetDisplayAspectRatio(void)
Find the setting of the attached display&#39;s aspect ratio This function is used by the GetDisplayAspect...
Definition: mh5misc.c:280
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...
#define RSA_SIGNATURE_SIZE
Definition: mh5misc.c:66
uint16_t U16BIT
Definition: techtype.h:84
Mheg5 logging and debug printing.
U16BIT service_id
Definition: dvblocator.h:34
#define MAX_RSA_KEY_SIZE
Definition: mh5misc.c:68
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.
Definition: mh5misc.c:311
#define MAX_VERSION_LEN
Definition: mh5misc.c:67
redirection include
void MHEG5restoreReceiverDefaults(void)
Restore receiver defaults as described in section 3.12.10 of the 1.06 profile.
Definition: mh5misc.c:397
Definition: mg_png.c:52
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...
Definition: mh5parse.c:153
#define FALSE
Definition: techtype.h:68
E_ICSPinStatus
Definition: dvb_ics.h:59
MHEG5Int len
Definition: mh5base.h:84
Platform Network API.
U8BIT BOOLEAN
Definition: techtype.h:99
E_ASPECT_RATIO DVB_MhegGetDisplayAspectRatio(void)
Get display aspect ratio.
U32BIT zlen
Definition: dtvstring.h:30
#define TRUE
Definition: techtype.h:69
void MHEG5setInputEventRegister(MHEG5Int inputEventRegister)
Change the input event register. This indicates which keypresses the MHEG-5 engine requires to be pas...
Definition: mh5keypress.c:320
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.
S32BIT MHEG5GetCurrentServiceIndex(void)
Definition: glue_main.c:1196
U16BIT service_id
Definition: dvb_service.h:68
E_MhegErr DVB_MhegDvbLocatorToIndex(S_DvbLocator *pDvbLocator, S32BIT *pServiceIndex)
Get a DVB implementation dependant service index - an integer greater or equal to 0...
#define MHEG5FALSE
Definition: mh5base.h:48
int MHEG5parseLcn(U8BIT *buf, U8BIT *end)
Definition: mh5parse.c:267
uint32_t U32BIT
Definition: techtype.h:86
#define TRACE(t, x)
Definition: glue_debug.h:118