]> git.basschouten.com Git - openhab-addons.git/blob
c47d0b97959c78ec3f92fabac2dbf3ae28c87fbe
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.magentatv.internal.handler;
14
15 import static org.openhab.binding.magentatv.internal.MagentaTVBindingConstants.*;
16 import static org.openhab.binding.magentatv.internal.MagentaTVUtil.*;
17
18 import java.nio.charset.StandardCharsets;
19 import java.security.MessageDigest;
20 import java.security.NoSuchAlgorithmException;
21 import java.text.MessageFormat;
22 import java.util.HashMap;
23 import java.util.StringTokenizer;
24
25 import org.eclipse.jdt.annotation.NonNullByDefault;
26 import org.eclipse.jetty.client.HttpClient;
27 import org.openhab.binding.magentatv.internal.MagentaTVException;
28 import org.openhab.binding.magentatv.internal.config.MagentaTVDynamicConfig;
29 import org.openhab.binding.magentatv.internal.network.MagentaTVHttp;
30 import org.openhab.binding.magentatv.internal.network.MagentaTVNetwork;
31 import org.openhab.binding.magentatv.internal.network.MagentaTVOAuth;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 /**
36  * The {@link MagentaTVControl} implements the control functions for the
37  * receiver.
38  *
39  * @author Markus Michels - Initial contribution
40  */
41 @NonNullByDefault
42 public class MagentaTVControl {
43     private final Logger logger = LoggerFactory.getLogger(MagentaTVControl.class);
44     private static final HashMap<String, String> KEY_MAP = new HashMap<>();
45
46     private final MagentaTVNetwork network;
47     private final MagentaTVHttp http = new MagentaTVHttp();
48     private final MagentaTVOAuth oauth;
49     private final MagentaTVDynamicConfig config;
50     private boolean initialized = false;
51     private String thingId = "";
52
53     public MagentaTVControl() {
54         config = new MagentaTVDynamicConfig();
55         network = new MagentaTVNetwork();
56         oauth = new MagentaTVOAuth(new HttpClient());
57     }
58
59     public MagentaTVControl(MagentaTVDynamicConfig config, MagentaTVNetwork network, HttpClient httpClient) {
60         this.thingId = config.getFriendlyName();
61         this.network = network;
62         this.oauth = new MagentaTVOAuth(httpClient);
63         this.config = config;
64         this.config.setTerminalID(computeMD5(network.getLocalMAC().toUpperCase() + config.getUDN()));
65         this.config.setLocalIP(network.getLocalIP());
66         this.config.setLocalMAC(network.getLocalMAC());
67         initialized = true;
68     }
69
70     public boolean isInitialized() {
71         return initialized;
72     }
73
74     public void setThingId(String thingId) {
75         this.thingId = thingId;
76     }
77
78     /**
79      * Returns the thingConfig - the Control class adds various attributes of the
80      * discovered device (like the MR model)
81      *
82      * @return thingConfig
83      */
84     public MagentaTVDynamicConfig getConfig() {
85         return config;
86     }
87
88     /**
89      * Initiate OAuth authentication
90      *
91      * @param accountName T-Online user id
92      * @param accountPassword T-Online password
93      * @return true: successful, false: failed
94      *
95      * @throws MagentaTVException
96      */
97     public String getUserId(String accountName, String accountPassword) throws MagentaTVException {
98         return oauth.getUserId(accountName, accountPassword);
99     }
100
101     /**
102      * Retries the device properties. This will result in an Exception if the device
103      * is not connected.
104      *
105      * Response is returned in XMl format, e.g.:
106      * <?xml version="1.0"?> <root xmlns="urn:schemas-upnp-org:device-1-0">
107      * <specVersion><major>1</major><minor>0</minor></specVersion> <device>
108      * <UDN>uuid:70dff25c-1bdf-5731-a283-XXXXXXXX</UDN>
109      * <friendlyName>DMS_XXXXXXXXXXXX</friendlyName>
110      * <deviceType>urn:schemas-upnp-org:device:tvdevice:1</deviceType>
111      * <manufacturer>Zenterio</manufacturer> <modelName>MR401B</modelName>
112      * <modelNumber>R01A5</modelNumber> <productVersionNumber>&quot; 334
113      * &quot;</productVersionNumber> <productType>stb</productType>
114      * <serialNumber></serialNumber> <X_wakeOnLan>0</X_wakeOnLan> <serviceList>
115      * <service> <serviceType>urn:dial-multiscreen-org:service:dial:1</serviceType>
116      * <serviceId>urn:dial-multiscreen-org:service:dial</serviceId> </service>
117      * </serviceList> </device> </root>
118      *
119      * @return true: device is online, false: device is offline
120      * @throws MagentaTVException
121      */
122     public boolean checkDev() throws MagentaTVException {
123         logger.debug("{}: Check device {} ({}:{})", thingId, config.getTerminalID(), config.getIpAddress(),
124                 config.getPort());
125
126         String url = MessageFormat.format(CHECKDEV_URI, config.getIpAddress(), config.getPort(),
127                 config.getDescriptionUrl());
128         String result = http.httpGet(buildHost(), url, "");
129         if (result.contains("<modelName>")) {
130             config.setModel(substringBetween(result, "<modelName>", "</modelName>"));
131         }
132         if (result.contains("<modelNumber>")) {
133             config.setHardwareVersion(substringBetween(result, "<modelNumber>", "</modelNumber>"));
134         }
135         if (result.contains("<X_wakeOnLan>")) {
136             String wol = substringBetween(result, "<X_wakeOnLan>", "</X_wakeOnLan>");
137             config.setWakeOnLAN(wol);
138             logger.debug("{}: Wake-on-LAN is {}", thingId, "0".equals(wol) ? "disabled" : "enabled");
139         }
140         if (result.contains("<productVersionNumber>")) {
141             String version;
142             if (result.contains("<productVersionNumber>&quot; ")) {
143                 version = substringBetween(result, "<productVersionNumber>&quot; ", " &quot;</productVersionNumber>");
144             } else {
145                 version = substringBetween(result, "<productVersionNumber>", "</productVersionNumber>");
146             }
147             config.setFirmwareVersion(version);
148         }
149         if (result.contains("<friendlyName>")) {
150             String friendlyName = result.substring(result.indexOf("<friendlyName>") + "<friendlyName>".length(),
151                     result.indexOf("</friendlyName>"));
152             config.setFriendlyName(friendlyName);
153         }
154         if (result.contains("<UDN>uuid:")) {
155             String udn = result.substring(result.indexOf("<UDN>uuid:") + "<UDN>uuid:".length(),
156                     result.indexOf("</UDN>"));
157             if (config.getUDN().isEmpty()) {
158                 config.setUDN(udn);
159             }
160         }
161         logger.trace("{}: Online status verified for device {}:{}, UDN={}", thingId, config.getIpAddress(),
162                 config.getPort(), config.getUDN());
163         return true;
164     }
165
166     /**
167      *
168      * Sends a SUBSCRIBE request to the MR. This also defines the local callback url
169      * used by the MR to return the pairing code and event information.
170      *
171      * Subscripbe to event channel a) receive the pairing code b) receive
172      * programInfo and playStatus events after successful paring
173      *
174      * SUBSCRIBE /upnp/service/X-CTC_RemotePairing/Event HTTP/1.1\r\n HOST:
175      * $remote_ip:$remote_port CALLBACK: <http://$local_ip:$local_port/>\r\n // NT:
176      * upnp:event\r\n // TIMEOUT: Second-300\r\n // CONNECTION: close\r\n // \r\n
177      *
178      * @throws MagentaTVException
179      */
180     public void subscribeEventChannel() throws MagentaTVException {
181         String sid = "";
182         logger.debug("{}: Subscribe Event Channel (terminalID={}, {}:{}", thingId, config.getTerminalID(),
183                 config.getIpAddress(), config.getPort());
184         String subscribe = MessageFormat.format(PAIRING_SUBSCRIBE, config.getIpAddress(), config.getPort(),
185                 network.getLocalIP(), network.getLocalPort(), PAIRING_NOTIFY_URI, PAIRING_TIMEOUT_SEC);
186         String response = http.sendData(config.getIpAddress(), config.getPort(), subscribe);
187         if (!response.contains("200 OK")) {
188             response = substringBefore(response, "SERVER");
189             throw new MagentaTVException("Unable to subscribe to pairing channel: " + response);
190         }
191         if (!response.contains(NOTIFY_SID)) {
192             throw new MagentaTVException("Unable to subscribe to pairing channel, SID missing: " + response);
193         }
194
195         StringTokenizer tokenizer = new StringTokenizer(response, "\r\n");
196         while (tokenizer.hasMoreElements()) {
197             String str = tokenizer.nextToken();
198             if (!str.isEmpty()) {
199                 if (str.contains(NOTIFY_SID)) {
200                     sid = str.substring("SID: uuid:".length());
201                     logger.debug("{}: SUBSCRIBE returned SID {}", thingId, sid);
202                     break;
203                 }
204             }
205         }
206     }
207
208     /**
209      * Send Pairing Request to the Media Receiver. The method waits for the
210      * response, but the pairing code will be received via the NOTIFY callback (see
211      * NotifyServlet)
212      *
213      * XML format for Pairing Request: <s:Envelope
214      * xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"
215      * <s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"> <s:Body>\n
216      * <u:X-pairingRequest
217      * xmlns:u=\"urn:schemas-upnp-org:service:X-CTC_RemotePairing:1\">\n
218      * <pairingDeviceID>$pairingDeviceID</pairingDeviceID>\n
219      * <friendlyName>$friendlyName</friendlyName>\n <userID>$userID</userID>\n
220      * </u:X-pairingRequest>\n </s:Body> </s:Envelope>
221      *
222      * @return true: pairing successful
223      * @throws MagentaTVException
224      */
225     public boolean sendPairingRequest() throws MagentaTVException {
226         logger.debug("{}: Send Pairing Request (deviceID={}, type={}, userID={})", thingId, config.getTerminalID(),
227                 DEF_FRIENDLY_NAME, config.getUserId());
228         resetPairing();
229
230         String soapBody = MessageFormat.format(PAIRING_SOAP_BODY, config.getTerminalID(), DEF_FRIENDLY_NAME,
231                 config.getUserId());
232         String soapXml = MessageFormat.format(SOAP_ENVELOPE, soapBody);
233         String response = http.httpPOST(buildHost(), buildReceiverUrl(PAIRING_CONTROL_URI), soapXml,
234                 PAIRING_SOAP_ACTION, CONNECTION_CLOSE);
235
236         // pairingCode will be received by the Servlet, is calls onPairingResult()
237         // Exception if request failed (response code != HTTP_OK)
238         if (!response.contains("X-pairingRequestResponse") || !response.contains("<result>")) {
239             throw new MagentaTVException("Unexpected result for pairing response: " + response);
240         }
241
242         String result = substringBetween(response, "<result>", "</result>");
243         if (!"0".equals(result)) {
244             throw new MagentaTVException("Pairing failed, result=" + result);
245         }
246
247         logger.debug("{}: Pairing initiated (deviceID={}).", thingId, config.getTerminalID());
248         return true;
249     }
250
251     /**
252      * Calculates the verifificationCode to complete pairing. This will be triggered
253      * as a result after receiving the pairing code provided by the MR. The
254      * verification code is the MD5 hash of <Pairing Code><Terminal-ID><User ID>
255      *
256      * @param pairingCode Pairing code received from the MR
257      * @return true: a new code has been generated, false: the code matches a
258      *         previous pairing
259      */
260     public boolean generateVerificationCode(String pairingCode) {
261         if (config.getPairingCode().equals(pairingCode) && !config.getVerificationCode().isEmpty()) {
262             logger.debug("{}: Pairing code ({}) refreshed, verificationCode={}", thingId, pairingCode,
263                     config.getVerificationCode());
264             return false;
265         }
266         config.setPairingCode(pairingCode);
267         String md5Input = pairingCode + config.getTerminalID() + config.getUserId();
268         config.setVerificationCode(computeMD5(md5Input).toUpperCase());
269         logger.debug("{}: VerificationCode({}): Input={}, code={}", thingId, config.getTerminalID(), md5Input,
270                 config.getVerificationCode());
271         return true;
272     }
273
274     /**
275      * Send a pairing verification request to the receiver. This is important to
276      * complete the pairing process. You should see a message like "Connected to
277      * openHAB" on your TV screen.
278      *
279      * @return true: successful, false: a non-critical error occured, caller handles
280      *         this
281      * @throws MagentaTVException
282      */
283     public boolean verifyPairing() throws MagentaTVException {
284         logger.debug("{}: Verify pairing (id={}, code={}", thingId, config.getTerminalID(),
285                 config.getVerificationCode());
286         String soapBody = MessageFormat.format(PAIRCHECK_SOAP_BODY, config.getTerminalID(),
287                 config.getVerificationCode());
288         String soapXml = MessageFormat.format(SOAP_ENVELOPE, soapBody);
289         String response = http.httpPOST(buildHost(), buildReceiverUrl(PAIRCHECK_URI), soapXml, PAIRCHECK_SOAP_ACTION,
290                 CONNECTION_CLOSE);
291
292         // Exception if request failed (response code != HTTP_OK)
293         if (!response.contains("<pairingResult>")) {
294             throw new MagentaTVException("Unexpected result for pairing verification: " + response);
295         }
296
297         String result = getXmlValue(response, "pairingResult");
298         if (!"0".equals(result)) {
299             logger.debug("{}: Pairing failed or pairing no longer valid, result={}", thingId, result);
300             resetPairing();
301             // let the caller decide how to proceed
302             return false;
303         }
304
305         if (!config.isMR400()) {
306             String enable4K = getXmlValue(response, "Enable4K");
307             String enableSAT = getXmlValue(response, "EnableSAT");
308             logger.debug("{}: Features: Enable4K:{}, EnableSAT:{}", thingId, enable4K, enableSAT);
309         }
310         return true;
311     }
312
313     /**
314      *
315      * @return true if pairing is completed (verification code was generated)
316      */
317     public boolean isPaired() {
318         // pairing was completed successful if we have the verification code
319         return !config.getVerificationCode().isEmpty();
320     }
321
322     /**
323      * Reset pairing information (e.g. when verification failed)
324      */
325     public void resetPairing() {
326         // pairing no longer valid
327         config.setPairingCode("");
328         config.setVerificationCode("");
329     }
330
331     /**
332      * Send key code to the MR (via SOAP request). A key code could be send by it's
333      * code (0x.... notation) or with a symbolic namne, which will first be mapped
334      * to the key code
335      *
336      * XML format for Send Key
337      *
338      * <s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"
339      * s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"> <s:Body>\n
340      * <u:X_CTC_RemoteKey
341      * xmlns:u=\"urn:schemas-upnp-org:service:X-CTC_RemoteControl:1\">\n
342      * <InstanceID>0</InstanceID>\n
343      * <KeyCode>keyCode=$keyCode^$pairingDeviceID:$verificationCode^userID:$userID</KeyCode>\n
344      * </u:X_CTC_RemoteKey>\n </s:Body></s:Envelope>
345      *
346      * @param keyName
347      * @return true: successful, false: failed, e.g. unkown key code
348      * @throws MagentaTVException
349      */
350     public boolean sendKey(String keyName) throws MagentaTVException {
351         String keyCode = getKeyCode(keyName);
352         logger.debug("{}: Send Key {} (keyCode={}, tid={})", thingId, keyName, keyCode, config.getTerminalID());
353         if (keyCode.length() <= "0x".length()) {
354             logger.debug("{}: Key {} is unkown!", thingId, keyCode);
355             return false;
356         }
357
358         String soapBody = MessageFormat.format(SENDKEY_SOAP_BODY, keyCode, config.getTerminalID(),
359                 config.getVerificationCode(), config.getUserId());
360         String soapXml = MessageFormat.format(SOAP_ENVELOPE, soapBody);
361         logger.debug("{}: send keyCode={} to {}:{}", thingId, keyCode, config.getIpAddress(), config.getPort());
362         logger.trace("{}: sendKey terminalid={}, pairingCode={}, verificationCode={}, userId={}", thingId,
363                 config.getTerminalID(), config.getPairingCode(), config.getVerificationCode(), config.getUserId());
364         http.httpPOST(buildHost(), buildReceiverUrl(SENDKEY_URI), soapXml, SENDKEY_SOAP_ACTION, CONNECTION_CLOSE);
365         // Exception if request failed (response code != HTTP_OK)
366         // pairingCode will be received by the Servlet, is calls onPairingResult()
367         return true;
368     }
369
370     /**
371      * Select channel for TV
372      *
373      * @param channel new channel (a sequence of numbers, which will be send one by one)
374      * @return true:ok, false: failed
375      */
376     public boolean selectChannel(String channel) throws MagentaTVException {
377         logger.debug("{}: Select channel {}", thingId, channel);
378         for (int i = 0; i < channel.length(); i++) {
379             if (!sendKey("" + channel.charAt(i))) {
380                 return false;
381             }
382             try {
383                 Thread.sleep(200);
384             } catch (InterruptedException e) {
385             }
386         }
387         return true;
388     }
389
390     /**
391      * Get key code to send to receiver
392      *
393      * @param key Key for which to get the key code
394      * @return
395      */
396     private String getKeyCode(String key) {
397         if (key.contains("0x")) {
398             // direct key code
399             return key;
400         }
401         String code = KEY_MAP.get(key);
402         return code != null ? code : "";
403     }
404
405     /**
406      * Map playStatus code to string for a list of codes see
407      * http://support.huawei.com/hedex/pages/DOC1100366313CEH0713H/01/DOC1100366313CEH0713H/01/resources/dsv_hdx_idp/DSV/en/en-us_topic_0094619231.html
408      *
409      * @param playStatus Integer code parsed form json (see EV_PLAYCHG_XXX)
410      * @return playStatus as String
411      */
412     public String getPlayStatus(int playStatus) {
413         switch (playStatus) {
414             case EV_PLAYCHG_PLAY:
415                 return "playing";
416             case EV_PLAYCHG_STOP:
417                 return "stopped";
418             case EV_PLAYCHG_PAUSE:
419                 return "paused";
420             case EV_PLAYCHG_TRICK:
421                 return "tricking";
422             case EV_PLAYCHG_MC_PLAY:
423                 return "playing (MC)";
424             case EV_PLAYCHG_UC_PLAY:
425                 return "playing (UC)";
426             case EV_PLAYCHG_BUFFERING:
427                 return "buffering";
428             default:
429                 return Integer.toString(playStatus);
430         }
431     }
432
433     /**
434      * Map runningStatus code to string for a list of codes see
435      * http://support.huawei.com/hedex/pages/DOC1100366313CEH0713H/01/DOC1100366313CEH0713H/01/resources/dsv_hdx_idp/DSV/en/en-us_topic_0094619523.html
436      *
437      * @param runStatus Integer code parsed form json (see EV_EITCHG_RUNNING_XXX)
438      * @return runningStatus as String
439      */
440     public String getRunStatus(int runStatus) {
441         switch (runStatus) {
442             case EV_EITCHG_RUNNING_NOT_RUNNING:
443                 return "stopped";
444             case EV_EITCHG_RUNNING_STARTING:
445                 return "starting";
446             case EV_EITCHG_RUNNING_PAUSING:
447                 return "paused";
448             case EV_EITCHG_RUNNING_RUNNING:
449                 return "running";
450             default:
451                 return Integer.toString(runStatus);
452         }
453     }
454
455     /**
456      * builds url from the discovered IP address/port and the requested uri
457      *
458      * @param uri requested URI
459      * @return the complete URL
460      */
461     public String buildReceiverUrl(String uri) {
462         return MessageFormat.format("http://{0}:{1}{2}", config.getIpAddress(), config.getPort(), uri);
463     }
464
465     /**
466      * build host string
467      *
468      * @return formatted string (<ip_address>:<port>)
469      */
470     private String buildHost() {
471         return config.getIpAddress() + ":" + config.getPort();
472     }
473
474     /**
475      * Given a string, return the MD5 hash of the String.
476      *
477      * @param unhashed The string contents to be hashed.
478      * @return MD5 Hashed value of the String. Null if there is a problem hashing
479      *         the String.
480      */
481     public static String computeMD5(String unhashed) {
482         try {
483             byte[] bytesOfMessage = unhashed.getBytes(StandardCharsets.UTF_8);
484
485             MessageDigest md5 = MessageDigest.getInstance(HASH_ALGORITHM_MD5);
486             byte[] hash = md5.digest(bytesOfMessage);
487             StringBuilder sb = new StringBuilder(2 * hash.length);
488             for (byte b : hash) {
489                 sb.append(String.format("%02x", b & 0xff));
490             }
491
492             return sb.toString();
493         } catch (NoSuchAlgorithmException e) {
494             return "";
495         }
496     }
497
498     /**
499      * Helper to parse a Xml tag value from string without using a complex XML class
500      *
501      * @param xml Input string in the format <tag>value</tag>
502      * @param tagName The tag to find
503      * @return Tag value (between <tag> and </tag>)
504      */
505     public static String getXmlValue(String xml, String tagName) {
506         String open = "<" + tagName + ">";
507         String close = "</" + tagName + ">";
508         if (xml.contains(open) && xml.contains(close)) {
509             return substringBetween(xml, open, close);
510         }
511         return "";
512     }
513
514     /**
515      * Initialize key map (key name -> key code)
516      * "
517      * for a list of valid key codes see
518      * http://support.huawei.com/hedex/pages/DOC1100366313CEH0713H/01/DOC1100366313CEH0713H/01/resources/dsv_hdx_idp/DSV/en/en-us_topic_0094619112.html
519      */
520     static {
521         KEY_MAP.put("POWER", "0x0100");
522         KEY_MAP.put("MENU", "0x0110");
523         KEY_MAP.put("EPG", "0x0111");
524         KEY_MAP.put("TVMENU", "0x0454");
525         KEY_MAP.put("VODMENU", "0x0455");
526         KEY_MAP.put("TVODMENU", "0x0456");
527         KEY_MAP.put("NVODMENU", "0x0458");
528         KEY_MAP.put("INFO", "0x010C");
529         KEY_MAP.put("TTEXT", "0x0560");
530         KEY_MAP.put("0", "0x0030");
531         KEY_MAP.put("1", "0x0031");
532         KEY_MAP.put("2", "0x0032");
533         KEY_MAP.put("3", "0x0033");
534         KEY_MAP.put("4", "0x0034");
535         KEY_MAP.put("5", "0x0035");
536         KEY_MAP.put("6", "0x0036");
537         KEY_MAP.put("7", "0x0037");
538         KEY_MAP.put("8", "0x0038");
539         KEY_MAP.put("9", "0x0039");
540         KEY_MAP.put("SPACE", "0x0020");
541         KEY_MAP.put("POUND", "0x0069");
542         KEY_MAP.put("STAR", "0x006A");
543         KEY_MAP.put("UP", "0x0026");
544         KEY_MAP.put("DOWN", "0x0028");
545         KEY_MAP.put("LEFT", "0x0025");
546         KEY_MAP.put("RIGHT", "0x0027");
547         KEY_MAP.put("PGUP", "0x0021");
548         KEY_MAP.put("PGDOWN", "0x0022");
549         KEY_MAP.put("DELETE", "0x0008");
550         KEY_MAP.put("ENTER", "0x000D");
551         KEY_MAP.put("SEARCH", "0x0451");
552         KEY_MAP.put("RED", "0x0113");
553         KEY_MAP.put("GREEN", "0x0114");
554         KEY_MAP.put("YELLOW", "0x0115");
555         KEY_MAP.put("BLUE", "0x0116");
556         KEY_MAP.put("OPTION", "0x0460");
557         KEY_MAP.put("OK", "0x000D");
558         KEY_MAP.put("BACK", "0x0008");
559         KEY_MAP.put("EXIT", "0x045D");
560         KEY_MAP.put("PORTAL", "0x0110");
561         KEY_MAP.put("VOLUP", "0x0103");
562         KEY_MAP.put("VOLDOWN", "0x0104");
563         KEY_MAP.put("INTER", "0x010D");
564         KEY_MAP.put("HELP", "0x011C");
565         KEY_MAP.put("SETTINGS", "0x011D");
566         KEY_MAP.put("MUTE", "0x0105");
567         KEY_MAP.put("CHUP", "0x0101");
568         KEY_MAP.put("CHDOWN", "0x0102");
569         KEY_MAP.put("REWIND", "0x0109");
570         KEY_MAP.put("PLAY", "0x0107");
571         KEY_MAP.put("PAUSE", "0x0107");
572         KEY_MAP.put("FORWARD", "0x0108");
573         KEY_MAP.put("TRACK", "0x0106");
574         KEY_MAP.put("LASTCH", "0x045E");
575         KEY_MAP.put("PREVCH", "0x010B");
576         KEY_MAP.put("NEXTCH", "0x0107");
577         KEY_MAP.put("RECORD", "0x0461");
578         KEY_MAP.put("STOP", "0x010E");
579         KEY_MAP.put("BEGIN", "0x010B");
580         KEY_MAP.put("END", "0x010A");
581         KEY_MAP.put("REPLAY", "0x045B");
582         KEY_MAP.put("SKIP", "0x045C");
583         KEY_MAP.put("SUBTITLE", "0x236");
584         KEY_MAP.put("RECORDINGS", "0x045F");
585         KEY_MAP.put("FAV", "0x0119");
586         KEY_MAP.put("SOURCE", "0x0083");
587         KEY_MAP.put("SWITCH", "0x0118");
588         KEY_MAP.put("IPTV", "0x0081");
589         KEY_MAP.put("PC", "0x0082");
590         KEY_MAP.put("PIP", "0x0084");
591         KEY_MAP.put("MULTIVIEW", "0x0562");
592         KEY_MAP.put("F1", "0x0070");
593         KEY_MAP.put("F2", "0x0071");
594         KEY_MAP.put("F3", "0x0072");
595         KEY_MAP.put("F4", "0x0073");
596         KEY_MAP.put("F5", "0x0074");
597         KEY_MAP.put("F6", "0x0075");
598         KEY_MAP.put("F7", "0x0076");
599         KEY_MAP.put("F8", "0x0077");
600         KEY_MAP.put("F9", "0x0078");
601         KEY_MAP.put("F10", "0x0079");
602         KEY_MAP.put("F11", "0x007A");
603         KEY_MAP.put("F12", "0x007B");
604         KEY_MAP.put("F13", "0x007C");
605         KEY_MAP.put("F14", "0x007D");
606         KEY_MAP.put("F15", "0x007E");
607         KEY_MAP.put("F16", "0x007F");
608
609         KEY_MAP.put("PVR", "0x0461");
610         KEY_MAP.put("RADIO", "0x0462");
611
612         // Those key codes are missing and not included in the spec
613         // KEY_MAP.put("TV", "0x");
614         // KEY_MAP.put("RADIO", "0x");
615         // KEY_MAP.put("MOVIES", "0x");
616     }
617 }