ibLoc.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /***************************************************************************
  2. lib/ibLoc.c
  3. -------------------
  4. copyright : (C) 2001,2002 by Frank Mori Hess
  5. email : fmhess@users.sourceforge.net
  6. ***************************************************************************/
  7. /***************************************************************************
  8. * *
  9. * This program is free software; you can redistribute it and/or modify *
  10. * it under the terms of the GNU General Public License as published by *
  11. * the Free Software Foundation; either version 2 of the License, or *
  12. * (at your option) any later version. *
  13. * *
  14. ***************************************************************************/
  15. #include "ib_internal.h"
  16. #include "ibP.h"
  17. #include <stdlib.h>
  18. int ibloc(int ud)
  19. {
  20. ibConf_t *conf;
  21. ibBoard_t *board;
  22. uint8_t cmd[32];
  23. unsigned int i;
  24. ssize_t count;
  25. int retval;
  26. conf = general_enter_library(ud, 1, 0);
  27. if( conf == NULL )
  28. return exit_library( ud, 1 );
  29. board = interfaceBoard( conf );
  30. if( conf->is_interface )
  31. {
  32. retval = ioctl( board->fileno, IBLOC );
  33. if( retval < 0 )
  34. {
  35. fprintf( stderr, "IBLOC ioctl failed\n" );
  36. setIberr( EDVR );
  37. setIbcnt( errno );
  38. return exit_library( ud, 1 );
  39. }
  40. }else
  41. {
  42. retval = conf_lock_board(conf);
  43. if( retval < 0 )
  44. {
  45. return general_exit_library(ud, 1, 0, 0, 0, 0, 1);
  46. }
  47. i = send_setup_string( conf, cmd );
  48. if( i < 0 )
  49. {
  50. setIberr( EDVR );
  51. return exit_library( ud, 1 );
  52. }
  53. cmd[ i++ ] = GTL;
  54. count = my_ibcmd( conf, cmd, i);
  55. if(count != i)
  56. {
  57. return exit_library( ud, 1 );
  58. }
  59. }
  60. return exit_library( ud, 0 );
  61. }
  62. void EnableLocal( int boardID, const Addr4882_t addressList[] )
  63. {
  64. int i;
  65. ibConf_t *conf;
  66. ibBoard_t *board;
  67. uint8_t *cmd;
  68. int count;
  69. int retval;
  70. conf = enter_library( boardID );
  71. if( conf == NULL )
  72. {
  73. exit_library( boardID, 1 );
  74. return;
  75. }
  76. if( addressListIsValid( addressList ) == 0 )
  77. {
  78. exit_library( boardID, 1 );
  79. return;
  80. }
  81. if( conf->is_interface == 0 )
  82. {
  83. setIberr( EDVR );
  84. exit_library( boardID, 1 );
  85. return;
  86. }
  87. board = interfaceBoard( conf );
  88. if( is_cic( board ) == 0 )
  89. {
  90. setIberr( ECIC );
  91. exit_library( boardID, 1 );
  92. return;
  93. }
  94. if( numAddresses( addressList ) == 0 )
  95. {
  96. retval = remote_enable( board, 0 );
  97. if( retval < 0 ) exit_library( boardID, 1 );
  98. else exit_library( boardID, 0 );
  99. return;
  100. }
  101. cmd = malloc( 16 + 2 * numAddresses( addressList ) );
  102. if( cmd == NULL )
  103. {
  104. setIberr( EDVR );
  105. setIbcnt( ENOMEM );
  106. exit_library( boardID, 1 );
  107. return;
  108. }
  109. i = create_send_setup( board, addressList, cmd );
  110. cmd[ i++ ] = GTL;
  111. //XXX detect no listeners (EBUS) error
  112. count = my_ibcmd( conf, cmd, i );
  113. free( cmd );
  114. cmd = NULL;
  115. if(count != i)
  116. {
  117. exit_library( boardID, 1 );
  118. return;
  119. }
  120. exit_library( boardID, 0 );
  121. }