Ejemplo n.º 1
0
void fb_exit()
{
   bt_unmmap(btd, _sfi, SFI_SIZE);
   bt_close(btd);
   bt_unmmap(btd_lm, remote_ram_buffer, REMOTE_RAM_SIZE);
   bt_close(btd_lm);
}
Ejemplo n.º 2
0
static void
bt_play_close(struct voss_backend *pbe)
{
	struct bt_config *cfg = pbe->arg;

	switch (cfg->codec) {
	case CODEC_SBC:
		if (cfg->handle.sbc_enc == NULL)
			break;
		free(cfg->handle.sbc_enc);
		cfg->handle.sbc_enc = NULL;
		break;
#ifdef HAVE_FFMPEG
	case CODEC_AAC:
		if (cfg->handle.av.context == NULL)
			break;
		av_free(cfg->rem_in_data);
		av_frame_free(&cfg->handle.av.frame);
		avcodec_close(cfg->handle.av.context);
		avformat_free_context(cfg->handle.av.format);
		cfg->handle.av.context = NULL;
		break;
#endif
	default:
		break;
	}
	return (bt_close(pbe));
}
Ejemplo n.º 3
0
int main (int argc, const char * argv[]){
	// parse addr of Bob
	uint8_t ok = 0;
	if (argc >= 2) {
		ok = sscan_bd_addr((uint8_t *) argv[1], bob_addr);
	} 
	if (!ok) {
		printf("Usage: mitm 12:34:56:78:9A:BC\n");
		exit(0);
	}
	
	// start stack
	run_loop_init(RUN_LOOP_POSIX);
	int err = bt_open();
	if (err) {
		printf("Failed to open connection to BTdaemon\n");
		return err;
	}
	
	printf("BTstack-in-the-Middle started, will pretend to be BOB (");
	print_bd_addr(bob_addr);
	printf(")\n");
	
	bt_register_packet_handler(packet_handler);
	bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON );
	run_loop_execute();
	bt_close();
}
Ejemplo n.º 4
0
int main (int argc, const char * argv[]){
    // handle remote addr
    if (argc > 1){
        if (sscan_bd_addr((uint8_t *)argv[1], addr)){
            serverMode = 0;
            prepare_packet();
        }
    }

	run_loop_init(RUN_LOOP_POSIX);
	int err = bt_open();
	if (err) {
		printf("Failed to open connection to BTdaemon\n");
		return err;
	}
	bt_register_packet_handler(packet_handler);
	bt_send_cmd(&l2cap_register_service, PSM_TEST, PACKET_SIZE);
	bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON );
	
	// banner
	printf("L2CAP Throughput Test (compatible with Apple's Bluetooth Explorer)\n");
	if (serverMode) {
	   printf(" * Running in Server mode. For client mode, specify remote addr 11:22:33:44:55:66\n");
    }
    printf(" * MTU: 1000 bytes\n");
	
	run_loop_execute();
	bt_close();
	return 0;
}
Ejemplo n.º 5
0
/**************************************************************************//**
* \fn      CAENComm_ErrorCode STDCALL CAENComm_CloseDevice(int handle);
* \brief   Close the device
*
* \param   [IN]  handle: device handler
* \return  0 = Success; negative numbers are error codes
******************************************************************************/
CAENComm_ErrorCode STDCALL CAENComm_CloseDevice(int handle)
{
  CAENComm_ErrorCode returnValue = CAENComm_Success; // Optimistic initialization.
  try {
    // Get the handle:

    pNSCLHandle pHandle = getHandle(handle);
    
    // Unmap memory and close the device.
    // ignoring errors for now.

    bt_unmmap(*(pHandle->s_pSbsHandle),
	      pHandle->s_pMappedMemory,
	      gWindowSize);
    bt_close(*(pHandle->s_pSbsHandle));

    // Mark the handle as invalid:

    pHandle->s_fValid = false;
    delete pHandle->s_pSbsHandle;
  }
  catch(CAENComm_ErrorCode code) {
    returnValue = code;
  }
  return returnValue;
}
void deInitaccessory(Accessory* accessory)
{
	udev_monitor_unref(accessory->udev_monitor);
	udev_unref(accessory->udev_context);
	libusb_exit(accessory->usb_context);
	bt_close(accessory->bt_service);
	free(accessory);
}
Ejemplo n.º 7
0
/*****************************************************************************
 Close communications with GPS device.
 *****************************************************************************/
