diddfunc.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* $Id: diddfunc.c,v 1.14.6.2 2004/08/28 20:03:53 armin Exp $
  2. *
  3. * DIDD Interface module for Eicon active cards.
  4. *
  5. * Functions are in dadapter.c
  6. *
  7. * Copyright 2002-2003 by Armin Schindler (mac@melware.de)
  8. * Copyright 2002-2003 Cytronics & Melware (info@melware.de)
  9. *
  10. * This software may be used and distributed according to the terms
  11. * of the GNU General Public License, incorporated herein by reference.
  12. */
  13. #include "platform.h"
  14. #include "di_defs.h"
  15. #include "dadapter.h"
  16. #include "divasync.h"
  17. #define DBG_MINIMUM (DL_LOG + DL_FTL + DL_ERR)
  18. #define DBG_DEFAULT (DBG_MINIMUM + DL_XLOG + DL_REG)
  19. extern void DIVA_DIDD_Read(void *, int);
  20. extern char *DRIVERRELEASE_DIDD;
  21. static dword notify_handle;
  22. static DESCRIPTOR _DAdapter;
  23. /*
  24. * didd callback function
  25. */
  26. static void *didd_callback(void *context, DESCRIPTOR *adapter,
  27. int removal)
  28. {
  29. if (adapter->type == IDI_DADAPTER) {
  30. DBG_ERR(("Notification about IDI_DADAPTER change ! Oops."))
  31. return (NULL);
  32. } else if (adapter->type == IDI_DIMAINT) {
  33. if (removal) {
  34. DbgDeregister();
  35. } else {
  36. DbgRegister("DIDD", DRIVERRELEASE_DIDD, DBG_DEFAULT);
  37. }
  38. }
  39. return (NULL);
  40. }
  41. /*
  42. * connect to didd
  43. */
  44. static int __init connect_didd(void)
  45. {
  46. int x = 0;
  47. int dadapter = 0;
  48. IDI_SYNC_REQ req;
  49. DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
  50. DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
  51. for (x = 0; x < MAX_DESCRIPTORS; x++) {
  52. if (DIDD_Table[x].type == IDI_DADAPTER) { /* DADAPTER found */
  53. dadapter = 1;
  54. memcpy(&_DAdapter, &DIDD_Table[x], sizeof(_DAdapter));
  55. req.didd_notify.e.Req = 0;
  56. req.didd_notify.e.Rc =
  57. IDI_SYNC_REQ_DIDD_REGISTER_ADAPTER_NOTIFY;
  58. req.didd_notify.info.callback = (void *)didd_callback;
  59. req.didd_notify.info.context = NULL;
  60. _DAdapter.request((ENTITY *)&req);
  61. if (req.didd_notify.e.Rc != 0xff)
  62. return (0);
  63. notify_handle = req.didd_notify.info.handle;
  64. } else if (DIDD_Table[x].type == IDI_DIMAINT) { /* MAINT found */
  65. DbgRegister("DIDD", DRIVERRELEASE_DIDD, DBG_DEFAULT);
  66. }
  67. }
  68. return (dadapter);
  69. }
  70. /*
  71. * disconnect from didd
  72. */
  73. static void __exit disconnect_didd(void)
  74. {
  75. IDI_SYNC_REQ req;
  76. req.didd_notify.e.Req = 0;
  77. req.didd_notify.e.Rc = IDI_SYNC_REQ_DIDD_REMOVE_ADAPTER_NOTIFY;
  78. req.didd_notify.info.handle = notify_handle;
  79. _DAdapter.request((ENTITY *)&req);
  80. }
  81. /*
  82. * init
  83. */
  84. int __init diddfunc_init(void)
  85. {
  86. diva_didd_load_time_init();
  87. if (!connect_didd()) {
  88. DBG_ERR(("init: failed to connect to DIDD."))
  89. diva_didd_load_time_finit();
  90. return (0);
  91. }
  92. return (1);
  93. }
  94. /*
  95. * finit
  96. */
  97. void __exit diddfunc_finit(void)
  98. {
  99. DbgDeregister();
  100. disconnect_didd();
  101. diva_didd_load_time_finit();
  102. }