Made the cCiSession members sessionId and resourceId uint16_t and uint32_t

This commit is contained in:
Klaus Schmidinger 2006-08-12 10:26:43 +02:00
parent 9e6b12aa20
commit 7390eaf765
4 changed files with 45 additions and 41 deletions

View File

@ -1622,6 +1622,7 @@ Ville Skytt
for reporting that the call to pthread_setschedparam(childTid, SCHED_RR, 0) in for reporting that the call to pthread_setschedparam(childTid, SCHED_RR, 0) in
thread.c caused a compiler warning with g++ 4.1.1 thread.c caused a compiler warning with g++ 4.1.1
for fixing converting the port number in the "connect from..." log message of SVDRP for fixing converting the port number in the "connect from..." log message of SVDRP
for reporting that there are places where ntohs() is assigned to different types
Steffen Beyer <cpunk@reactor.de> Steffen Beyer <cpunk@reactor.de>
for fixing setting the colored button help after deleting a recording in case the next for fixing setting the colored button help after deleting a recording in case the next

View File

@ -4863,3 +4863,6 @@ Video Disk Recorder Revision History
- Fixed converting the port number in the "connect from..." log message of SVDRP - Fixed converting the port number in the "connect from..." log message of SVDRP
(thanks to Ville Skyttä). (thanks to Ville Skyttä).
- Made the cCiSession members sessionId and resourceId uint16_t and uint32_t,
respectively, to match their types in the CI session data (thanks to Ville Skyttä
for reporting that there are places where ntohs() is assigned to different types).