void coms_close(int fd, const cmdlnopts_t *cmdopt) {
  if (cmdopt->devs != NULL) {
    dev_close(fd);
    if (cmdopt->vflg)
      printf("Closed device %s\n", cmdopt->devs);
  } else {
    bt_close(fd);
    if (cmdopt->vflg)
      printf("Disconnected from %s\n", cmdopt->btas);
  }
}
Ejemplo n.º 8
0
int main (int argc, const char * argv[]){
	run_loop_init(RUN_LOOP_POSIX);
	int err = bt_open();
	if (err) {
		printf("Failed to open connection to BTdaemon\n");
		return err;
	}
	bt_register_packet_handler(packet_handler);
	bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON );
	run_loop_execute();
	bt_close();
}
Ejemplo n.º 9
0
static void ftk_app_bluetooth_destroy(FtkApp* thiz)
{
	if(thiz != NULL)
	{
		DECL_PRIV(thiz, priv);
		ftk_bitmap_unref(priv->icon);
		FTK_FREE(thiz);

		if (_bt) {
			bt_close(_bt);
			_bt = NULL;
		}
	}

	return;
}
Ejemplo n.º 10
0
int mvme_exit(MVME_INTERFACE *vme)
{
   int i;
   bt_error_t status;
   BT617_TABLE *ptab;

   for (i=0 ; i<MAX_BT617_TABLES ; i++) {
      ptab = ((BT617_TABLE *)vme->table)+i;
      if (ptab->btd != NULL) {
         status = bt_close(ptab->btd);
         if (status != BT_SUCCESS)
            bt_perror(ptab->btd, status, "bt_close error");
         }
      }

   return MVME_SUCCESS;
}
Ejemplo n.º 11
0
int main (int argc, const char * argv[]){
	// start stack
	run_loop_init(RUN_LOOP_POSIX);
	int err = bt_open();
	if (err) {
		printf("Failed to open connection to BTdaemon\n");
		return err;
	}
	// init table
	int i; for (i=0;i<MAX_DEVICES;i++) devices[i].state = 0;
	
	bt_register_packet_handler(packet_handler);
	bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON );
	run_loop_execute();
	bt_close();
	return 0;
}
Ejemplo n.º 12
0
int main (int argc, const char * argv[]){
	
    create_test_data();
    
	run_loop_init(RUN_LOOP_POSIX);
	int err = bt_open();
	if (err) {
		//fpritf(stderr,"Failed to open connection to BTdaemon, err %d\n",err);
		return 1;
	}
	bt_register_packet_handler(packet_handler);
	
	bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON );
	run_loop_execute();
	bt_close();
    return 0;
}
Ejemplo n.º 13
0
static void
bt_rec_close(struct voss_backend *pbe)
{
	struct bt_config *cfg = pbe->arg;

	switch (cfg->codec) {
	case CODEC_SBC:
		break;
#ifdef HAVE_FFMPEG
	case CODEC_AAC:
		break;
#endif

	default:
		break;
	}
	return (bt_close(pbe));
}
Ejemplo n.º 14
0
int vme_close()
{
    /* Check for status errors */
    status = bt_chkerr(btd);
    if ( BT_SUCCESS != status) {
        bt_perror(btd, status, "Engine ERROR: Status error from SBS VME-PCI");
    }

    /* Close SBS VME-PCI */
    status = bt_close(btd);
    if ( BT_SUCCESS != status) {
        bt_perror(btd, status, "Engine ERROR: Could not close SBS VME-PCI");
    }
	
	/* Remove the lock file (if it is not done already) */
	remove("/Applications/sirius/system/engine.lock");

   	return 0;
}
Ejemplo n.º 15
0
int main (int argc, const char * argv[]) {
    printf("le_scan started\n");
    printf("- connecting to BTstack Daemon\n");
    // start stack
    btstack_run_loop_init(btstack_run_loop_posix_get_instance());
    int err = bt_open();
    if (err) {
        printf("-> Failed to open connection to BTstack Daemon\n");
        return err;
    }

    printf("- connected\n");
    printf("- send power on\n");

    bt_register_packet_handler(packet_handler);
    bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON );
    btstack_run_loop_execute();
    bt_close();
    return 0;
}
Ejemplo n.º 16
0
int vme_open()
{
   /*  Open SBS VME-PCI  */
    status = bt_open(&btd, bt_gen_name(unit, type, &devname[0], BT_MAX_DEV_NAME), BT_RD | BT_WR);
    if (BT_SUCCESS != status) {
        bt_perror(btd, status, "Engine ERROR: Could not open SBS VME-PCI");
		remove("/Applications/sirius/system/engine.lock");
        return -1;
    }
	
    /* Clear any outstanding errors */
    status = bt_clrerr(btd);
    if (BT_SUCCESS != status) {
        bt_perror(btd, status, "Engine ERROR: Could not clear errors from SBS VME-PCI");
		remove("/Applications/sirius/system/engine.lock");
        (void) bt_close(btd);
        return -1;
    }
	return 0;
}
Ejemplo n.º 17
0
void portthread (void * port_ptr)
{
 SOCKET s;
 BT_PORT port_info ;

 port_info = *(BT_PORT*) port_ptr ;

 s = bt_listen (port_info.port);

 if (!s)
  _endthread();

 while (1)
 {
  socklen_t addrlen = sizeof(SOCKADDR_IN);
  SOCKADDR_IN addr ; 
  SOCKET client_sock;
  BT_CLIENT * client ;
  char reason, *ip;

  client_sock = accept (s, (SOCKADDR*) &addr, &addrlen);

  if (client_sock == -1)
   continue;

  ip = inet_ntoa (addr.sin_addr);

  if ((reason = allow(ip)) <= 0)
  {
   switch (reason)
   {
   case 0:
	logevent("Refused %s:%i (filter)", 
	 ip,port_info.port);
	break;
   case -1:
	logevent("Refused %s:%i (connection limit)", 
	 ip,port_info.port);
	break;
   case -2:
	logevent("Refused %s:%i (clone limit)", 
	 ip,port_info.port);
	break;
   }
   bt_close(client_sock);
   continue;
  }

  client = addconn(ip,port_info.port);
  client->sock = client_sock;
  client->use_pass = port_info.use_pass ;

  if (client->use_pass)
   bt_cpy (client->password, port_info.password);

  if (_beginthread (proxythread,0,client) == -1)
  {
   logevent ("Could not create proxy thread for %s:%i",
	client->ip,client->port);

   bt_close(client->sock);
   delconn(client);

   _endthread();
  }
 }

 _endthread();
}
Ejemplo n.º 18
0
static int
bt_play_open(struct voss_backend *pbe, const char *devname, int samplerate,
    int bufsize, int *pchannels, int *pformat)
{
	struct bt_config *cfg = pbe->arg;
	int retval;

	bt_init_cfg(cfg);

	retval = bt_open(pbe, devname, samplerate, bufsize, pchannels, pformat,
	    cfg, SDP_SERVICE_CLASS_AUDIO_SINK, 1);
	if (retval != 0)
		return (retval);

	/* setup codec */
	switch (cfg->codec) {
	case CODEC_SBC:
		cfg->handle.sbc_enc =
		    malloc(sizeof(*cfg->handle.sbc_enc));
		if (cfg->handle.sbc_enc == NULL)
			return (-1);
		memset(cfg->handle.sbc_enc, 0, sizeof(*cfg->handle.sbc_enc));
		break;
#ifdef HAVE_FFMPEG
	case CODEC_AAC:
		av_register_all();

		cfg->handle.av.codec = avcodec_find_encoder_by_name("aac");
		if (cfg->handle.av.codec == NULL) {
			DPRINTF("Codec AAC encoder not found\n");
			goto av_error_0;
		}
		cfg->handle.av.format = avformat_alloc_context();
		if (cfg->handle.av.format == NULL) {
			DPRINTF("Could not allocate format context\n");
			goto av_error_0;
		}
		cfg->handle.av.format->oformat =
		    av_guess_format("latm", NULL, NULL);
		if (cfg->handle.av.format->oformat == NULL) {
			DPRINTF("Could not guess output format\n");
			goto av_error_1;
		}
		cfg->handle.av.stream = avformat_new_stream(
		    cfg->handle.av.format, cfg->handle.av.codec);

		if (cfg->handle.av.stream == NULL) {
			DPRINTF("Could not create new stream\n");
			goto av_error_1;
		}
		cfg->handle.av.context = cfg->handle.av.stream->codec;
		if (cfg->handle.av.context == NULL) {
			DPRINTF("Could not allocate audio context\n");
			goto av_error_1;
		}
		avcodec_get_context_defaults3(cfg->handle.av.context,
		    cfg->handle.av.codec);

		cfg->handle.av.context->bit_rate = 128000;
		cfg->handle.av.context->sample_fmt = AV_SAMPLE_FMT_FLTP;
		cfg->handle.av.context->sample_rate = samplerate;
		switch (*pchannels) {
		case 1:
			cfg->handle.av.context->channel_layout = AV_CH_LAYOUT_MONO;
			cfg->handle.av.context->channels = 1;
			break;
		default:
			cfg->handle.av.context->channel_layout = AV_CH_LAYOUT_STEREO;
			cfg->handle.av.context->channels = 2;
			break;
		}

		cfg->handle.av.context->profile = FF_PROFILE_AAC_LOW;
		if (1) {
			AVDictionary *opts = NULL;

			av_dict_set(&opts, "strict", "-2", 0);
			av_dict_set_int(&opts, "latm", 1, 0);

			if (avcodec_open2(cfg->handle.av.context,
			    cfg->handle.av.codec, &opts) < 0) {
				av_dict_free(&opts);

				DPRINTF("Could not open codec\n");
				goto av_error_1;
			}
			av_dict_free(&opts);
		}
		cfg->handle.av.frame = av_frame_alloc();
		if (cfg->handle.av.frame == NULL) {
			DPRINTF("Could not allocate audio frame\n");
			goto av_error_2;
		}
		cfg->handle.av.frame->nb_samples = cfg->handle.av.context->frame_size;
		cfg->handle.av.frame->format = cfg->handle.av.context->sample_fmt;
		cfg->handle.av.frame->channel_layout = cfg->handle.av.context->channel_layout;
		cfg->rem_in_size = av_samples_get_buffer_size(NULL,
		    cfg->handle.av.context->channels,
		    cfg->handle.av.context->frame_size,
		    cfg->handle.av.context->sample_fmt, 0);

		cfg->rem_in_data = av_malloc(cfg->rem_in_size);
		if (cfg->rem_in_data == NULL) {
			DPRINTF("Could not allocate %u bytes sample buffer\n",
			    (unsigned)cfg->rem_in_size);
			goto av_error_3;
		}
		retval = avcodec_fill_audio_frame(cfg->handle.av.frame,
		    cfg->handle.av.context->channels,
		    cfg->handle.av.context->sample_fmt,
		    cfg->rem_in_data, cfg->rem_in_size, 0);
		if (retval < 0) {
			DPRINTF("Could not setup audio frame\n");
			goto av_error_4;
		}
		break;
av_error_4:
		av_free(cfg->rem_in_data);
av_error_3:
		av_frame_free(&cfg->handle.av.frame);
av_error_2:
		avcodec_close(cfg->handle.av.context);
av_error_1:
		avformat_free_context(cfg->handle.av.format);
		cfg->handle.av.context = NULL;
av_error_0:
		bt_close(pbe);
		return (-1);
#endif
	default:
		bt_close(pbe);
		return (-1);
	}
	return (0);
}
main(int argc, char **argv)
{
    char inbuf[BUFLEN], *s;
    Btree *bt = NULL;
    FILE *logfile = NULL;

    for (;;) {
        fflush(stdout);
        fputs("Action (? for help): ", stdout);
        fflush(stdout);
        fgets(inbuf, BUFLEN, stdin);
        s = inbuf + strlen(inbuf);
        while(iscntrl(*s))
            *s-- = 0;

        if (logfile)
            fprintf(logfile, "%s\n", inbuf);

        if (!bt && strchr("@adfkKmMsSwW", inbuf[0])) {
            fputs(" **no open dataset\n", stdout);
            continue;
        }


        switch (inbuf[0]) {
            case '?':
                fputs(
        "@file      - load strings in file into tree\n"
        "a string   - add name;addr to tree\n"
        "d string   - delete name;addr from tree\n"
        "dup [0|1]  - disallow/allow duplicates\n"
        "f string   - find name;addr in tree\n"
        "k/K [file] - display key counts (K = overwrite file)\n"
        "l file     - log actions to file\n"
        "l          - turn off action logging\n"
        "m/M [file] - display block usage map\n"
        "n file     - make a new dataset\n"
        "o file     - open an existing dataset\n"
        "s/S [file] - display tree (S = overwrite file)\n"
        "w/W [file] - walk tree, (W = overwrite file)\n"
        "q          - quit\n"
        , stdout);
                fflush(stdout);
                break;

            case '@':
                LoadFile(bt, inbuf + 1);
                break;

            case 'a':
                if (inbuf[1] != ' ' ||
                    !inbuf[2]       ||
                    !strchr(inbuf,';'))
                    fputs(" Not a valid command\n", stdout);
                else
                    if (DoData(bt, inbuf + 2, 1) == TREE_FAIL)
                        fputs(" ** Insertion failed\n", stdout);
                break;

            case 'd':
                if (inbuf[1] == 'u' && inbuf[2] == 'p') {
                    if (inbuf[3] == ' ' &&
                        (inbuf[4] == '0' || inbuf[4] == '1'))
                        bt -> duplicatesOK =
                        inbuf[4] == '0' ? 0 : 1;
                    fputs("duplicates are ", stdout);
                    if (bt -> duplicatesOK == 0)
                        fputs("not ", stdout);
                    fputs("allowed.\n", stdout);
                    break;
                }

                if (inbuf[1] != ' ' || inbuf[2] == 0)
                    fputs(" Not a valid command\n", stdout);


                else {
                    if (DoData(bt, inbuf + 2, 0) == TREE_FAIL)
                        fputs(" ** Delete failed\n", stdout);
                }
                break;

            case 'f':
                if (inbuf[1] != ' ' || inbuf[2] == 0)
                    fputs(" Not a valid command\n", stdout);
                else {
                    UR record;
                    inbuf[12] = '\0';
                    if (bt_find(bt, &record, inbuf+2) ==
                                                    TREE_FAIL)
                        fputs(" ** Find failed\n", stdout);
                    else
                        fprintf(stdout, "found %s;%s\n",
                                record.name, record.addr);
                }
                break;

            case 'k': case 'K': {
                    FILE *out;

                    if (inbuf[1] == ' ' && inbuf[2] != 0) {
                        out = fopen(inbuf+2,
                                    inbuf[0] == 'k' ? "w" : "a");
                        if (!out)
                            printf("Can't open %s\n", inbuf + 2);
                        else {
                            show_btree(bt, out, 0);
                            fclose(out);
                        }
                    }
                    else
                        show_btree(bt, stdout, 0);
                }
                break;

            case 'l':
                if (inbuf[1] != ' ' || inbuf[2] == 0) {
                    if (logfile) {
                        fclose(logfile);
                        logfile = NULL;
                    }
                    else
                        fputs(" Logfile not open\n", stdout);
                }
                else {
                    logfile = fopen(inbuf + 2, "w");
                    if (logfile == NULL)
                        printf("Can't open %s\n", inbuf + 2);
                }
                break;

            case 'm': case 'M': {
                    FILE *out;

                    if (inbuf[1] == ' ' && inbuf[2] != 0) {
                        out = fopen(inbuf+2, inbuf[0] ==
                                                'm' ? "w" : "a");
                        if (!out)
                            printf("Can't open %s\n", inbuf + 2);
                        else {
                            show_btree_map(bt, out);
                            fclose(out);
                        }
                    }
                    else
                        show_btree_map(bt, stdout);
                }
                break;

            case 'n':
                if (inbuf[1] != ' ' || inbuf[2] == 0)
                    fputs(" Not a valid command\n", stdout);
                else
                    make_dataset(inbuf+2);
                break;

            case 'o':
				if (inbuf[1] != ' ' || inbuf[2] == 0)
                    fputs(" Not a valid command\n", stdout);
                else {
                    if (bt) {
                        if (bt_close(bt))
                            printf("\nClose failed: %s\n",
                                    ErrorText[bt->error_code]);
                        else
                            printf("\nData files closed.\n");

                        bt = NULL;
                    }
					bt = open_dataset(inbuf+2);
                }
                break;

            case 'q':
                if (logfile)
                    fclose(logfile);

                if (bt) {
                    if (bt_close(bt))
                        printf("\nClose failed: %s\n",
                                ErrorText[bt->error_code]);
                    else
                        printf("\nData files closed.\n");
                }
                return;

            case 's': case 'S': {
                    FILE *out;

                    if (inbuf[1] == ' ' && inbuf[2] != 0) {
                        out = fopen(inbuf+2, inbuf[0] ==
                                             's' ? "w" : "a");
                        if (!out)
                            printf("Can't open %s\n", inbuf + 2);
                        else {
                            show_btree(bt, out, 1);
                            fclose(out);
                        }
                    }
                    else
                        show_btree(bt, stdout, 1);
                }
                break;

            case 'w': case 'W': {
                    if (inbuf[1] == ' ' && inbuf[2] != 0) {
                        outfile = fopen(inbuf+2, inbuf[0] ==
                                             'w' ? "w" : "a");
                        if (!outfile)
                            printf("Can't open %s\n", inbuf + 2);
                        else {
                            DataCount = 0;
                            bt_walk(bt, DisplayFunc);
                            fprintf(outfile, "%d items\n",
                                    DataCount);
                            fclose(outfile);
                            outfile = NULL;
                        }
                    }
                    else {
                        DataCount = 0;
                        outfile = stdout;
                        bt_walk(bt, DisplayFunc);
                        fprintf(outfile, "%d items\n",
                                    DataCount);
                        outfile = NULL;
                    }
                }
                break;

            case ';':
                break;  /* comment */

            default:
                fputs(" Not a valid command\n", stdout);
                break;
        }
        if (bt && bt->error_code) {
            printf("ERROR: %s\n", ErrorText[bt->error_code]);
            bt->error_code = 0;
        }
    }
}
Ejemplo n.º 20
0
int fb_init()
{
   bt_error_t status;           /* Bit 3 library error return type */
   char devname[BT_MAX_DEV_NAME];       /* Device to open */
   bt_devdata_t flag;

   /* Open the device in A24 space */
   bt_gen_name(0, BT_DEV_A24, devname, BT_MAX_DEV_NAME);
   status = bt_open(&btd, devname, BT_RDWR);
   if (status != BT_SUCCESS) {
      cm_msg(MERROR, "fb_init", "Cannot open Bit3 device driver");
      return FALSE;
   }
   bt_init(btd);
   bt_clrerr(btd);

   /* map SFI memory */
   status = bt_mmap(btd, &_sfi, SFI_ADDRESS, SFI_SIZE, BT_RDWR, BT_SWAP_DEFAULT);
   if (status != BT_SUCCESS) {
      cm_msg(MERROR, "fb_init", "Cannot map VME memory");
      bt_close(btd);
      return FALSE;
   }

   /* Open the device in local memory */
   bt_gen_name(0, BT_DEV_LM, devname, BT_MAX_DEV_NAME);
   status = bt_open(&btd_lm, devname, BT_RDWR);
   if (status != BT_SUCCESS) {
      cm_msg(MERROR, "fb_init", "Cannot open Bit3 device for local memory");
      return FALSE;
   }
   bt_clrerr(btd_lm);

   /* map local memory */
   status =
       bt_mmap(btd_lm, &remote_ram_buffer, 0, REMOTE_RAM_SIZE, BT_RDWR, BT_SWAP_DEFAULT);
   if (status != BT_SUCCESS) {
      cm_msg(MERROR, "fb_init", "Cannot map local memory");
      bt_close(btd);
      return FALSE;
   }

   /* clear local memory */
   memset(remote_ram_buffer, 0, REMOTE_RAM_SIZE);

   /* force D32 mode */
   bt_get_info(btd, BT_INFO_MMAP_AMOD, &flag);
   flag = BT_AMOD_A24_SD;
   bt_set_info(btd, BT_INFO_MMAP_AMOD, flag);

   /* sequencer reset */
   SFI_OUT(SFI_SEQUENCER_RESET, 0);

   /* arbitration level */
//  SFI_OUT(SFI_FASTBUS_ARBITRATION_LEVEL_REGISTER, 0x15);
   SFI_OUT(SFI_FASTBUS_ARBITRATION_LEVEL_REGISTER, 0xBF);

   /* timeout */
   SFI_OUT(SFI_FASTBUS_TIMEOUT_REGISTER, 0x73);

   /* sequencer enable */
   SFI_OUT(SFI_SEQUENCER_ENABLE, 0);

   /* switch off all output */
   SFI_OUT(SFI_CLEAR_BOTH_LCA1_TEST_REGISTER, 0);

   /* clear registers */
   SFI_OUT(SFI_RESET_REGISTER_GROUP_LCA2, 0);

   return SUCCESS;
}
Ejemplo n.º 21
0
void proxythread (void * client_ptr)
{
 BT_CLIENT *client;
 BT_PROXY proxy = { 0 };
 BT_CLIENTINFO ci = { 0 };

 char buf[4096] = { 0 };

 int c = 0;

 // set up client information

 client = (BT_CLIENT*) client_ptr;

 // welcome user

 if (!client->use_pass) // anon server
 {
  logevent("Accepted %s:%i", client->ip, client->port);

  ci.pass_reg = 1;

  bt_send (client->sock,
   ":BounceThis NOTICE :You have connected to a BounceThis server. (version " BT_VERSION_NUMBER ")\r\n"
   ":BounceThis NOTICE :Please type \002/BOUNCE <server> [port] [password]\002 to connect to a server.\r\n"
   ":BounceThis NOTICE :For a list of commands, type \002/COMMANDS\002.\r\n");
 }

 /* parsing engine */


 while (1)
 {
  char *ptr, *bufptr, *msgptr ;
  char msgbuf[512] = { 0 };

  c = bt_recv (client->sock, buf, 4096);

  if (c == SOCKET_ERROR)
   goto abort ;

  buf[c] = 0;

  bufptr = buf;

  do
  {
   msgptr = msgbuf;

   // get first message (terminated with \r\n)

   while (*bufptr != '\n' && *bufptr != '\0')
   {
	if (*bufptr == 0) goto abort;
	*msgptr++ = *bufptr++;
   }

   *bufptr++;
   *msgptr = 0;

   ptr = strtok (msgbuf," ");

   if (!ptr)
	continue;

   if (!strcmpi (ptr,"PASS"))
   {
	if (ci.pass_reg)
	{
	 bt_send(client->sock, 
	  ":BounceThis NOTICE :Password not needed.\r\n");
	 continue;
	}
	else
	{
	 ptr = strtok(NULL," \r");

	 if (!ptr)
	  continue;

	 if (!strcmp (ptr, client->password))
	 {
	  logevent("Accepted %s:%i", client->ip, client->port);

	  ci.pass_reg = 1;

	  bt_send(client->sock,
	   ":BounceThis NOTICE :Password accepted.\r\n"
	   ":BounceThis NOTICE :You have connected to a BounceThis server. (version " BT_VERSION_NUMBER ")\r\n"
	   ":BounceThis NOTICE :Please type \002/BOUNCE <server> [port] [password]\002 to connect to a server.\r\n"
	   ":BounceThis NOTICE :For a list of commands, type \002/COMMANDS\002.\r\n");

	  continue;
	 }
	 else
	 {
	  logevent("Refused %s (incorrect password)", client->ip);
	  bt_send (client->sock, 
	   ":BounceThis NOTICE :Password incorrect.\r\n");
	  goto abort2;
	 }
	}
   }

   if (ci.pass_reg)
   {
	if (!strcmpi (ptr,"COMMANDS"))
	{
	 bt_send (client->sock,
	 ":BounceThis NOTICE :Commands listing:\r\n"
	 ":BounceThis NOTICE :\002/ABOUT\002 About BounceThis.\r\n"
	 ":BounceThis NOTICE :\002/ADMIN\002 Login as the admin.\r\n"
	 ":BounceThis NOTICE :\002/BOUNCE\002 Connects you to a server.\r\n"
	 ":BounceThis NOTICE :\002/COMMANDS\002 Shows this screen.\r\n"
	 ":BounceThis NOTICE :\002/INFO\002 Info about yourself and the server.\r\n"
	 ":BounceThis NOTICE :\002/NICK\002 Changes your nickname.\r\n"
	 ":BounceThis NOTICE :\002/QUIT\002 Disconnects you.\r\n");

	 if (ci.is_admin)
	  bt_send (client->sock,
	  ":BounceThis NOTICE :Admin commands listing:\r\n"
	 ":BounceThis NOTICE :\002/BROADCAST\002 Send a message to all users.\r\n"
	 ":BounceThis NOTICE :\002/KILL\002 Kill everyone matching an ip (BT style filters allowed)\r\n"
	 ":BounceThis NOTICE :\002/TEMPFILTER\002 Ban everyone matching an ip (BT style filters allowed) until server is stopped.\r\n"
	 ":BounceThis NOTICE :\002/LISTCONN\002 Lists all connections to the server.\r\n");

	}

	else if (!strcmpi (ptr,"ABOUT"))
	 bt_send(client->sock,
	 ":BounceThis NOTICE :About BounceThis:\r\n"
	 ":BounceThis NOTICE :BounceThis was created by Chris M. in 2002.\r\n"
	 ":BounceThis NOTICE :It is a full featured Win32 BNC server designed for IRC.\r\n"
	 ":BounceThis NOTICE :Check us out on the web at 12http://bouncethis.linear.cc\r\n");

	else if (!strcmpi (ptr,"INFO"))
	{ 
	 bt_sendf (client->sock,
	  ":BounceThis NOTICE :" BT_VERSION ", bound on IP %s on port %i\r\n"
	  ":BounceThis NOTICE :You are connecting as %s!%s@%s (%s)\r\n",
	  server.ip, client->port, real(ci.nick), ci.user, client->ip, real(ci.name));

	 if (server.use_identd)
	  bt_sendf (client->sock,
	  ":BounceThis NOTICE :Identd server enabled, using ident '%s'\r\n",
	  server.ident);
	}

	else if (!strcmpi (ptr,"NICK"))
	{
	 ptr = strtok(NULL," \r");

	 if (!ptr)
	  continue;

	 bt_cpy (ci.nick, ptr);

	 if (ci.nick_reg)
	  bt_sendf (client->sock, 
	  ":BounceThis NOTICE :Your nickname is now \002%s\002.\r\n",
	  real(ci.nick));
	 else
	  ci.nick_reg = 1;
	}
	else if (!strcmpi (ptr,"QUIT"))
	 goto abort; 
	else if (!strcmpi (ptr,"USER"))
	{
	 if (ci.user_reg)
	 {
	  bt_send (client->sock, 
	   ":BounceThis NOTICE :You cannot reregister.\r\n");
	  continue;
	 }

	 ptr = strtok(NULL," ");

	 if (!ptr)
	  continue;

	 bt_cpy (ci.user, ptr);

	 // skip next two fields. useless -_-;
	 strtok(NULL," ");
	 strtok(NULL," ");

	 ptr = strtok(NULL,"\r");

	 if (!ptr)
	  continue;

	 bt_cpy (ci.name, ptr);
	 ci.user_reg = 1;
	}
	else if (!strcmpi (ptr,"ADMIN"))
	{ 
	 char user[16] ; 
	 char pass[16] ;

	 ptr = strtok(NULL," \r");

	 if (!ptr)
	  continue;

	 bt_cpy(user,ptr) ;

	 ptr = strtok(NULL," \r");

	 if (!ptr)
	  continue;

	 bt_cpy(pass,ptr) ;

	 if (!strcmpi(user,server.admin_user) && !strcmp(pass,server.admin_pass))
	 {
	  bt_send(client->sock,":BounceThis NOTICE :Admin password accepted.\r\n");
	  ci.is_admin = 1 ;
	 }
	 else
	 {
	  logevent("Connection from %s:%i closed (invalid admin attempt)", client->ip,client->port);
	  bt_send (client->sock,
	   ":BounceThis NOTICE :Admin password incorrect. Disconnecting.\r\n");
	  goto abort2;
	 }
	}
	else if (!strcmpi (ptr,"BROADCAST"))
	{
	 if (!ci.is_admin) // :O!
	 {
	  bt_send(client->sock,":BounceThis NOTICE :You cannot perform this command.\r\n");
	  continue ;
	 }

	 ptr = strtok(NULL,"\r");

	 if (!ptr)
	  continue;

	 broadcast(ptr) ;
	}
	else if (!strcmpi (ptr,"KILL"))
	{
	 if (!ci.is_admin) // :O!
	 {
	  bt_send(client->sock,":BounceThis NOTICE :You cannot perform this command.\r\n");
	  continue ;
	 }

	 ptr = strtok(NULL,"\r");

	 if (!ptr)
	  continue;

	 bt_sendf(client->sock,":BounceThis NOTICE :Kill effected \002%i\002 users.\r\n",kill(ptr)) ;
	}
	else if (!strcmpi (ptr,"TEMPFILTER"))
	{
	 if (!ci.is_admin) // :O!
	 {
	  bt_send(client->sock,":BounceThis NOTICE :You cannot perform this command.\r\n");
	  continue ;
	 }

	 ptr = strtok(NULL,"\r");

	 if (!ptr)
	  continue;

	 bt_sendf(client->sock,":BounceThis NOTICE :Filter effected \002%i\002 users.\r\n",tempfilter(ptr)) ;
	}
	else if (!strcmpi (ptr,"LISTCONN"))
	{
	 if (!ci.is_admin) // :O!
	 {
	  bt_send(client->sock,":BounceThis NOTICE :You cannot perform this command.\r\n");
	  continue ;
	 }

	 list(client->sock);
	}
	else if (!strcmpi (ptr,"BOUNCE"))
	{
	 ptr = strtok(NULL," \r");

	 if (!ptr)
	  continue;

	 bt_cpy (proxy.host, ptr);

	 ptr = strtok(NULL," \r");

	 if (!ptr)
	  bt_cpy(proxy.port,"6667");
	 else
	 {
	  bt_cpy (proxy.port, ptr);
	  ptr = strtok(NULL," \r");

	  if (ptr)
	  {
	   bt_cpy (ci.pass,ptr);
	   ci.use_pass = 1;
	  }
	 }

	 proxy.sock = bt_connect (proxy.host, proxy.port);

	 if (!proxy.sock)
	  bt_sendf (client->sock,
	  ":BounceThis NOTICE :Error connecting to %s:%s.\r\n",
	  proxy.host,	proxy.port);
	 else
	 {
	  bt_sendf (client->sock,
	   ":BounceThis NOTICE :Connection established to %s:%s.\r\n",proxy.host,
	   proxy.port);

	  if (ci.use_pass)
	   bt_sendf (client->sock,":BounceThis NOTICE :Attempting to login with password '%s'\r\n",
	   ci.pass);
	  break;
	 }
	}
	else
	 bt_sendf (client->sock,
	 ":BounceThis NOTICE :\002/%s\002: Invalid command.\r\n",ptr);
   }
   else
   {
	logevent("Refused %s:%i (incorrect password)", client->ip,client->port);
	bt_send (client->sock,
	 ":BounceThis NOTICE :You must supply the password before performing any other commands.\r\n");
	goto abort2;
   }

  } while ((char)*bufptr != (char)0) ;

  if (proxy.sock) /* proxy connected, break from BT IRC interface */
   break;
 }

 logevent("Proxy connection to %s:%s from %s:%i", proxy.host,proxy.port,
  client->ip, client->port);

 // Register user.
 if (ci.use_pass)
  bt_sendf(proxy.sock,"PASS %s\r\n", ci.pass);

 bt_sendf(proxy.sock,"NICK %s\r\nUSER %s # # %s\r\n",ci.nick,ci.user,ci.name);

 while (1)
 {
  fd_set rset = { 0 };

  FD_SET (client->sock, &rset);
  FD_SET (proxy.sock, &rset);

  if (select (0, &rset, NULL, NULL, NULL) == -1)
   goto abort;

  if (FD_ISSET (client->sock, &rset))
  {
   c = bt_recv(client->sock, buf, 4096);

   if (c <= 0)
	goto abort;

   buf[c] = 0;

   client->sent += bt_send (proxy.sock, buf);
  }

  if (FD_ISSET (proxy.sock, &rset))
  {
   c = bt_recv (proxy.sock, buf, 4096);

   if (c <= 0)
	goto abort;

   buf[c] = 0;

   client->recv += bt_send (client->sock, buf);
  }

  updatesrtowin(client);
 }

abort:
 logevent("Connection from %s:%i closed", client->ip,client->port);
abort2: // for skipping auto log.
 bt_close(client->sock);

 if (proxy.sock)
 {
  bt_close(proxy.sock);
 }

 delconn(client);

 _endthread();
}