PcscLibrary.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. #ifndef __LoadLibrary_H__
  2. #define __LoadLibrary_H__
  3. #include <stdio.h> //标准输入输出定义
  4. #include <string.h>
  5. #include <stdlib.h> //标准函数库定义
  6. #include <unistd.h> //Unix标准函数定义
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <fcntl.h> //文件控制定义
  10. #include <termios.h> //PPSIX终端控制定义
  11. #include <errno.h> //错误号定义
  12. #include <dlfcn.h>
  13. //二代证信息
  14. typedef struct
  15. {
  16. char szName[31]; //姓名
  17. char szSex[5]; //性别
  18. char szNation[20]; //民族
  19. char szBornDay[10]; //出生
  20. char szAddress[128]; //地址
  21. char szIDNum[20]; //身份证编号
  22. char szIssued[51]; //签发机关
  23. char szBeginValidity[10]; //开始有效日期
  24. char szEndValidity[10]; //截止有效日期
  25. char szHeadPath[256]; //小头像路径
  26. }CRTDef_IDInfo, *pCRTDef_IDInf;
  27. /**
  28. * @fn CRT_OpenConnect
  29. * @detail 打开CRT智能读卡器
  30. * @see ...
  31. * @param iListNums:输出 连接的读卡器列表个数
  32. * @return 0 成功,非0失败
  33. * @exception ...
  34. *
  35. * @author luowei
  36. * @date 2015/12/1
  37. */
  38. typedef int (*pCRT_OpenConnect)(int* iListNums);
  39. /**
  40. * @fn CRT_CloseConnect
  41. * @detail 关闭CRT智能读卡器
  42. * @see ...
  43. * @return 0 成功,非0失败
  44. * @exception ...
  45. *
  46. * @author luowei
  47. * @date 2015/12/1
  48. */
  49. typedef int (*pCRT_CloseConnect)();
  50. /**
  51. * @fn CRT_GetReaderListName
  52. * @detail 获取智能读卡器列表名字
  53. * @see ...
  54. * @param iListNum:需获取的读卡器序列号(0为起始)
  55. * @param szListName:输出 获取到的读卡器名字
  56. * @return 0 成功, 非0失败
  57. * @exception ...
  58. *
  59. * @author luowei
  60. * @date 2015/12/1
  61. */
  62. typedef int (*pCRT_GetReaderListName)(int iListNum, char szListName[]);
  63. /**
  64. * @fn CRT_SetReaderName
  65. * @detail 设置当前工作的读卡器序列号(打开时,默认设置为第一个读卡器)
  66. * @see ...
  67. * @param iListNum:需设置的读卡器序列号(0为起始)
  68. * @return 0 成功, 非0失败
  69. * @exception ...
  70. *
  71. * @author luowei
  72. * @date 2015/12/1
  73. */
  74. typedef int (*pCRT_SetReaderName)(int iListNum);
  75. /**
  76. * @fn CRT_GetCardStatus
  77. * @detail 获取读卡器上卡状态
  78. * @see ...
  79. * @return 1 有卡, 2 无卡, 9 状态未知
  80. * @exception ...
  81. *
  82. * @author luowei
  83. * @date 2015/12/1
  84. */
  85. typedef int (*pCRT_GetCardStatus)();
  86. /**
  87. * @fn CRT_EjectCard
  88. * @detail 弹卡下电,读卡器断开连接
  89. * @see ...
  90. * @return 0 成功,非0失败
  91. * @exception ...
  92. *
  93. * @author luowei
  94. * @date 2015/12/1
  95. */
  96. typedef int (*pCRT_EjectCard)();
  97. /**
  98. * @fn CRT_ReaderConnect
  99. * @detail 读卡器卡片上电
  100. * @see ...
  101. * @param byAtrData:输出 上电成功返回的ATR数据
  102. * @param iAtrLen: 输出 上电成功返回的ATR数据长度
  103. * @return 0 成功,非0失败
  104. * @exception ...
  105. *
  106. * @author luowei
  107. * @date 2015/12/1
  108. */
  109. typedef int (*pCRT_ReaderConnect)(unsigned char byAtrData[], int* iAtrLen);
  110. /**
  111. * @fn CRT_SendApdu
  112. * @detail 读卡器发送APDU指令
  113. * @see ...
  114. * @param bySendData:需发送的APDU指令(支持acsii码与BCD码)
  115. * @param iSendDataLen: 需发送的APDU指令长度
  116. * @param byRecvData:输出 APDU通讯后返回的数据
  117. * @param iRecvDataLen: 输出 APDU通讯后返回的数据长度
  118. * @return 0 成功,非0失败
  119. * @exception ...
  120. *
  121. * @author luowei
  122. * @date 2015/12/1
  123. */
  124. typedef int (*pCRT_SendApdu)(unsigned char bySendData[], int iSendDataLen, unsigned char byRecvData[], int* iRecvDataLen);
  125. /**
  126. * @fn CRT_SendControlCMD
  127. * @detail 读卡器发送扩展控制命令
  128. * @see ...
  129. * @param bySendData:需发送的扩展控制命令数据(支持acsii码与BCD码)
  130. * @param iSendDataLen: 需发送的扩展控制命令数据长度
  131. * @param byRecvData:输出 扩展控制命令通讯后返回的数据
  132. * @param iRecvDataLen: 输出 扩展控制命令通讯后返回的数据长度
  133. * @return 0 成功,非0失败
  134. * @exception ...
  135. *
  136. * @author luowei
  137. * @date 2015/12/1
  138. */
  139. typedef int (*pCRT_SendControlCMD)(unsigned char bySendData[], int iSendDataLen, unsigned char byRecvData[], int* iRecvDataLen);
  140. //***********************发送CRT603具体功能扩展命令****************************
  141. /**
  142. * @fn CRT_HotReset
  143. * @detail 读卡器热复位
  144. * @see ...
  145. * @return 0 成功,非0失败
  146. * @exception ...
  147. *
  148. * @author luowei
  149. * @date 2015/12/1
  150. */
  151. typedef int (*pCRT_HotReset)();
  152. /**
  153. * @fn CRT_SetReaderType
  154. * @detail 设置读卡器操作模式
  155. * @see ...
  156. * @param iType: 1 正常RF卡模式, 2 Felica模式, 3 点对点模式, 4 二代证模式, 5 卡模拟模式
  157. * @return 0 成功,非0失败
  158. * @exception ...
  159. *
  160. * @author luowei
  161. * @date 2015/12/1
  162. */
  163. typedef int (*pCRT_SetReaderType)(int iType);
  164. /**
  165. * @fn CRT_GetReaderType
  166. * @detail 获取读卡器操作模式
  167. * @see ...
  168. * @return >0 失败 1 正常RF卡模式, 2 Felica模式, 3 点对点模式, 4 二代证模式, 5 卡模拟模式
  169. * @exception ...
  170. *
  171. * @author luowei
  172. * @date 2015/12/1
  173. */
  174. typedef int (*pCRT_GetReaderType)();
  175. /**
  176. * @fn CRT_GetVersionInfo
  177. * @detail 获取读卡器版本信息
  178. * @see ...
  179. * @param iVerType: 需获取的版本 0 P/N信息, 1 SN信息, 2, 固件版本信息, 3 生成版本信息, 4 EMID信息, 5 动态库版本信息
  180. * @param szVersionInfo: 输出 返回的版本信息
  181. * @return 0 成功,非0失败
  182. * @exception ...
  183. *
  184. * @author luowei
  185. * @date 2015/12/1
  186. */
  187. typedef int (*pCRT_GetVersionInfo)(int iVerType, char szVersionInfo[]);
  188. /**
  189. * @fn CRT_AutoBeel
  190. * @detail 读卡器自动蜂鸣
  191. * @see ...
  192. * @param bAutoBeel: 是否自动蜂鸣,true 开启,false 关闭
  193. * @return 0 成功,非0失败
  194. * @exception ...
  195. *
  196. * @author luowei
  197. * @date 2015/12/1
  198. */
  199. typedef int (*pCRT_AutoBeel)(bool bAutoBeel);
  200. /**
  201. * @fn CRT_Beel
  202. * @detail 读卡器蜂鸣设置
  203. * @see ...
  204. * @param MultipleTime: 蜂鸣时间:0.25秒的倍数,比如2,蜂鸣时间:2*0.25 即0.5秒(0-20 默认为1)
  205. * @return 0 成功,非0失败
  206. * @exception ...
  207. *
  208. * @author luowei
  209. * @date 2015/12/1
  210. */
  211. typedef int (*pCRT_Beel)(int MultipleTime);
  212. /**
  213. * @fn CRT_SetLightMode
  214. * @detail 设置读卡器指示灯模式
  215. * @see ...
  216. * @param iType: 指示灯模式 0 自动模式, 1 手动模式
  217. * @return 0 成功,非0失败
  218. * @exception ...
  219. *
  220. * @author luowei
  221. * @date 2015/12/1
  222. */
  223. typedef int (*pCRT_SetLightMode)(int iType);
  224. /**
  225. * @fn CRT_GetLightMode
  226. * @detail 获取读卡器指示灯模式
  227. * @see ...
  228. * @return 0 自动模式,1 手动模式, 9模式未知
  229. * @exception ...
  230. *
  231. * @author luowei
  232. * @date 2015/12/1
  233. */
  234. typedef int (*pCRT_GetLightMode)();
  235. /**
  236. * @fn CRT_SetLightStatus
  237. * @detail 设置读卡器指示灯状态
  238. * @see ...
  239. * @param iYellowType: 黄色指示灯状态 0 关, 1 开, 2 闪烁
  240. * @param iBlueType: 蓝色指示灯状态 0 关, 1 开, 2 闪烁
  241. * @param iGreenType: 绿色指示灯状态 0 关, 1 开, 2 闪烁
  242. * @param iRedType: 红色指示灯状态 0 关, 1 开, 2 闪烁
  243. * @return 0 成功,非0失败
  244. * @exception ...
  245. *
  246. * @author luowei
  247. * @date 2015/12/1
  248. */
  249. typedef int (*pCRT_SetLightStatus)(int iYellowType, int iBlueType, int iGreenType, int iRedType);
  250. /**
  251. * @fn CRT_SetLightStatus
  252. * @detail 获取读卡器指示灯状态
  253. * @see ...
  254. * @param iYellowType: 输出 黄色指示灯状态 0 关, 1 开, 2 闪烁
  255. * @param iBlueType: 输出 蓝色指示灯状态 0 关, 1 开, 2 闪烁
  256. * @param iGreenType: 输出 绿色指示灯状态 0 关, 1 开, 2 闪烁
  257. * @param iRedType: 输出 红色指示灯状态 0 关, 1 开, 2 闪烁
  258. * @return 0 成功,非0失败
  259. * @exception ...
  260. *
  261. * @author luowei
  262. * @date 2015/12/1
  263. */
  264. typedef int (*pCRT_GetLightStatus)(int* iYellowType, int* iBlueType, int* iGreenType, int* iRedType);
  265. /**
  266. * @fn CRT_BanTypeBCap
  267. * @detail 设置读卡器读取TYPE B卡能力
  268. * @see ...
  269. * @param bBan: 是否关闭读TYPE B卡能力。 true 关闭, false 打开
  270. * @return 0 成功,非0失败
  271. * @exception ...
  272. *
  273. * @author luowei
  274. * @date 2015/12/1
  275. */
  276. typedef int (*pCRT_BanTypeBCap)(bool bBan);
  277. //***********************发送CRT603具体功能APDU命令****************************
  278. /**
  279. * @fn CRT_LoadMifareKey
  280. * @detail Mifare卡下载密码
  281. * @see ...
  282. * @param ilocal: 密码存储位置。 0 临时性存储器, 1 非易失存储器
  283. * @param iKeyType: 密钥类型。 0 TYPE A类型, 1 TYPE B类型
  284. * @param iKeyNum: 将保存到密钥组号(共0-15组)
  285. * @param byInKeyData: 密码信息。 (共6位,如0xFF,0xFF,0xFF,0xFF,0xFF,0xFF)
  286. * @return 0 成功,非0失败
  287. * @exception ...
  288. *
  289. * @author luowei
  290. * @date 2015/12/1
  291. */
  292. typedef int (*pCRT_LoadMifareKey)(int ilocal, int iKeyType, int iKeyNum, unsigned char byInKeyData[]);
  293. /**
  294. * @fn CRT_CheckMifareKey
  295. * @detail Mifare卡校验密码
  296. * @see ...
  297. * @param iKeyType: 密钥类型。 0 TYPE A类型, 1 TYPE B类型
  298. * @param iKeyNum: 已下载好的密钥组号(共0-15组)
  299. * @param iBlockNum: 需校验的Mifare卡块号(0为起始位)
  300. * @return 0 成功,非0失败
  301. * @exception ...
  302. *
  303. * @author luowei
  304. * @date 2015/12/1
  305. */
  306. typedef int (*pCRT_CheckMifareKey)(int iKeyType, int iKeyNum, int iBlockNum);
  307. /**
  308. * @fn CRT_Read
  309. * @detail 非CPU卡读数据操作
  310. * @see ...
  311. * @param bFilica: 是否为filica卡读操作。 true 是filica, false 非filica
  312. * @param iBlockNum: 需读取的卡块号(0为起始位)
  313. * @param byReadData: 输出 读取到的数据
  314. * @param iReadDataLen: 输出 读取到的数据长度
  315. * @return 0 成功,非0失败
  316. * @exception ...
  317. *
  318. * @author luowei
  319. * @date 2015/12/1
  320. */
  321. typedef int (*pCRT_Read)(bool bFilica, int iBlockNum, unsigned char byReadData[], int* iReadDataLen);
  322. /**
  323. * @fn CRT_Write
  324. * @detail 非CPU卡写数据操作
  325. * @see ...
  326. * @param bFilica: 是否为filica卡读操作。 true 是filica, false 非filica
  327. * @param iBlockNum: 需写入的卡块号(0为起始位)
  328. * @param byWriteData: 写入到读卡器上的数据
  329. * @param iWriteLen: 写入到读卡器上的数据长度
  330. * @return 0 成功,非0失败
  331. * @exception ...
  332. *
  333. * @author luowei
  334. * @date 2015/12/1
  335. */
  336. typedef int (*pCRT_Write)(bool bFilica, int iBlockNum, unsigned char byWriteData[], int iWriteLen);
  337. /**
  338. * @fn CRT_GetCardUID
  339. * @detail 获取卡片UID信息
  340. * @see ...
  341. * @param szUID: 输出 卡片的UID信息
  342. * @return 0 成功,非0失败
  343. * @exception ...
  344. *
  345. * @author luowei
  346. * @date 2015/12/1
  347. */
  348. typedef int (*pCRT_GetCardUID)(char szUID[]);
  349. //***********************发送CRT603具体功能SAM卡命令****************************
  350. /**
  351. * @fn CRT_SAMSlotActivation
  352. * @detail SAM卡切换并激活卡座
  353. * @see ...
  354. * @param iSlotNum: 需切换激活的卡座号 (1-4个,如 1表示SAM1卡座)
  355. * @return 0 成功,非0失败
  356. * @exception ...
  357. *
  358. * @author luowei
  359. * @date 2015/12/1
  360. */
  361. typedef int (*pCRT_SAMSlotActivation)(int iSlotNum);
  362. //***********************磁条卡操作命令****************************
  363. /**
  364. * @fn CRT_ReadMagAllTracks
  365. * @detail 读所有磁道操作
  366. * @see ...
  367. * @param szTrack1: 磁道1数据 ‘Not’未读取到
  368. * @param szTrack2: 磁道2数据 ‘Not’未读取到
  369. * @param szTrack3: 磁道3数据 ‘Not’未读取到
  370. * @return 0 成功,非0失败
  371. * @exception ...
  372. *
  373. * @author luowei
  374. * @date 2015/12/1
  375. */
  376. typedef int (*pCRT_ReadMagAllTracks)(char szTrack1[], char szTrack2[], char szTrack3[]);
  377. //***********************获取RF卡类型****************************
  378. /**
  379. * @fn CRT_GetRFCardType
  380. * @detail 获取RF卡类型
  381. * @see ...
  382. * @return 0 无卡,1 TYPE A类型卡, 2 TYPE B类型卡, 3 身份证, 其他 失败
  383. * @exception ...
  384. *
  385. * @author luowei
  386. * @date 2015/12/1
  387. */
  388. typedef int (*pCRT_GetRFCardType)();
  389. //***********************读二代证信息命令****************************
  390. /**
  391. * @fn CRT_ReadIDCardInifo
  392. * @detail 读二代证信息
  393. * @see ...
  394. * @param crtdef_IdInfo: 输出,读取到的二代证信息
  395. * @return 0 成功,非0失败
  396. * @exception ...
  397. *
  398. * @author luowei
  399. * @date 2015/12/1
  400. */
  401. typedef int (*pCRT_ReadIDCardInifo)(CRTDef_IDInfo* crtdef_IdInfo);
  402. /**
  403. * @fn CRT_M1ValueProcess
  404. * @detail M1卡值操作
  405. * @see ...
  406. * @param iMode: 输入,操作模式。 1 初始化钱包, 2 增值, 3 减值
  407. * @param iBlock: 输入,操作块区。 需绝对地址
  408. * @param iValue: 输入,操作金额
  409. * @return 0 成功,非0失败
  410. * @exception ...
  411. *
  412. * @author luowei
  413. * @date 2016/9/19
  414. */
  415. typedef int (*pCRT_M1ValueProcess)(int iMode, int iBlock, int iValue);
  416. /**
  417. * @fn CRT_M1InquireBalance
  418. * @detail M1卡查询余额
  419. * @see ...
  420. * @param iBlock: 输入,操作块区。 需绝对地址
  421. * @param iValue: 输出,查询到的金额值
  422. * @return 0 成功,非0失败
  423. * @exception ...
  424. *
  425. * @author luowei
  426. * @date 2016/9/19
  427. */
  428. typedef int (*pCRT_M1InquireBalance)(int iBlock, int* iValue);
  429. /**
  430. * @fn CRT_M1BackBlock
  431. * @detail M1卡备份钱包
  432. * @see ...
  433. * @param iBlock: 输入,需备份块区。 需绝对地址
  434. * @param iBackBlock: 输入,备份到块区。 需绝对地址
  435. * @return 0 成功,非0失败
  436. * @exception ...
  437. *
  438. * @author luowei
  439. * @date 2016/9/19
  440. */
  441. typedef int (*pCRT_M1BackBlock)(int iBlock, int iBackBlock);
  442. /**
  443. * @fn CRT_GetIDFinger
  444. * @detail 获取二代证指纹信息
  445. * @see ...
  446. * @param byFinger: 输出,获取到的指纹信息(一般为1024个字节)
  447. * @param iFingerLen: 输出,指纹信息长度
  448. * @return 0 成功,非0失败
  449. * @exception ...
  450. *
  451. * @author luowei
  452. * @date 2016/10/27
  453. */
  454. typedef int (*pCRT_GetIDFinger)(unsigned char byFinger[], int *iFingerLen);
  455. /**
  456. * @fn CRT_GetIDFinger
  457. * @detail 获取二代证DN号
  458. * @see ...
  459. * @param szDNNums: 输出,获取到的DN号
  460. * @return 0 成功,非0失败
  461. * @exception ...
  462. *
  463. * @author luowei
  464. * @date 2016/10/30
  465. */
  466. typedef int (*pCRT_GetIDDNNums)(char szDNNums[]);
  467. /**
  468. * @fn CRT_GetSAMID
  469. * @detail 获取身份证盒子SAM ID
  470. * @see ...
  471. * @param szSAMID: 输出,获取到的SAM ID
  472. * @return 0 成功,非0失败
  473. * @exception ...
  474. *
  475. * @author luowei
  476. * @date 2016/10/30
  477. */
  478. typedef int (*pCRT_GetSAMID)(char szSAMID[]);
  479. /**
  480. * @fn CRT_SwitchRF
  481. * @detail 读卡器开关射频场
  482. * @see ...
  483. * @param iMode: 输入 开关射频场方式,0 开启, 1 关闭
  484. * @return 0 成功,非0失败
  485. * @exception ...
  486. *
  487. * @author luowei
  488. * @date 2016/10/30
  489. */
  490. typedef int (*pCRT_SwitchRF)(int iMode);
  491. //***********************获取最后一次错误描叙****************************
  492. /**
  493. * @fn CRT_GetLastError
  494. * @detail 获取最后一次错误描叙
  495. * @see ...
  496. * @return 获取信息
  497. * @exception ...
  498. *
  499. * @author luowei
  500. * @date 2015/12/1
  501. */
  502. typedef char* (*pCRT_GetLastError)();
  503. class CPcscLibrary
  504. {
  505. //对外接口函数
  506. public:
  507. bool Load(const char* lpDllPath, char* ErrorInfo);
  508. bool IsLoadSucceed();
  509. pCRT_OpenConnect OpenConnect ;
  510. pCRT_CloseConnect CloseConnect;
  511. pCRT_GetReaderListName GetReaderListName;
  512. pCRT_SetReaderName SetReaderName;
  513. pCRT_GetReaderType GetReaderType;
  514. pCRT_GetCardStatus GetCardStatus;
  515. pCRT_EjectCard EjectCard;
  516. pCRT_ReaderConnect ReaderConnect;
  517. pCRT_SendApdu SendApdu;
  518. pCRT_SendControlCMD SendControlCMD;
  519. pCRT_HotReset HotReset;
  520. pCRT_SetReaderType SetReaderType;
  521. pCRT_GetVersionInfo GetVersionInfo;
  522. pCRT_AutoBeel AutoBeel;
  523. pCRT_Beel Beel;
  524. pCRT_SetLightMode SetLightMode;
  525. pCRT_GetLightMode GetLightMode;
  526. pCRT_SetLightStatus SetLightStatus;
  527. pCRT_GetLightStatus GetLightStatus;
  528. pCRT_BanTypeBCap BanTypeBCap;
  529. pCRT_LoadMifareKey LoadMifareKey;
  530. pCRT_CheckMifareKey CheckMifareKey;
  531. pCRT_Read Read;
  532. pCRT_Write Write;
  533. pCRT_GetCardUID GetCardUID;
  534. pCRT_SAMSlotActivation SAMSlotActivation;
  535. pCRT_ReadMagAllTracks ReadMagAllTracks;
  536. pCRT_GetRFCardType GetRFCardType;
  537. pCRT_ReadIDCardInifo ReadIDCardInifo;
  538. pCRT_M1ValueProcess M1ValueProcess;
  539. pCRT_M1InquireBalance M1InquireBalance;
  540. pCRT_M1BackBlock M1BackBlock;
  541. pCRT_GetIDFinger GetIDFinger;
  542. pCRT_GetIDDNNums GetIDDNNums;
  543. pCRT_GetSAMID GetSAMID;
  544. pCRT_SwitchRF SwitchRF;
  545. pCRT_GetLastError GetLastError;
  546. private:
  547. void * hModule;
  548. bool returnValue;
  549. public:
  550. CPcscLibrary(void);
  551. ~CPcscLibrary(void);
  552. };
  553. #endif //__LoadLibrary_H__