68
ci.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: ci.c 1.43 2006/07/22 13:40:30 kls Exp $ * $Id: ci.c 1.44 2006/08/12 10:14:27 kls Exp $
*/ */
#include "ci.h" #include "ci.h"
@ -630,24 +630,24 @@ cCiTransportConnection *cCiTransportLayer::Process(int Slot)
class cCiSession { class cCiSession {
private: private:
int sessionId; uint16_t sessionId;
int resourceId; uint32_t resourceId;
cCiTransportConnection *tc; cCiTransportConnection *tc;
protected: protected:
int GetTag(int &Length, const uint8_t **Data); int GetTag(int &Length, const uint8_t **Data);
const uint8_t *GetData(const uint8_t *Data, int &Length); const uint8_t *GetData(const uint8_t *Data, int &Length);
int SendData(int Tag, int Length = 0, const uint8_t *Data = NULL); int SendData(int Tag, int Length = 0, const uint8_t *Data = NULL);
public: public:
cCiSession(int SessionId, int ResourceId, cCiTransportConnection *Tc); cCiSession(uint16_t SessionId, uint32_t ResourceId, cCiTransportConnection *Tc);
virtual ~cCiSession(); virtual ~cCiSession();
const cCiTransportConnection *Tc(void) { return tc; } const cCiTransportConnection *Tc(void) { return tc; }
int SessionId(void) { return sessionId; } uint16_t SessionId(void) { return sessionId; }
int ResourceId(void) { return resourceId; } uint32_t ResourceId(void) { return resourceId; }
virtual bool HasUserIO(void) { return false; } virtual bool HasUserIO(void) { return false; }
virtual bool Process(int Length = 0, const uint8_t *Data = NULL); virtual bool Process(int Length = 0, const uint8_t *Data = NULL);
}; };
cCiSession::cCiSession(int SessionId, int ResourceId, cCiTransportConnection *Tc) cCiSession::cCiSession(uint16_t SessionId, uint32_t ResourceId, cCiTransportConnection *Tc)
{ {
sessionId = SessionId; sessionId = SessionId;
resourceId = ResourceId; resourceId = ResourceId;
@ -711,11 +711,11 @@ class cCiResourceManager : public cCiSession {
private: private:
int state; int state;
public: public:
cCiResourceManager(int SessionId, cCiTransportConnection *Tc); cCiResourceManager(uint16_t SessionId, cCiTransportConnection *Tc);
virtual bool Process(int Length = 0, const uint8_t *Data = NULL); virtual bool Process(int Length = 0, const uint8_t *Data = NULL);
}; };
cCiResourceManager::cCiResourceManager(int SessionId, cCiTransportConnection *Tc) cCiResourceManager::cCiResourceManager(uint16_t SessionId, cCiTransportConnection *Tc)
:cCiSession(SessionId, RI_RESOURCE_MANAGER, Tc) :cCiSession(SessionId, RI_RESOURCE_MANAGER, Tc)
{ {
dbgprotocol("New Resource Manager (session id %d)\n", SessionId); dbgprotocol("New Resource Manager (session id %d)\n", SessionId);
@ -729,12 +729,12 @@ bool cCiResourceManager::Process(int Length, const uint8_t *Data)
switch (Tag) { switch (Tag) {
case AOT_PROFILE_ENQ: { case AOT_PROFILE_ENQ: {
dbgprotocol("%d: <== Profile Enquiry\n", SessionId()); dbgprotocol("%d: <== Profile Enquiry\n", SessionId());
int resources[] = { htonl(RI_RESOURCE_MANAGER), uint32_t resources[] = { htonl(RI_RESOURCE_MANAGER),
htonl(RI_APPLICATION_INFORMATION), htonl(RI_APPLICATION_INFORMATION),
htonl(RI_CONDITIONAL_ACCESS_SUPPORT), htonl(RI_CONDITIONAL_ACCESS_SUPPORT),
htonl(RI_DATE_TIME), htonl(RI_DATE_TIME),
htonl(RI_MMI) htonl(RI_MMI)
}; };
dbgprotocol("%d: ==> Profile\n", SessionId()); dbgprotocol("%d: ==> Profile\n", SessionId());
SendData(AOT_PROFILE, sizeof(resources), (uint8_t*)resources); SendData(AOT_PROFILE, sizeof(resources), (uint8_t*)resources);
state = 3; state = 3;
@ -779,14 +779,14 @@ private:
uint16_t manufacturerCode; uint16_t manufacturerCode;
char *menuString; char *menuString;
public: public:
cCiApplicationInformation(int SessionId, cCiTransportConnection *Tc); cCiApplicationInformation(uint16_t SessionId, cCiTransportConnection *Tc);
virtual ~cCiApplicationInformation(); virtual ~cCiApplicationInformation();
virtual bool Process(int Length = 0, const uint8_t *Data = NULL); virtual bool Process(int Length = 0, const uint8_t *Data = NULL);
bool EnterMenu(void); bool EnterMenu(void);
const char *GetMenuString(void) { return menuString; } const char *GetMenuString(void) { return menuString; }
}; };
cCiApplicationInformation::cCiApplicationInformation(int SessionId, cCiTransportConnection *Tc) cCiApplicationInformation::cCiApplicationInformation(uint16_t SessionId, cCiTransportConnection *Tc)
:cCiSession(SessionId, RI_APPLICATION_INFORMATION, Tc) :cCiSession(SessionId, RI_APPLICATION_INFORMATION, Tc)
{ {
dbgprotocol("New Application Information (session id %d)\n", SessionId); dbgprotocol("New Application Information (session id %d)\n", SessionId);
@ -963,14 +963,14 @@ private:
int numCaSystemIds; int numCaSystemIds;
unsigned short caSystemIds[MAXCASYSTEMIDS + 1]; // list is zero terminated! unsigned short caSystemIds[MAXCASYSTEMIDS + 1]; // list is zero terminated!
public: public:
cCiConditionalAccessSupport(int SessionId, cCiTransportConnection *Tc); cCiConditionalAccessSupport(uint16_t SessionId, cCiTransportConnection *Tc);
virtual bool Process(int Length = 0, const uint8_t *Data = NULL); virtual bool Process(int Length = 0, const uint8_t *Data = NULL);
const unsigned short *GetCaSystemIds(void) { return caSystemIds; } const unsigned short *GetCaSystemIds(void) { return caSystemIds; }
bool SendPMT(cCiCaPmt *CaPmt); bool SendPMT(cCiCaPmt *CaPmt);
bool ReceivedReply(bool CanDescramble = false); bool ReceivedReply(bool CanDescramble = false);
}; };
cCiConditionalAccessSupport::cCiConditionalAccessSupport(int SessionId, cCiTransportConnection *Tc) cCiConditionalAccessSupport::cCiConditionalAccessSupport(uint16_t SessionId, cCiTransportConnection *Tc)
:cCiSession(SessionId, RI_CONDITIONAL_ACCESS_SUPPORT, Tc) :cCiSession(SessionId, RI_CONDITIONAL_ACCESS_SUPPORT, Tc)
{ {
dbgprotocol("New Conditional Access Support (session id %d)\n", SessionId); dbgprotocol("New Conditional Access Support (session id %d)\n", SessionId);
@ -1090,11 +1090,11 @@ private:
time_t lastTime; time_t lastTime;
bool SendDateTime(void); bool SendDateTime(void);
public: public:
cCiDateTime(int SessionId, cCiTransportConnection *Tc); cCiDateTime(uint16_t SessionId, cCiTransportConnection *Tc);
virtual bool Process(int Length = 0, const uint8_t *Data = NULL); virtual bool Process(int Length = 0, const uint8_t *Data = NULL);
}; };
cCiDateTime::cCiDateTime(int SessionId, cCiTransportConnection *Tc) cCiDateTime::cCiDateTime(uint16_t SessionId, cCiTransportConnection *Tc)
:cCiSession(SessionId, RI_DATE_TIME, Tc) :cCiSession(SessionId, RI_DATE_TIME, Tc)
{ {
interval = 0; interval = 0;
@ -1193,7 +1193,7 @@ private:
cCiMenu *menu, *fetchedMenu; cCiMenu *menu, *fetchedMenu;
cCiEnquiry *enquiry, *fetchedEnquiry; cCiEnquiry *enquiry, *fetchedEnquiry;
public: public:
cCiMMI(int SessionId, cCiTransportConnection *Tc); cCiMMI(uint16_t SessionId, cCiTransportConnection *Tc);
virtual ~cCiMMI(); virtual ~cCiMMI();
virtual bool Process(int Length = 0, const uint8_t *Data = NULL); virtual bool Process(int Length = 0, const uint8_t *Data = NULL);
virtual bool HasUserIO(void) { return menu || enquiry; } virtual bool HasUserIO(void) { return menu || enquiry; }
@ -1204,7 +1204,7 @@ public:
bool SendCloseMMI(void); bool SendCloseMMI(void);
}; };
cCiMMI::cCiMMI(int SessionId, cCiTransportConnection *Tc) cCiMMI::cCiMMI(uint16_t SessionId, cCiTransportConnection *Tc)
:cCiSession(SessionId, RI_MMI, Tc) :cCiSession(SessionId, RI_MMI, Tc)
{ {
dbgprotocol("New MMI (session id %d)\n", SessionId); dbgprotocol("New MMI (session id %d)\n", SessionId);
@ -1524,12 +1524,12 @@ cCiHandler *cCiHandler::CreateCiHandler(const char *FileName)
return NULL; return NULL;
} }
int cCiHandler::ResourceIdToInt(const uint8_t *Data) uint32_t cCiHandler::ResourceIdToInt(const uint8_t *Data)
{ {
return (ntohl(get_unaligned((int32_t *)Data))); return (ntohl(get_unaligned((uint32_t *)Data)));
} }
bool cCiHandler::Send(uint8_t Tag, int SessionId, int ResourceId, int Status) bool cCiHandler::Send(uint8_t Tag, uint16_t SessionId, uint32_t ResourceId, int Status)
{ {
uint8_t buffer[16]; uint8_t buffer[16];
uint8_t *p = buffer; uint8_t *p = buffer;
@ -1538,7 +1538,7 @@ bool cCiHandler::Send(uint8_t Tag, int SessionId, int ResourceId, int Status)
if (Status >= 0) if (Status >= 0)
*p++ = Status; *p++ = Status;
if (ResourceId) { if (ResourceId) {
put_unaligned(htonl(ResourceId), (int32_t *)p); put_unaligned(htonl(ResourceId), (uint32_t *)p);
p += 4; p += 4;
} }
put_unaligned(htons(SessionId), (uint16_t *)p); put_unaligned(htons(SessionId), (uint16_t *)p);
@ -1547,7 +1547,7 @@ bool cCiHandler::Send(uint8_t Tag, int SessionId, int ResourceId, int Status)
return tc && tc->SendData(p - buffer, buffer) == OK; return tc && tc->SendData(p - buffer, buffer) == OK;
} }
cCiSession *cCiHandler::GetSessionBySessionId(int SessionId) cCiSession *cCiHandler::GetSessionBySessionId(uint16_t SessionId)
{ {
for (int i = 0; i < MAX_CI_SESSION; i++) { for (int i = 0; i < MAX_CI_SESSION; i++) {
if (sessions[i] && sessions[i]->SessionId() == SessionId) if (sessions[i] && sessions[i]->SessionId() == SessionId)
@ -1556,7 +1556,7 @@ cCiSession *cCiHandler::GetSessionBySessionId(int SessionId)
return NULL; return NULL;
} }
cCiSession *cCiHandler::GetSessionByResourceId(int ResourceId, int Slot) cCiSession *cCiHandler::GetSessionByResourceId(uint32_t ResourceId, int Slot)
{ {
for (int i = 0; i < MAX_CI_SESSION; i++) { for (int i = 0; i < MAX_CI_SESSION; i++) {
if (sessions[i] && sessions[i]->Tc()->Slot() == Slot && sessions[i]->ResourceId() == ResourceId) if (sessions[i] && sessions[i]->Tc()->Slot() == Slot && sessions[i]->ResourceId() == ResourceId)
@ -1565,7 +1565,7 @@ cCiSession *cCiHandler::GetSessionByResourceId(int ResourceId, int Slot)
return NULL; return NULL;
} }
cCiSession *cCiHandler::CreateSession(int ResourceId) cCiSession *cCiHandler::CreateSession(uint32_t ResourceId)
{ {
if (!GetSessionByResourceId(ResourceId, tc->Slot())) { if (!GetSessionByResourceId(ResourceId, tc->Slot())) {
for (int i = 0; i < MAX_CI_SESSION; i++) { for (int i = 0; i < MAX_CI_SESSION; i++) {
@ -1588,7 +1588,7 @@ cCiSession *cCiHandler::CreateSession(int ResourceId)
bool cCiHandler::OpenSession(int Length, const uint8_t *Data) bool cCiHandler::OpenSession(int Length, const uint8_t *Data)
{ {
if (Length == 6 && *(Data + 1) == 0x04) { if (Length == 6 && *(Data + 1) == 0x04) {
int ResourceId = ResourceIdToInt(Data + 2); uint32_t ResourceId = ResourceIdToInt(Data + 2);
dbgprotocol("OpenSession %08X\n", ResourceId); dbgprotocol("OpenSession %08X\n", ResourceId);
switch (ResourceId) { switch (ResourceId) {
case RI_RESOURCE_MANAGER: case RI_RESOURCE_MANAGER:
@ -1611,9 +1611,9 @@ bool cCiHandler::OpenSession(int Length, const uint8_t *Data)
return false; return false;
} }
bool cCiHandler::CloseSession(int SessionId) bool cCiHandler::CloseSession(uint16_t SessionId)
{ {
dbgprotocol("CloseSession %08X\n", SessionId); dbgprotocol("CloseSession %d\n", SessionId);
cCiSession *Session = GetSessionBySessionId(SessionId); cCiSession *Session = GetSessionBySessionId(SessionId);
if (Session && sessions[SessionId - 1] == Session) { if (Session && sessions[SessionId - 1] == Session) {
delete Session; delete Session;
@ -1675,7 +1675,7 @@ bool cCiHandler::Process(int Slot)
if (Data && Length > 1) { if (Data && Length > 1) {
switch (*Data) { switch (*Data) {
case ST_SESSION_NUMBER: if (Length > 4) { case ST_SESSION_NUMBER: if (Length > 4) {
int SessionId = ntohs(get_unaligned((uint16_t *)&Data[2])); uint16_t SessionId = ntohs(get_unaligned((uint16_t *)&Data[2]));
cCiSession *Session = GetSessionBySessionId(SessionId); cCiSession *Session = GetSessionBySessionId(SessionId);
if (Session) if (Session)
Session->Process(Length - 4, Data + 4); Session->Process(Length - 4, Data + 4);

14
ci.h
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: ci.h 1.21 2006/01/07 15:03:05 kls Exp $ * $Id: ci.h 1.22 2006/08/12 09:43:31 kls Exp $
*/ */
#ifndef __CI_H #ifndef __CI_H
@ -110,14 +110,14 @@ private:
int source; int source;
int transponder; int transponder;
cList<cCiCaProgramData> caProgramList; cList<cCiCaProgramData> caProgramList;
int ResourceIdToInt(const uint8_t *Data); uint32_t ResourceIdToInt(const uint8_t *Data);
bool Send(uint8_t Tag, int SessionId, int ResourceId = 0, int Status = -1); bool Send(uint8_t Tag, uint16_t SessionId, uint32_t ResourceId = 0, int Status = -1);
const unsigned short *GetCaSystemIds(int Slot); const unsigned short *GetCaSystemIds(int Slot);
cCiSession *GetSessionBySessionId(int SessionId); cCiSession *GetSessionBySessionId(uint16_t SessionId);
cCiSession *GetSessionByResourceId(int ResourceId, int Slot); cCiSession *GetSessionByResourceId(uint32_t ResourceId, int Slot);
cCiSession *CreateSession(int ResourceId); cCiSession *CreateSession(uint32_t ResourceId);
bool OpenSession(int Length, const uint8_t *Data); bool OpenSession(int Length, const uint8_t *Data);
bool CloseSession(int SessionId); bool CloseSession(uint16_t SessionId);
int CloseAllSessions(int Slot); int CloseAllSessions(int Slot);
cCiHandler(int Fd, int NumSlots); cCiHandler(int Fd, int NumSlots);
void SendCaPmt(void); void SendCaPmt(void);