00001 /* 00002 * hdhomerun_pkt.h 00003 * 00004 * Copyright © 2005-2006 Silicondust USA Inc. <www.silicondust.com>. 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 3 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 00018 * 00019 * As a special exception to the GNU Lesser General Public License, 00020 * you may link, statically or dynamically, an application with a 00021 * publicly distributed version of the Library to produce an 00022 * executable file containing portions of the Library, and 00023 * distribute that executable file under terms of your choice, 00024 * without any of the additional requirements listed in clause 4 of 00025 * the GNU Lesser General Public License. 00026 * 00027 * By "a publicly distributed version of the Library", we mean 00028 * either the unmodified Library as distributed by Silicondust, or a 00029 * modified version of the Library that is distributed under the 00030 * conditions defined in the GNU Lesser General Public License. 00031 */ 00032 #ifdef __cplusplus 00033 extern "C" { 00034 #endif 00035 00036 /* 00037 * The discover protocol (UDP port 65001) and control protocol (TCP port 65001) 00038 * both use the same packet based format: 00039 * uint16_t Packet type 00040 * uint16_t Payload length (bytes) 00041 * uint8_t[] Payload data (0-n bytes). 00042 * uint32_t CRC (Ethernet style 32-bit CRC) 00043 * 00044 * All variables are big-endian except for the crc which is little-endian. 00045 * 00046 * Valid values for the packet type are listed below as defines prefixed 00047 * with "HDHOMERUN_TYPE_" 00048 * 00049 * Discovery: 00050 * 00051 * The payload for a discovery request or reply is a simple sequence of 00052 * tag-length-value data: 00053 * uint8_t Tag 00054 * varlen Length 00055 * uint8_t[] Value (0-n bytes) 00056 * 00057 * The length field can be one or two bytes long. 00058 * For a length <= 127 bytes the length is expressed as a single byte. The 00059 * most-significant-bit is clear indicating a single-byte length. 00060 * For a length >= 128 bytes the length is expressed as a sequence of two bytes as follows: 00061 * The first byte is contains the least-significant 7-bits of the length. The 00062 * most-significant bit is then set (add 0x80) to indicate that it is a two byte length. 00063 * The second byte contains the length shifted down 7 bits. 00064 * 00065 * A discovery request packet has a packet type of HDHOMERUN_TYPE_DISCOVER_REQ and should 00066 * contain two tags: HDHOMERUN_TAG_DEVICE_TYPE and HDHOMERUN_TAG_DEVICE_ID. 00067 * The HDHOMERUN_TAG_DEVICE_TYPE value should be set to HDHOMERUN_DEVICE_TYPE_TUNER. 00068 * The HDHOMERUN_TAG_DEVICE_ID value should be set to HDHOMERUN_DEVICE_ID_WILDCARD to match 00069 * all devices, or to the 32-bit device id number to match a single device. 00070 * 00071 * The discovery response packet has a packet type of HDHOMERUN_TYPE_DISCOVER_RPY and has the 00072 * same format as the discovery request packet with the two tags: HDHOMERUN_TAG_DEVICE_TYPE and 00073 * HDHOMERUN_TAG_DEVICE_ID. In the future additional tags may also be returned - unknown tags 00074 * should be skipped and not treated as an error. 00075 * 00076 * Control get/set: 00077 * 00078 * The payload for a control get/set request is a simple sequence of tag-length-value data 00079 * following the same format as for discover packets. 00080 * 00081 * A get request packet has a packet type of HDHOMERUN_TYPE_GETSET_REQ and should contain 00082 * the tag: HDHOMERUN_TAG_GETSET_NAME. The HDHOMERUN_TAG_GETSET_NAME value should be a sequence 00083 * of bytes forming a null-terminated string, including the NULL. The TLV length must include 00084 * the NULL character so the length field should be set to strlen(str) + 1. 00085 * 00086 * A set request packet has a packet type of HDHOMERUN_TYPE_GETSET_REQ (same as a get request) 00087 * and should contain two tags: HDHOMERUN_TAG_GETSET_NAME and HDHOMERUN_TAG_GETSET_VALUE. 00088 * The HDHOMERUN_TAG_GETSET_NAME value should be a sequence of bytes forming a null-terminated 00089 * string, including the NULL. 00090 * The HDHOMERUN_TAG_GETSET_VALUE value should be a sequence of bytes forming a null-terminated 00091 * string, including the NULL. 00092 * 00093 * The get and set reply packets have the packet type HDHOMERUN_TYPE_GETSET_RPY and have the same 00094 * format as the set request packet with the two tags: HDHOMERUN_TAG_GETSET_NAME and 00095 * HDHOMERUN_TAG_GETSET_VALUE. A set request is also implicit get request so the updated value is 00096 * returned. 00097 * 00098 * If the device encounters an error handling the get or set request then the get/set reply packet 00099 * will contain the tag HDHOMERUN_TAG_ERROR_MESSAGE. The format of the value is a sequence of 00100 * bytes forming a null-terminated string, including the NULL. 00101 * 00102 * In the future additional tags may also be returned - unknown tags should be skipped and not 00103 * treated as an error. 00104 * 00105 * Security note: The application should not rely on the NULL character being present. The 00106 * application should write a NULL character based on the TLV length to protect the application 00107 * from a potential attack. 00108 * 00109 * Firmware Upgrade: 00110 * 00111 * A firmware upgrade packet has a packet type of HDHOMERUN_TYPE_UPGRADE_REQ and has a fixed format: 00112 * uint32_t Position in bytes from start of file. 00113 * uint8_t[256] Firmware data (256 bytes) 00114 * 00115 * The data must be uploaded in 256 byte chunks and must be uploaded in order. 00116 * The position number is in bytes so will increment by 256 each time. 00117 * 00118 * When all data is uploaded it should be signaled complete by sending another packet of type 00119 * HDHOMERUN_TYPE_UPGRADE_REQ with payload of a single uint32_t with the value 0xFFFFFFFF. 00120 */ 00121 00122 #define HDHOMERUN_DISCOVER_UDP_PORT 65001 00123 #define HDHOMERUN_CONTROL_TCP_PORT 65001 00124 00125 #define HDHOMERUN_MAX_PACKET_SIZE 1460 00126 #define HDHOMERUN_MAX_PAYLOAD_SIZE 1452 00127 00128 #define HDHOMERUN_TYPE_DISCOVER_REQ 0x0002 00129 #define HDHOMERUN_TYPE_DISCOVER_RPY 0x0003 00130 #define HDHOMERUN_TYPE_GETSET_REQ 0x0004 00131 #define HDHOMERUN_TYPE_GETSET_RPY 0x0005 00132 #define HDHOMERUN_TYPE_UPGRADE_REQ 0x0006 00133 #define HDHOMERUN_TYPE_UPGRADE_RPY 0x0007 00134 00135 #define HDHOMERUN_TAG_DEVICE_TYPE 0x01 00136 #define HDHOMERUN_TAG_DEVICE_ID 0x02 00137 #define HDHOMERUN_TAG_GETSET_NAME 0x03 00138 #define HDHOMERUN_TAG_GETSET_VALUE 0x04 00139 #define HDHOMERUN_TAG_GETSET_LOCKKEY 0x15 00140 #define HDHOMERUN_TAG_ERROR_MESSAGE 0x05 00141 #define HDHOMERUN_TAG_TUNER_COUNT 0x10 00142 00143 #define HDHOMERUN_DEVICE_TYPE_WILDCARD 0xFFFFFFFF 00144 #define HDHOMERUN_DEVICE_TYPE_TUNER 0x00000001 00145 #define HDHOMERUN_DEVICE_ID_WILDCARD 0xFFFFFFFF 00146 00147 #define HDHOMERUN_MIN_PEEK_LENGTH 4 00148 00149 struct hdhomerun_pkt_t { 00150 uint8_t *pos; 00151 uint8_t *start; 00152 uint8_t *end; 00153 uint8_t *limit; 00154 uint8_t buffer[3074]; 00155 }; 00156 00157 extern LIBTYPE struct hdhomerun_pkt_t *hdhomerun_pkt_create(void); 00158 extern LIBTYPE void hdhomerun_pkt_destroy(struct hdhomerun_pkt_t *pkt); 00159 extern LIBTYPE void hdhomerun_pkt_reset(struct hdhomerun_pkt_t *pkt); 00160 00161 extern LIBTYPE uint8_t hdhomerun_pkt_read_u8(struct hdhomerun_pkt_t *pkt); 00162 extern LIBTYPE uint16_t hdhomerun_pkt_read_u16(struct hdhomerun_pkt_t *pkt); 00163 extern LIBTYPE uint32_t hdhomerun_pkt_read_u32(struct hdhomerun_pkt_t *pkt); 00164 extern LIBTYPE size_t hdhomerun_pkt_read_var_length(struct hdhomerun_pkt_t *pkt); 00165 extern LIBTYPE uint8_t *hdhomerun_pkt_read_tlv(struct hdhomerun_pkt_t *pkt, uint8_t *ptag, size_t *plength); 00166 00167 extern LIBTYPE void hdhomerun_pkt_write_u8(struct hdhomerun_pkt_t *pkt, uint8_t v); 00168 extern LIBTYPE void hdhomerun_pkt_write_u16(struct hdhomerun_pkt_t *pkt, uint16_t v); 00169 extern LIBTYPE void hdhomerun_pkt_write_u32(struct hdhomerun_pkt_t *pkt, uint32_t v); 00170 extern LIBTYPE void hdhomerun_pkt_write_var_length(struct hdhomerun_pkt_t *pkt, size_t v); 00171 extern LIBTYPE void hdhomerun_pkt_write_mem(struct hdhomerun_pkt_t *pkt, const void *mem, size_t length); 00172 00173 extern LIBTYPE bool_t hdhomerun_pkt_open_frame(struct hdhomerun_pkt_t *pkt, uint16_t *ptype); 00174 extern LIBTYPE void hdhomerun_pkt_seal_frame(struct hdhomerun_pkt_t *pkt, uint16_t frame_type); 00175 00176 #ifdef __cplusplus 00177 } 00178 #endif
1.6.3