Ticket #844: hlci.patch
File hlci.patch, 10.9 KB (added by , 20 years ago) |
---|
-
libs/libmythtv/dvbdev/dvbci.cpp
1434 1434 capmt[infoLengthPos + 1] = l & 0xFF; 1435 1435 } 1436 1436 1437 // -- c CiHandler -------------------------------------------------------------1437 // -- cLlCiHandler ------------------------------------------------------------- 1438 1438 1439 c CiHandler::cCiHandler(int Fd, int NumSlots)1439 cLlCiHandler::cLlCiHandler(int Fd, int NumSlots) 1440 1440 { 1441 1441 numSlots = NumSlots; 1442 1442 newCaSupport = false; … … 1449 1449 needCaPmt = false; 1450 1450 } 1451 1451 1452 c CiHandler::~cCiHandler()1452 cLlCiHandler::~cLlCiHandler() 1453 1453 { 1454 1454 cMutexLock MutexLock(&mutex); 1455 1455 for (int i = 0; i < MAX_CI_SESSION; i++) … … 1471 1471 if (NumSlots > 0) 1472 1472 { 1473 1473 if (Caps.slot_type & CA_CI_LINK) 1474 return new cCiHandler(fd_ca, NumSlots); 1474 return new cLlCiHandler(fd_ca, NumSlots); 1475 else if (Caps.slot_type & CA_CI) 1476 return new cHlCiHandler(fd_ca, NumSlots); 1475 1477 else 1476 isyslog("CAM doesn't support link layer interface,"1478 isyslog("CAM doesn't support either high or low level CI," 1477 1479 " Caps.slot_type=%i", Caps.slot_type); 1478 1480 } 1479 1481 else … … 1486 1488 return NULL; 1487 1489 } 1488 1490 1489 int c CiHandler::ResourceIdToInt(const uint8_t *Data)1491 int cLlCiHandler::ResourceIdToInt(const uint8_t *Data) 1490 1492 { 1491 1493 return (ntohl(*(int *)Data)); 1492 1494 } 1493 1495 1494 bool c CiHandler::Send(uint8_t Tag, int SessionId, int ResourceId, int Status)1496 bool cLlCiHandler::Send(uint8_t Tag, int SessionId, int ResourceId, int Status) 1495 1497 { 1496 1498 uint8_t buffer[16]; 1497 1499 uint8_t *p = buffer; … … 1509 1511 return tc && tc->SendData(p - buffer, buffer) == OK; 1510 1512 } 1511 1513 1512 cCiSession *c CiHandler::GetSessionBySessionId(int SessionId)1514 cCiSession *cLlCiHandler::GetSessionBySessionId(int SessionId) 1513 1515 { 1514 1516 for (int i = 0; i < MAX_CI_SESSION; i++) { 1515 1517 if (sessions[i] && sessions[i]->SessionId() == SessionId) … … 1518 1520 return NULL; 1519 1521 } 1520 1522 1521 cCiSession *c CiHandler::GetSessionByResourceId(int ResourceId, int Slot)1523 cCiSession *cLlCiHandler::GetSessionByResourceId(int ResourceId, int Slot) 1522 1524 { 1523 1525 for (int i = 0; i < MAX_CI_SESSION; i++) { 1524 1526 if (sessions[i] && sessions[i]->Tc()->Slot() == Slot && sessions[i]->ResourceId() == ResourceId) … … 1527 1529 return NULL; 1528 1530 } 1529 1531 1530 cCiSession *c CiHandler::CreateSession(int ResourceId)1532 cCiSession *cLlCiHandler::CreateSession(int ResourceId) 1531 1533 { 1532 1534 if (!GetSessionByResourceId(ResourceId, tc->Slot())) { 1533 1535 for (int i = 0; i < MAX_CI_SESSION; i++) { … … 1547 1549 return NULL; 1548 1550 } 1549 1551 1550 bool c CiHandler::OpenSession(int Length, const uint8_t *Data)1552 bool cLlCiHandler::OpenSession(int Length, const uint8_t *Data) 1551 1553 { 1552 1554 if (Length == 6 && *(Data + 1) == 0x04) { 1553 1555 int ResourceId = ResourceIdToInt(Data + 2); … … 1573 1575 return false; 1574 1576 } 1575 1577 1576 bool c CiHandler::CloseSession(int SessionId)1578 bool cLlCiHandler::CloseSession(int SessionId) 1577 1579 { 1578 1580 dbgprotocol("CloseSession %08X\n", SessionId); 1579 1581 cCiSession *Session = GetSessionBySessionId(SessionId); … … 1590 1592 return false; 1591 1593 } 1592 1594 1593 int c CiHandler::CloseAllSessions(int Slot)1595 int cLlCiHandler::CloseAllSessions(int Slot) 1594 1596 { 1595 1597 int result = 0; 1596 1598 for (int i = 0; i < MAX_CI_SESSION; i++) { … … 1602 1604 return result; 1603 1605 } 1604 1606 1605 bool c CiHandler::Process(void)1607 bool cLlCiHandler::Process(void) 1606 1608 { 1607 1609 bool result = true; 1608 1610 cMutexLock MutexLock(&mutex); … … 1688 1690 return result; 1689 1691 } 1690 1692 1691 bool c CiHandler::EnterMenu(int Slot)1693 bool cLlCiHandler::EnterMenu(int Slot) 1692 1694 { 1693 1695 cMutexLock MutexLock(&mutex); 1694 1696 cCiApplicationInformation *api = (cCiApplicationInformation *)GetSessionByResourceId(RI_APPLICATION_INFORMATION, Slot); 1695 1697 return api ? api->EnterMenu() : false; 1696 1698 } 1697 1699 1698 cCiMenu *c CiHandler::GetMenu(void)1700 cCiMenu *cLlCiHandler::GetMenu(void) 1699 1701 { 1700 1702 cMutexLock MutexLock(&mutex); 1701 1703 for (int Slot = 0; Slot < numSlots; Slot++) { … … 1706 1708 return NULL; 1707 1709 } 1708 1710 1709 cCiEnquiry *c CiHandler::GetEnquiry(void)1711 cCiEnquiry *cLlCiHandler::GetEnquiry(void) 1710 1712 { 1711 1713 cMutexLock MutexLock(&mutex); 1712 1714 for (int Slot = 0; Slot < numSlots; Slot++) { … … 1717 1719 return NULL; 1718 1720 } 1719 1721 1720 const unsigned short *c CiHandler::GetCaSystemIds(int Slot)1722 const unsigned short *cLlCiHandler::GetCaSystemIds(int Slot) 1721 1723 { 1722 1724 cMutexLock MutexLock(&mutex); 1723 1725 cCiConditionalAccessSupport *cas = (cCiConditionalAccessSupport *)GetSessionByResourceId(RI_CONDITIONAL_ACCESS_SUPPORT, Slot); 1724 1726 return cas ? cas->GetCaSystemIds() : NULL; 1725 1727 } 1726 1728 1727 bool c CiHandler::SetCaPmt(cCiCaPmt &CaPmt, int Slot)1729 bool cLlCiHandler::SetCaPmt(cCiCaPmt &CaPmt, int Slot) 1728 1730 { 1729 1731 cMutexLock MutexLock(&mutex); 1730 1732 cCiConditionalAccessSupport *cas = (cCiConditionalAccessSupport *)GetSessionByResourceId(RI_CONDITIONAL_ACCESS_SUPPORT, Slot); 1731 1733 return cas && cas->SendPMT(CaPmt); 1732 1734 } 1733 1735 1734 bool c CiHandler::Reset(int Slot)1736 bool cLlCiHandler::Reset(int Slot) 1735 1737 { 1736 1738 cMutexLock MutexLock(&mutex); 1737 1739 CloseAllSessions(Slot); 1738 1740 return tpl->ResetSlot(Slot); 1739 1741 } 1740 1742 1741 bool c CiHandler::connected() const1743 bool cLlCiHandler::connected() const 1742 1744 { 1743 1745 return _connected; 1744 1746 } 1745 1747 1748 // -- cHlCiHandler ------------------------------------------------------------- 1749 1750 cHlCiHandler::cHlCiHandler(int Fd, int NumSlots) 1751 { 1752 numSlots = NumSlots; 1753 numCaSystemIds = 0; 1754 caSystemIds[0] = 0; 1755 fdCa = Fd; 1756 state = 0; 1757 fprintf(stderr, "New High level CI handler\n"); 1758 } 1759 1760 cHlCiHandler::~cHlCiHandler() 1761 { 1762 cMutexLock MutexLock(&mutex); 1763 close(fdCa); 1764 } 1765 1766 int cHlCiHandler::CommHL(unsigned tag, unsigned function, struct ca_msg *msg) 1767 { 1768 if (tag) { 1769 msg->msg[2] = tag & 0xff; 1770 msg->msg[1] = (tag & 0xff00) >> 8; 1771 msg->msg[0] = (tag & 0xff0000) >> 16; 1772 fprintf(stderr, "Sending message=[%02x %02x %02x ]\n", 1773 msg->msg[0], msg->msg[1], msg->msg[2]); 1774 } 1775 1776 return ioctl(fdCa, function, msg); 1777 } 1778 1779 int cHlCiHandler::GetData(unsigned tag, struct ca_msg *msg) 1780 { 1781 return CommHL(tag, CA_GET_MSG, msg); 1782 } 1783 1784 int cHlCiHandler::SendData(unsigned tag, struct ca_msg *msg) 1785 { 1786 return CommHL(tag, CA_SEND_MSG, msg); 1787 } 1788 1789 bool cHlCiHandler::Process(void) 1790 { 1791 cMutexLock MutexLock(&mutex); 1792 1793 struct ca_msg msg; 1794 switch(state) { 1795 case 0: 1796 // Get CA_system_ids 1797 /* Enquire */ 1798 if ((SendData(AOT_CA_INFO_ENQ, &msg)) < 0) { 1799 fprintf(stderr, "HLCI communication failed\n"); 1800 } else { 1801 dbgprotocol("==> Ca Info Enquiry"); 1802 /* Receive */ 1803 if ((GetData(AOT_CA_INFO, &msg)) < 0) { 1804 fprintf(stderr, "HLCI communication failed\n"); 1805 } else { 1806 printf("Debug: "); 1807 for(int i = 0; i < 20; i++) { 1808 printf("%d ", msg.msg[i]); 1809 } 1810 printf("\n"); 1811 dbgprotocol("<== Ca Info"); 1812 int l = msg.msg[3]; 1813 const uint8_t *d = &msg.msg[4]; 1814 while (l > 1) { 1815 unsigned short id = ((unsigned short)(*d) << 8) | *(d + 1); 1816 dbgprotocol(" %04X", id); 1817 d += 2; 1818 l -= 2; 1819 if (numCaSystemIds < MAXCASYSTEMIDS) { 1820 caSystemIds[numCaSystemIds++] = id; 1821 caSystemIds[numCaSystemIds] = 0; 1822 } 1823 else 1824 esyslog("ERROR: too many CA system IDs!"); 1825 } 1826 dbgprotocol("\n"); 1827 } 1828 state = 1; 1829 break; 1830 } 1831 } 1832 1833 bool result = true; 1834 1835 return result; 1836 } 1837 1838 bool cHlCiHandler::EnterMenu(int) 1839 { 1840 return false; 1841 } 1842 1843 cCiMenu *cHlCiHandler::GetMenu(void) 1844 { 1845 return NULL; 1846 } 1847 1848 cCiEnquiry *cHlCiHandler::GetEnquiry(void) 1849 { 1850 return NULL; 1851 } 1852 1853 const unsigned short *cHlCiHandler::GetCaSystemIds(int) 1854 { 1855 return caSystemIds; 1856 } 1857 1858 bool cHlCiHandler::SetCaPmt(cCiCaPmt &CaPmt, int) 1859 { 1860 cMutexLock MutexLock(&mutex); 1861 struct ca_msg msg; 1862 1863 fprintf(stderr, "Setting CA PMT.\n"); 1864 state = 2; 1865 1866 msg.msg[3] = CaPmt.length; 1867 memcpy(&msg.msg[4], CaPmt.capmt, CaPmt.length); 1868 1869 if ((SendData(AOT_CA_PMT, &msg)) < 0) { 1870 fprintf(stderr, "HLCI communication failed\n"); 1871 return false; 1872 } 1873 1874 return true; 1875 } 1876 1877 bool cHlCiHandler::Reset(int) 1878 { 1879 if ((ioctl(fdCa, CA_RESET)) < 0) { 1880 fprintf(stderr, "ioctl CA_RESET failed.\n"); 1881 return false; 1882 } 1883 return true; 1884 } 1885 1886 bool cHlCiHandler::NeedCaPmt(void) 1887 { 1888 if(state == 1) 1889 return true; 1890 1891 return false; 1892 } -
libs/libmythtv/dvbdev/dvbci.h
122 122 123 123 class cCiCaPmt { 124 124 friend class cCiConditionalAccessSupport; 125 friend class cHlCiHandler; 125 126 private: 126 127 int length; 127 128 int infoLengthPos; … … 139 140 class cCiTransportConnection; 140 141 141 142 class cCiHandler { 143 public: 144 static cCiHandler *CreateCiHandler(const char *FileName); 145 virtual int NumSlots(void) = 0; 146 virtual bool Process(void) = 0; 147 virtual bool HasUserIO(void) = 0; 148 virtual bool NeedCaPmt(void) = 0; 149 virtual bool EnterMenu(int Slot) = 0; 150 virtual cCiMenu *GetMenu(void) = 0; 151 virtual cCiEnquiry *GetEnquiry(void) = 0; 152 virtual const unsigned short *GetCaSystemIds(int Slot) = 0; 153 virtual bool SetCaPmt(cCiCaPmt &CaPmt, int Slot) = 0; 154 }; 155 156 class cLlCiHandler : public cCiHandler { 157 friend class cCiHandler; 142 158 private: 143 159 cMutex mutex; 144 160 int fdCa; … … 157 173 bool OpenSession(int Length, const uint8_t *Data); 158 174 bool CloseSession(int SessionId); 159 175 int CloseAllSessions(int Slot); 160 c CiHandler(int Fd, int NumSlots);176 cLlCiHandler(int Fd, int NumSlots); 161 177 public: 162 ~cCiHandler(); 163 static cCiHandler *CreateCiHandler(const char *FileName); 178 virtual ~cLlCiHandler(); 164 179 int NumSlots(void) { return numSlots; } 165 180 bool Process(void); 166 181 bool HasUserIO(void) { return hasUserIO; } … … 175 190 bool connected() const; 176 191 }; 177 192 193 class cHlCiHandler : public cCiHandler { 194 friend class cCiHandler; 195 private: 196 cMutex mutex; 197 int fdCa; 198 int numSlots; 199 int state; 200 int numCaSystemIds; 201 unsigned short caSystemIds[MAXCASYSTEMIDS + 1]; // list is zero terminated! 202 cHlCiHandler(int Fd, int NumSlots); 203 int CommHL(unsigned tag, unsigned function, struct ca_msg *msg); 204 int GetData(unsigned tag, struct ca_msg *msg); 205 int SendData(unsigned tag, struct ca_msg *msg); 206 public: 207 virtual ~cHlCiHandler(); 208 int NumSlots(void) { return numSlots; } 209 bool Process(void); 210 bool HasUserIO(void) { return false; }//hasUserIO; } 211 bool NeedCaPmt(void); 212 bool EnterMenu(int Slot); 213 cCiMenu *GetMenu(void); 214 cCiEnquiry *GetEnquiry(void); 215 bool SetCaPmt(cCiCaPmt &CaPmt); 216 const unsigned short *GetCaSystemIds(int Slot); 217 bool SetCaPmt(cCiCaPmt &CaPmt, int Slot); 218 bool Reset(int Slot); 219 bool connected() const; 220 }; 221 178 222 int tcp_listen(struct sockaddr_in *name,int sckt,unsigned long address=INADDR_ANY); 179 223 int accept_tcp(int ip_sock,struct sockaddr_in *ip_name); 180 224 int udp_listen(struct sockaddr_un *name,char const * const filename);