1 #include <lib/dvb/dvb.h>
\r
2 #include <lib/dvb/frontendparms.h>
\r
9 #include <sys/ioctl.h>
\r
10 #include <sys/types.h>
\r
11 #include <sys/stat.h>
\r
12 #include <sys/poll.h>
\r
16 #include <termios.h>
\r
17 #include <lib/driver/sc_test.h>
\r
19 #include <lib/base/eerror.h>
\r
20 #include <lib/base/estring.h>
\r
23 #include <sys/time.h>
\r
27 #define SC_CHECK_TIMEOUT 5
\r
28 #define SC_REMOVE_TIMEOUT 10
\r
31 #define SMART_CARD0 "/dev/sci0" /* upper smart card */
\r
32 #define SMART_CARD1 "/dev/sci1" /* lower smart card */
\r
34 #define SC_SUCCESS 0
\r
35 #define NO_DEV_FOUND -1
\r
36 #define SC_NOT_INSERTED -2
\r
37 #define SC_NOT_VALID_ATR -3
\r
38 #define SC_NOT_REMOVED -4
\r
39 #define SC_READ_TIMEOUT -5
\r
42 #define SCI_IOW_MAGIC 's'
\r
44 /* ioctl cmd table */
\r
45 //#include "sci_global.h"
\r
46 #define IOCTL_SET_RESET _IOW(SCI_IOW_MAGIC, 1, unsigned long)
\r
47 #define IOCTL_SET_MODES _IOW(SCI_IOW_MAGIC, 2, SCI_MODES)
\r
48 #define IOCTL_GET_MODES _IOW(SCI_IOW_MAGIC, 3, SCI_MODES)
\r
49 #define IOCTL_SET_PARAMETERS _IOW(SCI_IOW_MAGIC, 4, SCI_PARAMETERS)
\r
50 #define IOCTL_GET_PARAMETERS _IOW(SCI_IOW_MAGIC, 5, SCI_PARAMETERS)
\r
51 #define IOCTL_SET_CLOCK_START _IOW(SCI_IOW_MAGIC, 6, unsigned long)
\r
52 #define IOCTL_SET_CLOCK_STOP _IOW(SCI_IOW_MAGIC, 7, unsigned long)
\r
53 #define IOCTL_GET_IS_CARD_PRESENT _IOW(SCI_IOW_MAGIC, 8, unsigned long)
\r
54 #define IOCTL_GET_IS_CARD_ACTIVATED _IOW(SCI_IOW_MAGIC, 9, unsigned long)
\r
55 #define IOCTL_SET_DEACTIVATE _IOW(SCI_IOW_MAGIC, 10, unsigned long)
\r
56 #define IOCTL_SET_ATR_READY _IOW(SCI_IOW_MAGIC, 11, unsigned long)
\r
57 #define IOCTL_GET_ATR_STATUS _IOW(SCI_IOW_MAGIC, 12, unsigned long)
\r
58 #define IOCTL_DUMP_REGS _IOW(SCI_IOW_MAGIC, 20, unsigned long)
\r
60 eSctest *eSctest::instance;
\r
74 int eSctest::n_check_smart_card(char *dev_name)
\r
77 struct pollfd pollfd;
\r
78 unsigned char buf[64];
\r
81 int count = SC_CHECK_TIMEOUT;
\r
84 fd = ::open(dev_name, O_RDWR);
\r
87 eDebug("sci0 open error\n");
\r
88 return NO_DEV_FOUND;
\r
91 eDebug("sci0 is opened fd : %d\n", fd);
\r
94 ::ioctl(fd, IOCTL_GET_IS_CARD_PRESENT, &modem_status);
\r
97 eDebug("card is now inserted\n");
\r
100 eDebug("card is NOT inserted\n");
\r
102 return SC_NOT_INSERTED;
\r
105 /* now smart card is inserted, let's do reset */
\r
107 ::ioctl(fd, IOCTL_SET_RESET, &modem_status);
\r
109 /* now we can get the ATR */
\r
112 pollfd.events = POLLIN|POLLOUT|POLLERR|POLLPRI;
\r
115 while(poll(&pollfd, 1, 1000)>=0 && count--){
\r
117 eDebug("pollfd.revents : 0x%x\n", pollfd.revents);
\r
118 if(pollfd.revents & POLLIN){
\r
119 eDebug(">>read \n");
\r
120 cnt = read(fd, buf, 64);
\r
121 eDebug("<<read cnt:%d\n", cnt);
\r
124 if(buf[0]==0x3b||buf[0]==0x3f)
\r
126 eDebug("read -%d : 0x%x",cnt, buf[0]);
\r
132 eDebug("no data\n");
\r
138 if (readok == 0) return SC_NOT_VALID_ATR;
\r
139 if(!count) return SC_READ_TIMEOUT;
\r
143 int eSctest::check_smart_card(char *dev_name)
\r
146 struct pollfd pollfd;
\r
147 unsigned char buf[64];
\r
150 int count = SC_CHECK_TIMEOUT;
\r
152 fd = ::open(dev_name, O_RDWR);
\r
155 eDebug("sci0 open error");
\r
156 return NO_DEV_FOUND;
\r
159 eDebug("sci0 is opened fd : %d", fd);
\r
161 ::tcflush(fd, TCIFLUSH);
\r
163 ::ioctl(fd, TIOCMGET, &modem_status);
\r
165 if( modem_status & TIOCM_CAR)
\r
166 eDebug("card is now inserted");
\r
169 eDebug("card is NOT inserted");
\r
171 return SC_NOT_INSERTED;
\r
174 /* now smart card is inserted, let's do reset */
\r
176 modem_status |= TIOCM_RTS;
\r
177 ::ioctl(fd, TIOCMSET, &modem_status);
\r
179 modem_status &= ~TIOCM_RTS;
\r
180 ::ioctl(fd, TIOCMSET, &modem_status);
\r
183 /* now we can get the ATR */
\r
186 pollfd.events = POLLIN|POLLOUT|POLLERR|POLLPRI;
\r
189 while(poll(&pollfd, 1, 1000)>=0 && count--){
\r
191 eDebug("pollfd.revents : 0x%x %d", pollfd.revents,count);
\r
192 if(pollfd.revents & POLLIN){
\r
194 cnt = ::read(fd, buf, 64);
\r
195 eDebug("<<read cnt:%d", cnt);
\r
199 for( i = 0 ; i < cnt ; i ++)
\r
203 eDebug("read : 0x%x", buf[i]);
\r
213 eDebug("readok = %d",readok);
\r
214 if (readok == 0) return SC_NOT_VALID_ATR;
\r
215 if(count<=0 ) return SC_READ_TIMEOUT;
\r
218 int eSctest::eject_smart_card(char *dev_name)
\r
221 struct pollfd pollfd;
\r
222 unsigned char buf[64];
\r
225 int count = SC_CHECK_TIMEOUT;
\r
227 fd = ::open(dev_name, O_RDWR);
\r
230 eDebug("sci0 open error");
\r
231 return NO_DEV_FOUND;
\r
234 eDebug("sci0 is opened fd : %d", fd);
\r
236 ::tcflush(fd, TCIFLUSH);
\r
238 ::ioctl(fd, TIOCMGET, &modem_status);
\r
240 if( modem_status & TIOCM_CAR)
\r
241 eDebug("card is now inserted");
\r
244 eDebug("card is NOT inserted");
\r
246 return SC_NOT_INSERTED;
\r
248 /* now we can get the ATR */
\r
251 pollfd.events = POLLIN|POLLOUT|POLLERR|POLLPRI;
\r
253 /* let's wait until card is removed for count secs.*/
\r
254 count = SC_REMOVE_TIMEOUT;
\r
256 ::ioctl(fd, TIOCMGET, &modem_status);
\r
257 eDebug("modem_status : 0x%x %d", modem_status,count);
\r
261 while((modem_status&TIOCM_CAR) && count--);
\r
263 if(count<=0 ) return SC_NOT_REMOVED;
\r
270 int eSctest::VFD_Open()
\r
272 VFD_fd = open("/dev/dbox/lcd0", O_RDWR);
\r
276 int eSctest::turnon_VFD()
\r
278 ioctl(VFD_fd, 0xa0a0a0a0, 0);
\r
281 int eSctest::turnoff_VFD()
\r
283 ioctl(VFD_fd, 0x01010101, 0);
\r
286 void eSctest::VFD_Close()
\r
291 extern int frontend0_fd;
\r
292 extern int frontend1_fd;
\r
294 int eSctest::getFrontendstatus(int fe)
\r
296 fe_status_t status;
\r
302 m_fd = frontend0_fd;
\r
304 m_fd = frontend1_fd;
\r
310 eDebug("%d open error ",fe);
\r
314 eDebug("%d open ok!!!! ",m_fd);
\r
316 if ( ioctl(m_fd, FE_READ_STATUS, &status) < 0)
\r
317 eDebug("%d read error ",fe);
\r
319 if (status&FE_HAS_LOCK)
\r