Пример #1
0
static void testKludge( const char *argPtr )
	{
#if 0
	testReadCorruptedKey();
#endif /* 0 */

	/* To test dodgy certificate collections */
#if 0
	int result;

	if( argPtr == NULL )
		{
		printf( "Error: Missing argument.\n" );
		exit( EXIT_FAILURE );
		}
	if( *argPtr == '@' )
		{
		cryptSetAttribute( CRYPT_UNUSED, CRYPT_OPTION_CERT_COMPLIANCELEVEL,
						   CRYPT_COMPLIANCELEVEL_OBLIVIOUS );
		argPtr++;
		}
	if( *argPtr == '#' )
		{
		cryptSetAttribute( CRYPT_UNUSED, CRYPT_OPTION_CERT_COMPLIANCELEVEL,
						   CRYPT_COMPLIANCELEVEL_PKIX_FULL );
		argPtr++;
		}
	result = xxxCertImport( argPtr );
	cryptEnd();
	exit( result ? EXIT_SUCCESS : EXIT_FAILURE );
#endif /* 1 */

	/* Performance-testing test harness */
#if 0
	void performanceTests( const CRYPT_DEVICE cryptDevice );

	performanceTests( CRYPT_UNUSED );
#endif /* 0 */

	/* Memory diagnostic test harness */
#if 0
	testReadFileCertPrivkey();
	testEnvelopePKCCrypt();		/* Use "Datasize, certificate" */
	testEnvelopeSign();			/* Use "Datasize, certificate" */
#endif /* 0 */

	/* Simple (brute-force) server code. NB: Remember to change
	   setLocalConnect() to not bind the server to localhost if expecting
	   external connections */
#if 0
	while( TRUE )
		testSessionTSPServer();
#endif /* 0 */

	/* Exit point for the test harnesses above, used when we don't want to 
	   fall through to the main test code */
#if 0
	cleanupAndExit( EXIT_SUCCESS );
#endif /* 0 */
	}
Пример #2
0
static gchar* parseParentClassIdent(void)
{
    g_message("Line %d: Error in class declaration",  g_scanner_cur_line(gScanner));
    cleanupAndExit(0);

    return NULL;
}
Пример #3
0
/*
  Function to parse the body of a class.
  Current token is '{'.

  CBODY:= '}'   //This is an empty class body
         | CLASSMETHODS '}'

 */
static void parseCBody(void)
{
    PPARSEINFO pParseInfo=(PPARSEINFO)gScanner->user_data;

    while(g_scanner_peek_next_token(gScanner)!= G_TOKEN_EOF && g_scanner_peek_next_token(gScanner)!='}')
    {
        PSYMBOL pCurSymbol;
        GTokenValue value;

        /* Method implementations must start with "public" which is registered as a symbol. Here we check if
         the token is a symbol. */
        exitIfNotMatchNext(G_TOKEN_SYMBOL, "Method implementation must start with 'public'.");

        value=gScanner->value;
        pCurSymbol=value.v_symbol;

        /* Check if token is "public". */
        if(!pCurSymbol || pCurSymbol->uiSymbolToken!=NOMC_SYMBOL_PUBLIC)
        {
            g_scanner_unexp_token(gScanner,
                                  G_TOKEN_SYMBOL,
                                  NULL, NULL, NULL,
                                  "'impl'.",
                                  TRUE); /* is_error */
            cleanupAndExit(1);
        }

        /* Get name, parameters and stuff. Print the body. */
        parseClassMethod();
    };

    exitIfNotMatchNext('}',  "No closing of 'class' section.");
}
Пример #4
0
static void doClassDeclaration(void)
{
    PPARSEINFO pParseInfo=(PPARSEINFO)gScanner->user_data;

    PINTERFACE pif;
    gchar *chrTemp=pParseInfo->pCurInterface->chrName;

    /* Check if we already have a (maybe forward) declaration */
    pif=findInterfaceFromName(pParseInfo->pCurInterface->chrName);
    if(pif)
    {
        if(pif->fIsForwardDeclaration)
        {
            /* Remove the forward declaration and insert the real thing afterwards. */
            deRegisterInterface(pif);
        }
        else
        {
            /* It˚s the declaration from the *.h file. Save a pointer to this information. */
            pParseInfo->pClassDefinition=pif;
            deRegisterInterface(pif);
        }
    }

    pParseInfo->pCurInterface->chrName=chrTemp;
    pParseInfo->pCurInterface->chrSourceFileName=g_strdup(pParseInfo->chrCurrentSourceFile);

    /* It's save to register the interface right here even if the struct is almost empty.
     If anything goes wrong later we will exit anyway. */
    registerInterface();

    /* The class definition in *.nom files does not contain all the stuff an interface may define. We use the found
     interface to fill the gaps. If we don˚t have an interface something went wrong and we quit. */
    if(!pParseInfo->pClassDefinition)
    {
        g_message("Line %d: Error during class parsing. No class definition found. MAke sure you included the *.ih file.",  g_scanner_cur_line(gScanner));
        cleanupAndExit(0);
    }

    pParseInfo->pCurInterface->chrParent=g_strdup(pParseInfo->pClassDefinition->chrParent);

    /* Note: We don˚t support subclasses yet. */
    if(matchNext(':'))
    {
        parseParentClassIdent();
    }
    parseClassBody();
}
Пример #5
0
/*
 Parse the class name. If we already encountered this class the name is registered as a
 symbol. IF this is the first time the name is an identifier.

 Note that the current token is the 'class' keyword.

 CLASSIDENT:=  G_TOKEN_IDENTIFIER
             | IDL_SYMBOL_INTERFACE
 */
static gchar* parseClassIdent(void)
{
    PPARSEINFO pParseInfo=(PPARSEINFO)gScanner->user_data;

    if(matchNext(G_TOKEN_IDENTIFIER))
    {
        /* Save interface info */
        GTokenValue value=gScanner->value;

        return g_strdup(value.v_identifier);
    }
    else
    {
        PSYMBOL pCurSymbol;
        GTokenValue value;

        /* If the interface name is a symbol, it means the interface was
         already registered before. Maybe because of a forward statement.
         We will check that in the function which called us. */
        exitIfNotMatchNext(G_TOKEN_SYMBOL, "Keyword 'class' must be followed by an identifier");

        /* Check if it's one of our interface symbols */
        value=gScanner->value;
        pCurSymbol=value.v_symbol;
        if(IDL_SYMBOL_REGINTERFACE!=pCurSymbol->uiSymbolToken)
        {
            /* No, some other symbol */
            g_scanner_unexp_token(gScanner,
                                  G_TOKEN_SYMBOL,
                                  NULL, NULL, NULL,
                                  "Keyword 'class' is not followed by a valid identifier.",
                                  TRUE); /* is_error */
            cleanupAndExit(1);
        }

        /* Save interface name */
        return g_strdup(pCurSymbol->chrSymbolName);
    }
}
Пример #6
0
static void testKludge( const char *argPtr )
	{
#if 0
	testSessionTLS11Server();
	testSessionTLS11Server();
	testSessionTLS11Server();
#else
//	testSessionTLS11ClientServer();
#endif
//	fuzzSession( CRYPT_SESSION_SSL );
//	testBasicCert();
#if 0
//	--> PKCS #15 read private key + cert
//	--> PKCS #12 write the same
#endif

	/* Performance-testing test harness */
#if 0
	void performanceTests( const CRYPT_DEVICE cryptDevice );

	performanceTests( CRYPT_UNUSED );
#endif /* 0 */

	/* Simple (brute-force) server code. NB: Remember to change
	   setLocalConnect() to not bind the server to localhost if expecting
	   external connections */
#if 0
	while( TRUE )
		testSessionTSPServer();
#endif /* 0 */

	/* Exit point for the test harnesses above, used when we don't want to 
	   fall through to the main test code */
#if 0
	cleanupAndExit( EXIT_SUCCESS );
#endif /* 0 */
	}
Пример #7
0
/* #define SERVER_DEBUG 1   */
int
main(int argc, char *argv[])
{
    int status;
    rsComm_t rsComm;
    char *tmpStr;

    ProcessType = AGENT_PT;

#ifdef RUN_SERVER_AS_ROOT
#ifndef windows_platform
    if (initServiceUser() < 0) {
        exit (1);
    }
#endif
#endif

#ifdef windows_platform
	iRODSNtAgentInit(argc, argv);
#endif

#ifndef windows_platform
    signal(SIGINT, signalExit);
    signal(SIGHUP, signalExit);
    signal(SIGTERM, signalExit);
    /* set to SIG_DFL as recommended by andy.salnikov so that system()
     * call returns real values instead of 1 */
    signal(SIGCHLD, SIG_DFL);
    signal(SIGUSR1, signalExit);
    signal(SIGPIPE, rsPipSigalHandler);
#endif

#ifndef windows_platform
#ifdef SERVER_DEBUG
    if (isPath ("/tmp/rodsdebug"))
        sleep (20);
#endif
#endif

#ifdef SYS_TIMING
    rodsLogLevel(LOG_NOTICE);
    printSysTiming ("irodsAgent", "exec", 1);
#endif

    memset (&rsComm, 0, sizeof (rsComm));

    status = initRsCommWithStartupPack (&rsComm, NULL);

    if (status < 0) {
	sendVersion (rsComm.sock, status, 0, NULL, 0);
        cleanupAndExit (status);
    }

    /* Handle option to log sql commands */
    tmpStr = getenv (SP_LOG_SQL);
    if (tmpStr != NULL) {
#ifdef IRODS_SYSLOG
       int j = atoi(tmpStr);
       rodsLogSqlReq(j);
#else
       rodsLogSqlReq(1);
#endif
    }

    /* Set the logging level */
    tmpStr = getenv (SP_LOG_LEVEL);
    if (tmpStr != NULL) {
       int i;
       i = atoi(tmpStr);
       rodsLogLevel(i);
    } else {
       rodsLogLevel(LOG_NOTICE); /* default */
    }

#ifdef IRODS_SYSLOG
/* Open a connection to syslog */
#ifdef SYSLOG_FACILITY_CODE
    openlog("rodsAgent",LOG_ODELAY|LOG_PID,SYSLOG_FACILITY_CODE);
#else
    openlog("rodsAgent",LOG_ODELAY|LOG_PID,LOG_DAEMON);
#endif
#endif

    status = getRodsEnv (&rsComm.myEnv);

    if (status < 0) {
	sendVersion (rsComm.sock, SYS_AGENT_INIT_ERR, 0, NULL, 0);
        cleanupAndExit (status);
    }

#if RODS_CAT
    if (strstr(rsComm.myEnv.rodsDebug, "CAT") != NULL) {
       chlDebug(rsComm.myEnv.rodsDebug);
    }
#endif

#ifdef RULE_ENGINE_N
    status = initAgent (RULE_ENGINE_TRY_CACHE, &rsComm);
#else
    status = initAgent (&rsComm);
#endif
#ifdef SYS_TIMING
    printSysTiming ("irodsAgent", "initAgent", 0);
#endif

    if (status < 0) {
	sendVersion (rsComm.sock, SYS_AGENT_INIT_ERR, 0, NULL, 0);
        cleanupAndExit (status);
    }

    /* move configConnectControl behind initAgent for now. need zoneName if
     * the user does not specify one in the input */
    initConnectControl ();

    if (rsComm.clientUser.userName[0] != '\0') {
        status = chkAllowedUser (rsComm.clientUser.userName,
         rsComm.clientUser.rodsZone);

        if (status < 0) {
            sendVersion (rsComm.sock, status, 0, NULL, 0);
            cleanupAndExit (status);
	}
    }

    /* send the server version and atatus as part of the protocol. Put
     * rsComm.reconnPort as the status */

    status = sendVersion (rsComm.sock, status, rsComm.reconnPort,
      rsComm.reconnAddr, rsComm.cookie);

    if (status < 0) {
	sendVersion (rsComm.sock, SYS_AGENT_INIT_ERR, 0, NULL, 0);
        cleanupAndExit (status);
    }
#ifdef SYS_TIMING
    printSysTiming ("irodsAgent", "sendVersion", 0);
#endif

    logAgentProc (&rsComm);

    status = agentMain (&rsComm);

    cleanupAndExit (status);

    return (status);
}
Пример #8
0
int main(int argc, char *argv[]) {
  if (!glfwInit()) {
    fprintf(stderr, "Failed to initialize GLFW\n");
    exit(1);
  }
  printf("Welcome to the demo. Controls are quite simple--left/right arrows and space to play, escape to quit. Enjoy!\n");
  printf("Press enter to continue...");
  std::getchar();

  // Demand a core profile.
  glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
  glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
  glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

  // This is really for multisampling not FSAA but whatevs, we still need it.
  glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 8);
  int screen_mode = fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW;
  int width, height;
  if (fullscreen) {
    // Gets native resolution of monitor.
    GLFWvidmode mode;
    glfwGetDesktopMode(&mode);
    width = mode.Width;
    height = mode.Height;
  } else {
    width = 800;
    height = 600;
  }
  if (!glfwOpenWindow(width, height, 0, 0, 0, 0, 24, 8, screen_mode)) {
    fprintf(stderr, "Failed to open GLFW window.\n");
    cleanupAndExit(1);
  }
  int major, minor, rev;
  glfwGetGLVersion(&major, &minor, &rev);
  fprintf(stderr, "OpenGL version: %d.%d.%d\n", major, minor, rev);
  
  // Init glew. We need experimental for a core profile till glew fixes a bug...
  glewExperimental = GL_TRUE;
  GLenum err = glewInit();
  // Glew init spawns an error sometimes. This clears the GL error state for our own use.
  glGetError();
  if (GLEW_OK != err) {
    fprintf(stderr, "GLEW error: %s\n", glewGetErrorString(err));
    cleanupAndExit(1);
  }
  if (!GLEW_VERSION_3_3) {
    fprintf(stderr, "OpenGL 3.3 is not supported.\n");
    cleanupAndExit(1);
  }

  // GLFW options.
  glfwEnable(GLFW_KEY_REPEAT);
  glfwSwapInterval(1);
  // Set callback functions.
  glfwSetKeyCallback(keyboardCallback);
  glfwSetWindowCloseCallback(windowCloseCallback);

  // Make the main game object.
  game = new Game();
  game->init(width, height);  
  // Main loop.
  int frame = 0;
  int print_frequency = 500;
  float last_print_time = static_cast<float>(glfwGetTime());
  float time_updating = 0.0f, time_drawing = 0.0f;
  while (game->stillRunning()) {
    float frame_start_time = static_cast<float>(glfwGetTime());
    ++frame;

    // Update and draw the game.
    game->draw();
    // glFinish will hurt framerate but gives better estimate of the draw time.
    //glFinish();
    float frame_draw_time = static_cast<float>(glfwGetTime());
    time_drawing += frame_draw_time - frame_start_time;
    game->update();
    time_updating += static_cast<float>(glfwGetTime()) - frame_draw_time;
    
    // Print the frame rate every once and a while.
    if (frame % print_frequency == 0) {
      float time_elapsed = frame_start_time - last_print_time;
      printf("FPS: %f\n", print_frequency / (time_elapsed));
      last_print_time = frame_start_time;
      printf("Draw time per frame: %f.\n", time_drawing / print_frequency);
      time_drawing = 0.0f;
      printf("Update time per frame: %f.\n", time_updating / print_frequency);
      time_updating = 0.0f;
    }
    glfwSwapBuffers();
  }
  cleanupAndExit(0);
  return 0;
}
Пример #9
0
int
getFrameSync (dsd_opts * opts, dsd_state * state)
{
  /* detects frame sync and returns frame type
   * 0 = +P25p1
   * 1 = -P25p1
   * 2 = +X2-TDMA (non inverted signal data frame)
   * 3 = +X2-TDMA (inverted signal voice frame)
   * 4 = -X2-TDMA (non inverted signal voice frame)
   * 5 = -X2-TDMA (inverted signal data frame)
   * 6 = +D-STAR
   * 7 = -D-STAR
   * 8 = +NXDN (non inverted voice frame)
   * 9 = -NXDN (inverted voice frame)
   * 10 = +DMR (non inverted singlan data frame)
   * 11 = -DMR (inverted signal voice frame)
   * 12 = +DMR (non inverted signal voice frame)
   * 13 = -DMR (inverted signal data frame)
   * 14 = +ProVoice
   * 15 = -ProVoice
   * 16 = +NXDN (non inverted data frame)
   * 17 = -NXDN (inverted data frame)
   * 18 = +D-STAR_HD
   * 19 = -D-STAR_HD
   */

  int i, j, t, o, dibit, sync, symbol, synctest_pos, lastt;
  char synctest[25];
  char synctest18[19];
  char synctest32[33];
  char modulation[8];
  char *synctest_p;
  char synctest_buf[10240];
  int lmin, lmax, lidx;
  int lbuf[24], lbuf2[24];
  int lsum;
  char spectrum[64];

  for (i = 18; i < 24; i++)
    {
      lbuf[i] = 0;
      lbuf2[i] = 0;
    }

  // detect frame sync
  t = 0;
  synctest[24] = 0;
  synctest18[18] = 0;
  synctest32[32] = 0;
  synctest_pos = 0;
  synctest_p = synctest_buf + 10;
  sync = 0;
  lmin = 0;
  lmax = 0;
  lidx = 0;
  lastt = 0;
  state->numflips = 0;
  if ((opts->symboltiming == 1) && (state->carrier == 1))
    {
      printf ("\nSymbol Timing:\n");
    }
  while (sync == 0)
    {
      t++;
      symbol = getSymbol (opts, state, 0);
      lbuf[lidx] = symbol;
      state->sbuf[state->sidx] = symbol;
      if (lidx == 23)
        {
          lidx = 0;
        }
      else
        {
          lidx++;
        }
      if (state->sidx == (opts->ssize - 1))
        {
          state->sidx = 0;
        }
      else
        {
          state->sidx++;
        }

      if (lastt == 23)
        {
          lastt = 0;
          if (state->numflips > opts->mod_threshold)
            {
              if (opts->mod_qpsk == 1)
                {
                  state->rf_mod = 1;
                }
            }
          else if (state->numflips > 18)
            {
              if (opts->mod_gfsk == 1)
                {
                  state->rf_mod = 2;
                }
            }
          else
            {
              if (opts->mod_c4fm == 1)
                {
                  state->rf_mod = 0;
                }
            }
          state->numflips = 0;
        }
      else
        {
          lastt++;
        }

      if (state->dibit_buf_p > state->dibit_buf + 900000)
        {
    	  state->dibit_buf_p = state->dibit_buf + 200;
        }

      //determine dibit state
      if (symbol > 0)
        {
          *state->dibit_buf_p = 1;
          state->dibit_buf_p++;
          dibit = 49;
        }
      else
        {
          *state->dibit_buf_p = 3;
          state->dibit_buf_p++;
          dibit = 51;
        }

      *synctest_p = dibit;
      if (t >= 18)
        {
          for (i = 0; i < 24; i++)
            {
              lbuf2[i] = lbuf[i];
            }
          qsort (lbuf2, 24, sizeof (int), comp);
          lmin = (lbuf2[2] + lbuf2[3] + lbuf2[4]) / 3;
          lmax = (lbuf2[21] + lbuf2[20] + lbuf2[19]) / 3;

          if (state->rf_mod == 1)
            {
              state->minbuf[state->midx] = lmin;
              state->maxbuf[state->midx] = lmax;
              if (state->midx == (opts->msize - 1))
                {
                  state->midx = 0;
                }
              else
                {
                  state->midx++;
                }
              lsum = 0;
              for (i = 0; i < opts->msize; i++)
                {
                  lsum += state->minbuf[i];
                }
              state->min = lsum / opts->msize;
              lsum = 0;
              for (i = 0; i < opts->msize; i++)
                {
                  lsum += state->maxbuf[i];
                }
              state->max = lsum / opts->msize;
              state->center = ((state->max) + (state->min)) / 2;
              state->maxref = ((state->max) * 0.80);
              state->minref = ((state->min) * 0.80);
            }
          else
            {
              state->maxref = state->max;
              state->minref = state->min;
            }

          if (state->rf_mod == 0)
            {
              sprintf (modulation, "C4FM");
            }
          else if (state->rf_mod == 1)
            {
              sprintf (modulation, "QPSK");
            }
          else if (state->rf_mod == 2)
            {
              sprintf (modulation, "GFSK");
            }

          if (opts->datascope == 1)
            {
              if (lidx == 0)
                {
                  for (i = 0; i < 64; i++)
                    {
                      spectrum[i] = 0;
                    }
                  for (i = 0; i < 24; i++)
                    {
                      o = (lbuf2[i] + 32768) / 1024;
                      spectrum[o]++;
                    }
                  if (state->symbolcnt > (4800 / opts->scoperate))
                    {
                      state->symbolcnt = 0;
                      printf ("\n");
                      printf ("Demod mode:     %s                Nac:                     %4X\n", modulation, state->nac);
                      printf ("Frame Type:    %s        Talkgroup:            %7i\n", state->ftype, state->lasttg);
                      printf ("Frame Subtype: %s       Source:          %12i\n", state->fsubtype, state->lastsrc);
                      printf ("TDMA activity:  %s %s     Voice errors: %s\n", state->slot0light, state->slot1light, state->err_str);
                      printf ("+----------------------------------------------------------------+\n");
                      for (i = 0; i < 10; i++)
                        {
                          printf ("|");
                          for (j = 0; j < 64; j++)
                            {
                              if (i == 0)
                                {
                                  if ((j == ((state->min) + 32768) / 1024) || (j == ((state->max) + 32768) / 1024))
                                    {
                                      printf ("#");
                                    }
                                  else if (j == (state->center + 32768) / 1024)
                                    {
                                      printf ("!");
                                    }
                                  else
                                    {
                                      if (j == 32)
                                        {
                                          printf ("|");
                                        }
                                      else
                                        {
                                          printf (" ");
                                        }
                                    }
                                }
                              else
                                {
                                  if (spectrum[j] > 9 - i)
                                    {
                                      printf ("*");
                                    }
                                  else
                                    {
                                      if (j == 32)
                                        {
                                          printf ("|");
                                        }
                                      else
                                        {
                                          printf (" ");
                                        }
                                    }
                                }
                            }
                          printf ("|\n");
                        }
                      printf ("+----------------------------------------------------------------+\n");
                    }
                }
            }

          strncpy (synctest, (synctest_p - 23), 24);
          if (opts->frame_p25p1 == 1)
            {
              if (strcmp (synctest, P25P1_SYNC) == 0)
                {
                  state->carrier = 1;
                  state->offset = synctest_pos;
                  state->max = ((state->max) + lmax) / 2;
                  state->min = ((state->min) + lmin) / 2;
                  sprintf (state->ftype, " P25 Phase 1 ");
                  if (opts->errorbars == 1)
                    {
                      printFrameSync (opts, state, " +P25p1    ", synctest_pos + 1, modulation);
                    }
                  state->lastsynctype = 0;
                  return (0);
                }
              if (strcmp (synctest, INV_P25P1_SYNC) == 0)
                {
                  state->carrier = 1;
                  state->offset = synctest_pos;
                  state->max = ((state->max) + lmax) / 2;
                  state->min = ((state->min) + lmin) / 2;
                  sprintf (state->ftype, " P25 Phase 1 ");
                  if (opts->errorbars == 1)
                    {
                      printFrameSync (opts, state, " -P25p1    ", synctest_pos + 1, modulation);
                    }
                  state->lastsynctype = 1;
                  return (1);
                }
            }
          if (opts->frame_x2tdma == 1)
            {
              if ((strcmp (synctest, X2TDMA_BS_DATA_SYNC) == 0) || (strcmp (synctest, X2TDMA_MS_DATA_SYNC) == 0))
                {
                  state->carrier = 1;
                  state->offset = synctest_pos;
                  state->max = ((state->max) + (lmax)) / 2;
                  state->min = ((state->min) + (lmin)) / 2;
                  if (opts->inverted_x2tdma == 0)
                    {
                      // data frame
                      sprintf (state->ftype, " X2-TDMA     ");
                      if (opts->errorbars == 1)
                        {
                          printFrameSync (opts, state, " +X2-TDMA  ", synctest_pos + 1, modulation);
                        }
                      state->lastsynctype = 2;
                      return (2);
                    }
                  else
                    {
                      // inverted voice frame
                      sprintf (state->ftype, " X2-TDMA     ");
                      if (opts->errorbars == 1)
                        {
                          printFrameSync (opts, state, " -X2-TDMA  ", synctest_pos + 1, modulation);
                        }
                      if (state->lastsynctype != 3)
                        {
                          state->firstframe = 1;
                        }
                      state->lastsynctype = 3;
                      return (3);
                    }
                }
              if ((strcmp (synctest, X2TDMA_BS_VOICE_SYNC) == 0) || (strcmp (synctest, X2TDMA_MS_VOICE_SYNC) == 0))
                {
                  state->carrier = 1;
                  state->offset = synctest_pos;
                  state->max = ((state->max) + lmax) / 2;
                  state->min = ((state->min) + lmin) / 2;
                  if (opts->inverted_x2tdma == 0)
                    {
                      // voice frame
                      sprintf (state->ftype, " X2-TDMA     ");
                      if (opts->errorbars == 1)
                        {
                          printFrameSync (opts, state, " +X2-TDMA  ", synctest_pos + 1, modulation);
                        }
                      if (state->lastsynctype != 4)
                        {
                          state->firstframe = 1;
                        }
                      state->lastsynctype = 4;
                      return (4);
                    }
                  else
                    {
                      // inverted data frame
                      sprintf (state->ftype, " X2-TDMA     ");
                      if (opts->errorbars == 1)
                        {
                          printFrameSync (opts, state, " -X2-TDMA  ", synctest_pos + 1, modulation);
                        }
                      state->lastsynctype = 5;
                      return (5);
                    }
                }
            }
          if (opts->frame_dmr == 1)
            {
              if ((strcmp (synctest, DMR_MS_DATA_SYNC) == 0) || (strcmp (synctest, DMR_BS_DATA_SYNC) == 0))
                {
                  state->carrier = 1;
                  state->offset = synctest_pos;
                  state->max = ((state->max) + (lmax)) / 2;
                  state->min = ((state->min) + (lmin)) / 2;
                  if (opts->inverted_dmr == 0)
                    {
                      // data frame
                      sprintf (state->ftype, " DMR         ");
                      if (opts->errorbars == 1)
                        {
                          printFrameSync (opts, state, " +DMR      ", synctest_pos + 1, modulation);
                        }
                      state->lastsynctype = 10;
                      return (10);
                    }
                  else
                    {
                      // inverted voice frame
                      sprintf (state->ftype, " DMR         ");
                      if (opts->errorbars == 1)
                        {
                          printFrameSync (opts, state, " -DMR      ", synctest_pos + 1, modulation);
                        }
                      if (state->lastsynctype != 11)
                        {
                          state->firstframe = 1;
                        }
                      state->lastsynctype = 11;
                      return (11);
                    }
                }
              if ((strcmp (synctest, DMR_MS_VOICE_SYNC) == 0) || (strcmp (synctest, DMR_BS_VOICE_SYNC) == 0))
                {
                  state->carrier = 1;
                  state->offset = synctest_pos;
                  state->max = ((state->max) + lmax) / 2;
                  state->min = ((state->min) + lmin) / 2;
                  if (opts->inverted_dmr == 0)
                    {
                      // voice frame
                      sprintf (state->ftype, " DMR         ");
                      if (opts->errorbars == 1)
                        {
                          printFrameSync (opts, state, " +DMR      ", synctest_pos + 1, modulation);
                        }
                      if (state->lastsynctype != 12)
                        {
                          state->firstframe = 1;
                        }
                      state->lastsynctype = 12;
                      return (12);
                    }
                  else
                    {
                      // inverted data frame
                      sprintf (state->ftype, " DMR         ");
                      if (opts->errorbars == 1)
                        {
                          printFrameSync (opts, state, " -DMR      ", synctest_pos + 1, modulation);
                        }
                      state->lastsynctype = 13;
                      return (13);
                    }
                }
            }
          if (opts->frame_provoice == 1)
            {
              strncpy (synctest32, (synctest_p - 31), 32);
              if ((strcmp (synctest32, PROVOICE_SYNC) == 0) || (strcmp (synctest32, PROVOICE_EA_SYNC) == 0))
                {
                  state->carrier = 1;
                  state->offset = synctest_pos;
                  state->max = ((state->max) + lmax) / 2;
                  state->min = ((state->min) + lmin) / 2;
                  sprintf (state->ftype, " ProVoice    ");
                  if (opts->errorbars == 1)
                    {
                      printFrameSync (opts, state, " -ProVoice ", synctest_pos + 1, modulation);
                    }
                  state->lastsynctype = 14;
                  return (14);
                }
              else if ((strcmp (synctest32, INV_PROVOICE_SYNC) == 0) || (strcmp (synctest32, INV_PROVOICE_EA_SYNC) == 0))
                {
                  state->carrier = 1;
                  state->offset = synctest_pos;
                  state->max = ((state->max) + lmax) / 2;
                  state->min = ((state->min) + lmin) / 2;
                  sprintf (state->ftype, " ProVoice    ");
                  if (opts->errorbars == 1)
                    {
                      printFrameSync (opts, state, " -ProVoice ", synctest_pos + 1, modulation);
                    }
                  state->lastsynctype = 15;
                  return (15);
                }

            }
          if ((opts->frame_nxdn96 == 1) || (opts->frame_nxdn48 == 1))
            {
              strncpy (synctest18, (synctest_p - 17), 18);
              if ((strcmp (synctest18, NXDN_BS_VOICE_SYNC) == 0) || (strcmp (synctest18, NXDN_MS_VOICE_SYNC) == 0))
                {
                  if ((state->lastsynctype == 8) || (state->lastsynctype == 16))
                    {
                      state->carrier = 1;
                      state->offset = synctest_pos;
                      state->max = ((state->max) + lmax) / 2;
                      state->min = ((state->min) + lmin) / 2;
                      if (state->samplesPerSymbol == 20)
                        {
                          sprintf (state->ftype, " NXDN48      ");
                          if (opts->errorbars == 1)
                            {
                              printFrameSync (opts, state, " +NXDN48   ", synctest_pos + 1, modulation);
                            }
                        }
                      else
                        {
                          sprintf (state->ftype, " NXDN96      ");
                          if (opts->errorbars == 1)
                            {
                              printFrameSync (opts, state, " +NXDN96   ", synctest_pos + 1, modulation);
                            }
                        }
                      state->lastsynctype = 8;
                      return (8);
                    }
                  else
                    {
                      state->lastsynctype = 8;
                    }
                }
              else if ((strcmp (synctest18, INV_NXDN_BS_VOICE_SYNC) == 0) || (strcmp (synctest18, INV_NXDN_MS_VOICE_SYNC) == 0))
                {
                  if ((state->lastsynctype == 9) || (state->lastsynctype == 17))
                    {
                      state->carrier = 1;
                      state->offset = synctest_pos;
                      state->max = ((state->max) + lmax) / 2;
                      state->min = ((state->min) + lmin) / 2;
                      if (state->samplesPerSymbol == 20)
                        {
                          sprintf (state->ftype, " NXDN48      ");
                          if (opts->errorbars == 1)
                            {
                              printFrameSync (opts, state, " -NXDN48   ", synctest_pos + 1, modulation);
                            }
                        }
                      else
                        {
                          sprintf (state->ftype, " NXDN96      ");
                          if (opts->errorbars == 1)
                            {
                              printFrameSync (opts, state, " -NXDN96   ", synctest_pos + 1, modulation);
                            }
                        }
                      state->lastsynctype = 9;
                      return (9);
                    }
                  else
                    {
                      state->lastsynctype = 9;
                    }
                }
              else if ((strcmp (synctest18, NXDN_BS_DATA_SYNC) == 0) || (strcmp (synctest18, NXDN_MS_DATA_SYNC) == 0))
                {
                  if ((state->lastsynctype == 8) || (state->lastsynctype == 16))
                    {
                      state->carrier = 1;
                      state->offset = synctest_pos;
                      state->max = ((state->max) + lmax) / 2;
                      state->min = ((state->min) + lmin) / 2;
                      if (state->samplesPerSymbol == 20)
                        {
                          sprintf (state->ftype, " NXDN48      ");
                          if (opts->errorbars == 1)
                            {
                              printFrameSync (opts, state, " +NXDN48   ", synctest_pos + 1, modulation);
                            }
                        }
                      else
                        {
                          sprintf (state->ftype, " NXDN96      ");
                          if (opts->errorbars == 1)
                            {
                              printFrameSync (opts, state, " +NXDN96   ", synctest_pos + 1, modulation);
                            }
                        }
                      state->lastsynctype = 16;
                      return (16);
                    }
                  else
                    {
                      state->lastsynctype = 16;
                    }
                }
              else if ((strcmp (synctest18, INV_NXDN_BS_DATA_SYNC) == 0) || (strcmp (synctest18, INV_NXDN_MS_DATA_SYNC) == 0))
                {
                  if ((state->lastsynctype == 9) || (state->lastsynctype == 17))
                    {
                      state->carrier = 1;
                      state->offset = synctest_pos;
                      state->max = ((state->max) + lmax) / 2;
                      state->min = ((state->min) + lmin) / 2;
                      sprintf (state->ftype, " NXDN        ");
                      if (state->samplesPerSymbol == 20)
                        {
                          sprintf (state->ftype, " NXDN48      ");
                          if (opts->errorbars == 1)
                            {
                              printFrameSync (opts, state, " -NXDN48   ", synctest_pos + 1, modulation);
                            }
                        }
                      else
                        {
                          sprintf (state->ftype, " NXDN96      ");
                          if (opts->errorbars == 1)
                            {
                              printFrameSync (opts, state, " -NXDN96   ", synctest_pos + 1, modulation);
                            }
                        }
                      state->lastsynctype = 17;
                      return (17);
                    }
                  else
                    {
                      state->lastsynctype = 17;
                    }
                }
            }
          if (opts->frame_dstar == 1)
            {
              if (strcmp (synctest, DSTAR_SYNC) == 0)
                {
                  state->carrier = 1;
                  state->offset = synctest_pos;
                  state->max = ((state->max) + lmax) / 2;
                  state->min = ((state->min) + lmin) / 2;
                  sprintf (state->ftype, " D-STAR      ");
                  if (opts->errorbars == 1)
                    {
                      printFrameSync (opts, state, " +D-STAR   ", synctest_pos + 1, modulation);
                    }
                  state->lastsynctype = 6;
                  return (6);
                }
              if (strcmp (synctest, INV_DSTAR_SYNC) == 0)
                {
                  state->carrier = 1;
                  state->offset = synctest_pos;
                  state->max = ((state->max) + lmax) / 2;
                  state->min = ((state->min) + lmin) / 2;
                  sprintf (state->ftype, " D-STAR      ");
                  if (opts->errorbars == 1)
                    {
                      printFrameSync (opts, state, " -D-STAR   ", synctest_pos + 1, modulation);
                    }
                  state->lastsynctype = 7;
                  return (7);
                }
              if (strcmp (synctest, DSTAR_HD) == 0)
				  {
					state->carrier = 1;
					state->offset = synctest_pos;
					state->max = ((state->max) + lmax) / 2;
					state->min = ((state->min) + lmin) / 2;
					sprintf (state->ftype, " D-STAR_HD   ");
					if (opts->errorbars == 1)
					  {
						printFrameSync (opts, state, " +D-STAR_HD   ", synctest_pos + 1, modulation);
					  }
					state->lastsynctype = 18;
					return (18);
				  }
              if (strcmp (synctest, INV_DSTAR_HD) == 0)
				  {
					state->carrier = 1;
					state->offset = synctest_pos;
					state->max = ((state->max) + lmax) / 2;
					state->min = ((state->min) + lmin) / 2;
					sprintf (state->ftype, " D-STAR_HD   ");
					if (opts->errorbars == 1)
					  {
						printFrameSync (opts, state, " -D-STAR_HD   ", synctest_pos + 1, modulation);
					  }
					state->lastsynctype = 19;
					return (19);
				  }

            }

          if ((t == 24) && (state->lastsynctype != -1))
            {
              if ((state->lastsynctype == 0) && ((state->lastp25type == 1) || (state->lastp25type == 2)))
                {
                  state->carrier = 1;
                  state->offset = synctest_pos;
                  state->max = ((state->max) + (lmax)) / 2;
                  state->min = ((state->min) + (lmin)) / 2;
                  sprintf (state->ftype, "(P25 Phase 1)");
                  if (opts->errorbars == 1)
                    {
                      printFrameSync (opts, state, "(+P25p1)   ", synctest_pos + 1, modulation);
                    }
                  state->lastsynctype = -1;
                  return (0);
                }
              else if ((state->lastsynctype == 1) && ((state->lastp25type == 1) || (state->lastp25type == 2)))
                {
                  state->carrier = 1;
                  state->offset = synctest_pos;
                  state->max = ((state->max) + lmax) / 2;
                  state->min = ((state->min) + lmin) / 2;
                  sprintf (state->ftype, "(P25 Phase 1)");
                  if (opts->errorbars == 1)
                    {
                      printFrameSync (opts, state, "(-P25p1)   ", synctest_pos + 1, modulation);
                    }
                  state->lastsynctype = -1;
                  return (1);
                }
              else if ((state->lastsynctype == 3) && ((strcmp (synctest, X2TDMA_BS_VOICE_SYNC) != 0) || (strcmp (synctest, X2TDMA_MS_VOICE_SYNC) != 0)))
                {
                  state->carrier = 1;
                  state->offset = synctest_pos;
                  state->max = ((state->max) + lmax) / 2;
                  state->min = ((state->min) + lmin) / 2;
                  sprintf (state->ftype, "(X2-TDMA)    ");
                  if (opts->errorbars == 1)
                    {
                      printFrameSync (opts, state, "(-X2-TDMA) ", synctest_pos + 1, modulation);
                    }
                  state->lastsynctype = -1;
                  return (3);
                }
              else if ((state->lastsynctype == 4) && ((strcmp (synctest, X2TDMA_BS_DATA_SYNC) != 0) || (strcmp (synctest, X2TDMA_MS_DATA_SYNC) != 0)))
                {
                  state->carrier = 1;
                  state->offset = synctest_pos;
                  state->max = ((state->max) + lmax) / 2;
                  state->min = ((state->min) + lmin) / 2;
                  sprintf (state->ftype, "(X2-TDMA)    ");
                  if (opts->errorbars == 1)
                    {
                      printFrameSync (opts, state, "(+X2-TDMA) ", synctest_pos + 1, modulation);
                    }
                  state->lastsynctype = -1;
                  return (4);
                }
              else if ((state->lastsynctype == 11) && ((strcmp (synctest, DMR_BS_VOICE_SYNC) != 0) || (strcmp (synctest, DMR_MS_VOICE_SYNC) != 0)))
                {
                  state->carrier = 1;
                  state->offset = synctest_pos;
                  state->max = ((state->max) + lmax) / 2;
                  state->min = ((state->min) + lmin) / 2;
                  sprintf (state->ftype, "(DMR)        ");
                  if (opts->errorbars == 1)
                    {
                      printFrameSync (opts, state, "(-DMR)     ", synctest_pos + 1, modulation);
                    }
                  state->lastsynctype = -1;
                  return (11);
                }
              else if ((state->lastsynctype == 12) && ((strcmp (synctest, DMR_BS_DATA_SYNC) != 0) || (strcmp (synctest, DMR_MS_DATA_SYNC) != 0)))
                {
                  state->carrier = 1;
                  state->offset = synctest_pos;
                  state->max = ((state->max) + lmax) / 2;
                  state->min = ((state->min) + lmin) / 2;
                  sprintf (state->ftype, "(DMR)        ");
                  if (opts->errorbars == 1)
                    {
                      printFrameSync (opts, state, "(+DMR)     ", synctest_pos + 1, modulation);
                    }
                  state->lastsynctype = -1;
                  return (12);
                }
            }
        }

      if (exitflag == 1)
        {
          cleanupAndExit (opts, state);
        }

      if (synctest_pos < 10200)
        {
          synctest_pos++;
          synctest_p++;
        }
      else
        {
          // buffer reset
          synctest_pos = 0;
          synctest_p = synctest_buf;
          noCarrier (opts, state);
        }

      if (state->lastsynctype != 1)
        {
          if (synctest_pos >= 1800)
            {
              if ((opts->errorbars == 1) && (opts->verbose > 1) && (state->carrier == 1))
                {
                  printf ("Sync: no sync\n");
                }
              noCarrier (opts, state);
              return (-1);
            }
        }
    }

  return (-1);
}
Пример #10
0
int
xmsgServerMain() {
    int status = 0;
    rsComm_t rsComm;
    rsComm_t svrComm;	/* rsComm is connection to icat, svrComm is the
                         * server's listening socket */
    fd_set sockMask;
    int numSock;

    initThreadEnv();
    initXmsgHashQue();

    status = startXmsgThreads();

    if ( status < 0 ) {
        rodsLog( LOG_ERROR,
                 "xmsgServerMain: startXmsgThreads error. status = %d", status );
        return status;
    }

    status = initRsComm( &rsComm );

    if ( status < 0 ) {
        rodsLog( LOG_ERROR, "xmsgServerMain: initRsComm error. status = %d",
                 status );
        return status;
    }

    status = initRsComm( &svrComm );

    if ( status < 0 ) {
        rodsLog( LOG_ERROR, "xmsgServerMain: initRsComm error. status = %d",
                 status );
        return status;
    }

    status = initAgent( RULE_ENGINE_NO_CACHE, &rsComm );

    if ( status < 0 ) {
        rodsLog( LOG_ERROR, "xmsgServerMain: initAgent error. status = %d",
                 status );
        return status;
    }


    // =-=-=-=-=-=-=-
    // handle negotiations with the client regarding TLS if requested
    irods::error ret;

    // =-=-=-=-=-=-=-
    // manufacture a network object for comms
    irods::network_object_ptr net_obj;
    ret = irods::network_factory( &rsComm, net_obj );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
    }

    std::string neg_results;
    ret = irods::client_server_negotiation_for_server( net_obj, neg_results );
    if ( !ret.ok() || neg_results == irods::CS_NEG_FAILURE ) {
        irods::log( PASS( ret ) );
        // =-=-=-=-=-=-=-
        // send a 'we failed to negotiate' message here??
        // or use the error stack rule engine thingie
        irods::log( PASS( ret ) );
        sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 );
        cleanupAndExit( ret.code() );

    }
    else {
        // =-=-=-=-=-=-=-
        // copy negotiation results to comm for action by network objects
        snprintf( rsComm.negotiation_results, sizeof( rsComm.negotiation_results ),
                  "%s", neg_results.c_str() );
        //rsComm.ssl_do_accept = 1;

    }

    int xmsg_port = 0;
    ret = irods::get_server_property<
          int > (
              irods::CFG_XMSG_PORT,
              xmsg_port );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        return ret.code();

    }

    /* open  a socket and listen for connection */
    svrComm.sock = sockOpenForInConn(
                       &svrComm,
                       &xmsg_port,
                       NULL,
                       SOCK_STREAM );

    if ( svrComm.sock < 0 ) {
        rodsLog( LOG_NOTICE, "xmsgServerMain: sockOpenForInConn error. status = %d",
                 svrComm.sock );
        exit( 1 );
    }

    listen( svrComm.sock, MAX_LISTEN_QUE );

    FD_ZERO( &sockMask );

    rodsLog( LOG_NOTICE, "xmsgServer version %s is up", RODS_REL_VERSION );

    while ( 1 ) {       /* infinite loop */
        FD_SET( svrComm.sock, &sockMask );
        while ( ( numSock = select( svrComm.sock + 1, &sockMask,
                                    ( fd_set * ) NULL, ( fd_set * ) NULL, ( struct timeval * ) NULL ) ) < 0 ) {

            if ( errno == EINTR ) {
                rodsLog( LOG_NOTICE, "xmsgServerMain: select() interrupted" );
                FD_SET( svrComm.sock, &sockMask );
                continue;
            }
            else {
                rodsLog( LOG_NOTICE, "xmsgServerMain: select() error, errno = %d", errno );
                return -1;
            }
        }

        const int newSock = rsAcceptConn( &svrComm );

        if ( newSock < 0 ) {
            rodsLog( LOG_NOTICE,
                     "xmsgServerMain: acceptConn () error, errno = %d", errno );
            continue;
        }

        addReqToQue( newSock );

        if ( loopCnt > 0 ) {
            loopCnt--;
            if ( loopCnt == 0 ) {
                return 0;
            }
        }


    }
    return 0;
}
Пример #11
0
int
main (int argc, char **argv)
{

  int c;
  extern char *optarg;
  extern int optind, opterr, optopt;
  dsd_opts opts;
  dsd_state state;
  char versionstr[25];
  mbe_printVersion (versionstr);

  printf ("Digital Speech Decoder 1.7.0-dev (build:%s)\n", GIT_TAG);
  printf ("mbelib version %s\n", versionstr);

  initOpts (&opts);
  initState (&state);

  exitflag = 0;
  signal (SIGINT, sigfun);

  while ((c = getopt (argc, argv, "hep:qstv:z:i:o:d:g:nw:B:C:R:f:m:u:x:A:S:M:rl")) != -1)
    {
      opterr = 0;
      switch (c)
        {
        case 'h':
          usage ();
          exit (0);
        case 'e':
          opts.errorbars = 1;
          opts.datascope = 0;
          break;
        case 'p':
          if (optarg[0] == 'e')
            {
              opts.p25enc = 1;
            }
          else if (optarg[0] == 'l')
            {
              opts.p25lc = 1;
            }
          else if (optarg[0] == 's')
            {
              opts.p25status = 1;
            }
          else if (optarg[0] == 't')
            {
              opts.p25tg = 1;
            }
          else if (optarg[0] == 'u')
            {
        	  opts.unmute_encrypted_p25 = 1;
            }
          break;
        case 'q':
          opts.errorbars = 0;
          opts.verbose = 0;
          break;
        case 's':
          opts.errorbars = 0;
          opts.p25enc = 0;
          opts.p25lc = 0;
          opts.p25status = 0;
          opts.p25tg = 0;
          opts.datascope = 1;
          opts.symboltiming = 0;
          break;
        case 't':
          opts.symboltiming = 1;
          opts.errorbars = 1;
          opts.datascope = 0;
          break;
        case 'v':
          sscanf (optarg, "%d", &opts.verbose);
          break;
        case 'z':
          sscanf (optarg, "%d", &opts.scoperate);
          opts.errorbars = 0;
          opts.p25enc = 0;
          opts.p25lc = 0;
          opts.p25status = 0;
          opts.p25tg = 0;
          opts.datascope = 1;
          opts.symboltiming = 0;
          printf ("Setting datascope frame rate to %i frame per second.\n", opts.scoperate);
          break;
        case 'i':
          strncpy(opts.audio_in_dev, optarg, 1023);
          opts.audio_in_dev[1023] = '\0';
          break;
        case 'o':
          strncpy(opts.audio_out_dev, optarg, 1023);
          opts.audio_out_dev[1023] = '\0';
          break;
        case 'd':
          strncpy(opts.mbe_out_dir, optarg, 1023);
          opts.mbe_out_dir[1023] = '\0';
          printf ("Writing mbe data files to directory %s\n", opts.mbe_out_dir);
          break;
        case 'g':
          sscanf (optarg, "%f", &opts.audio_gain);
          if (opts.audio_gain < (float) 0 )
            {
              printf ("Disabling audio out gain setting\n");
            }
          else if (opts.audio_gain == (float) 0)
            {
              opts.audio_gain = (float) 0;
              printf ("Enabling audio out auto-gain\n");
            }
          else
            {
              printf ("Setting audio out gain to %f\n", opts.audio_gain);
              state.aout_gain = opts.audio_gain;
            }
          break;
        case 'n':
          opts.audio_out = 0;
          printf ("Disabling audio output to soundcard.\n");
          break;
        case 'w':
          strncpy(opts.wav_out_file, optarg, 1023);
          opts.wav_out_file[1023] = '\0';
          printf ("Writing audio to file %s\n", opts.wav_out_file);
          openWavOutFile (&opts, &state);
          break;
        case 'B':
          sscanf (optarg, "%d", &opts.serial_baud);
          break;
        case 'C':
          strncpy(opts.serial_dev, optarg, 1023);
          opts.serial_dev[1023] = '\0';
          break;
        case 'R':
          sscanf (optarg, "%d", &opts.resume);
          printf ("Enabling scan resume after %i TDULC frames\n", opts.resume);
          break;
        case 'f':
          if (optarg[0] == 'a')
            {
              opts.frame_dstar = 1;
              opts.frame_x2tdma = 1;
              opts.frame_p25p1 = 1;
              opts.frame_nxdn48 = 0;
              opts.frame_nxdn96 = 1;
              opts.frame_dmr = 1;
              opts.frame_provoice = 0;
            }
          else if (optarg[0] == 'd')
            {
              opts.frame_dstar = 1;
              opts.frame_x2tdma = 0;
              opts.frame_p25p1 = 0;
              opts.frame_nxdn48 = 0;
              opts.frame_nxdn96 = 0;
              opts.frame_dmr = 0;
              opts.frame_provoice = 0;
              printf ("Decoding only D-STAR frames.\n");
            }
          else if (optarg[0] == 'x')
            {
              opts.frame_dstar = 0;
              opts.frame_x2tdma = 1;
              opts.frame_p25p1 = 0;
              opts.frame_nxdn48 = 0;
              opts.frame_nxdn96 = 0;
              opts.frame_dmr = 0;
              opts.frame_provoice = 0;
              printf ("Decoding only X2-TDMA frames.\n");
            }
          else if (optarg[0] == 'p')
            {
              opts.frame_dstar = 0;
              opts.frame_x2tdma = 0;
              opts.frame_p25p1 = 0;
              opts.frame_nxdn48 = 0;
              opts.frame_nxdn96 = 0;
              opts.frame_dmr = 0;
              opts.frame_provoice = 1;
              state.samplesPerSymbol = 5;
              state.symbolCenter = 2;
              opts.mod_c4fm = 0;
              opts.mod_qpsk = 0;
              opts.mod_gfsk = 1;
              state.rf_mod = 2;
              printf ("Setting symbol rate to 9600 / second\n");
              printf ("Enabling only GFSK modulation optimizations.\n");
              printf ("Decoding only ProVoice frames.\n");
            }
          else if (optarg[0] == '1')
            {
              opts.frame_dstar = 0;
              opts.frame_x2tdma = 0;
              opts.frame_p25p1 = 1;
              opts.frame_nxdn48 = 0;
              opts.frame_nxdn96 = 0;
              opts.frame_dmr = 0;
              opts.frame_provoice = 0;
              printf ("Decoding only P25 Phase 1 frames.\n");
            }
          else if (optarg[0] == 'i')
            {
              opts.frame_dstar = 0;
              opts.frame_x2tdma = 0;
              opts.frame_p25p1 = 0;
              opts.frame_nxdn48 = 1;
              opts.frame_nxdn96 = 0;
              opts.frame_dmr = 0;
              opts.frame_provoice = 0;
              state.samplesPerSymbol = 20;
              state.symbolCenter = 10;
              opts.mod_c4fm = 0;
              opts.mod_qpsk = 0;
              opts.mod_gfsk = 1;
              state.rf_mod = 2;
              printf ("Setting symbol rate to 2400 / second\n");
              printf ("Enabling only GFSK modulation optimizations.\n");
              printf ("Decoding only NXDN 4800 baud frames.\n");
            }
          else if (optarg[0] == 'n')
            {
              opts.frame_dstar = 0;
              opts.frame_x2tdma = 0;
              opts.frame_p25p1 = 0;
              opts.frame_nxdn48 = 0;
              opts.frame_nxdn96 = 1;
              opts.frame_dmr = 0;
              opts.frame_provoice = 0;
              opts.mod_c4fm = 0;
              opts.mod_qpsk = 0;
              opts.mod_gfsk = 1;
              state.rf_mod = 2;
              printf ("Enabling only GFSK modulation optimizations.\n");
              printf ("Decoding only NXDN 9600 baud frames.\n");
            }
          else if (optarg[0] == 'r')
            {
              opts.frame_dstar = 0;
              opts.frame_x2tdma = 0;
              opts.frame_p25p1 = 0;
              opts.frame_nxdn48 = 0;
              opts.frame_nxdn96 = 0;
              opts.frame_dmr = 1;
              opts.frame_provoice = 0;
              printf ("Decoding only DMR/MOTOTRBO frames.\n");
            }
          break;
        case 'm':
          if (optarg[0] == 'a')
            {
              opts.mod_c4fm = 1;
              opts.mod_qpsk = 1;
              opts.mod_gfsk = 1;
              state.rf_mod = 0;
            }
          else if (optarg[0] == 'c')
            {
              opts.mod_c4fm = 1;
              opts.mod_qpsk = 0;
              opts.mod_gfsk = 0;
              state.rf_mod = 0;
              printf ("Enabling only C4FM modulation optimizations.\n");
            }
          else if (optarg[0] == 'g')
            {
              opts.mod_c4fm = 0;
              opts.mod_qpsk = 0;
              opts.mod_gfsk = 1;
              state.rf_mod = 2;
              printf ("Enabling only GFSK modulation optimizations.\n");
            }
          else if (optarg[0] == 'q')
            {
              opts.mod_c4fm = 0;
              opts.mod_qpsk = 1;
              opts.mod_gfsk = 0;
              state.rf_mod = 1;
              printf ("Enabling only QPSK modulation optimizations.\n");
            }
          break;
        case 'u':
          sscanf (optarg, "%i", &opts.uvquality);
          if (opts.uvquality < 1)
            {
              opts.uvquality = 1;
            }
          else if (opts.uvquality > 64)
            {
              opts.uvquality = 64;
            }
          printf ("Setting unvoice speech quality to %i waves per band.\n", opts.uvquality);
          break;
        case 'x':
          if (optarg[0] == 'x')
            {
              opts.inverted_x2tdma = 0;
              printf ("Expecting non-inverted X2-TDMA signals.\n");
            }
          else if (optarg[0] == 'r')
            {
              opts.inverted_dmr = 1;
              printf ("Expecting inverted DMR/MOTOTRBO signals.\n");
            }
          break;
        case 'A':
          sscanf (optarg, "%i", &opts.mod_threshold);
          printf ("Setting C4FM/QPSK auto detection threshold to %i\n", opts.mod_threshold);
          break;
        case 'S':
          sscanf (optarg, "%i", &opts.ssize);
          if (opts.ssize > 128)
            {
              opts.ssize = 128;
            }
          else if (opts.ssize < 1)
            {
              opts.ssize = 1;
            }
          printf ("Setting QPSK symbol buffer to %i\n", opts.ssize);
          break;
        case 'M':
          sscanf (optarg, "%i", &opts.msize);
          if (opts.msize > 1024)
            {
              opts.msize = 1024;
            }
          else if (opts.msize < 1)
            {
              opts.msize = 1;
            }
          printf ("Setting QPSK Min/Max buffer to %i\n", opts.msize);
          break;
        case 'r':
          opts.playfiles = 1;
          opts.errorbars = 0;
          opts.datascope = 0;
          state.optind = optind;
          break;
        case 'l':
          opts.use_cosine_filter = 0;
          break;
        default:
          usage ();
          exit (0);
        }
    }


  if (opts.resume > 0)
    {
      openSerial (&opts, &state);
    }

  if (opts.playfiles == 1)
    {
      opts.split = 1;
      opts.playoffset = 0;
      opts.delay = 0;
      if(strlen(opts.wav_out_file) > 0) {
        openWavOutFile (&opts, &state);
      }
      else {
        openAudioOutDevice (&opts, 8000);
      }
    }
  else if (strcmp (opts.audio_in_dev, opts.audio_out_dev) != 0)
    {
      opts.split = 1;
      opts.playoffset = 0;
      opts.delay = 0;
      if(strlen(opts.wav_out_file) > 0) {
        openWavOutFile (&opts, &state);
      }
      else {
        openAudioOutDevice (&opts, 8000);
      }
      openAudioInDevice (&opts);
    }
  else
    {
      opts.split = 0;
      opts.playoffset = 25;     // 38
      opts.delay = 0;
      openAudioInDevice (&opts);
      opts.audio_out_fd = opts.audio_in_fd;
    }

  if (opts.playfiles == 1)
    {
      playMbeFiles (&opts, &state, argc, argv);
    }
  else
    {
      liveScanner (&opts, &state);
    }
  cleanupAndExit (&opts, &state);
  return (0);
}
Пример #12
0
static void updateConfig( void )
	{
#if 0
	const char *driverPath = "acospkcs11.dll";		/* ACOS */
	const char *driverPath = "aetpkss1.dll";		/* AET */
	const char *driverPath = "aloaha_pkcs11.dll";	/* Aloaha */
	const char *driverPath = "etpkcs11.dll";		/* Aladdin eToken */
	const char *driverPath = "psepkcs11.dll";		/* A-Sign */
	const char *driverPath = "asepkcs.dll";			/* Athena */
	const char *driverPath = "c:/temp/bpkcs11.dll";	/* Bloomberg */
	const char *driverPath = "cryst32.dll";			/* Chrysalis */
	const char *driverPath = "c:/program files/luna/cryst201.dll";	/* Chrysalis */
	const char *driverPath = "pkcs201n.dll";		/* Datakey */
	const char *driverPath = "dkck201.dll";			/* Datakey (for Entrust) */
	const char *driverPath = "dkck232.dll";			/* Datakey/iKey (NB: buggy, use 201) */
	const char *driverPath = "c:/program files/eracom/cprov sw/cryptoki.dll";	/* Eracom (old, OK) */
	const char *driverPath = "c:/program files/eracom/cprov runtime/cryptoki.dll";	/* Eracom (new, doesn't work) */
	const char *driverPath = "sadaptor.dll";		/* Eutron */
	const char *driverPath = "ngp11v211.dll";		/* Feitian Technology */
	const char *driverPath = "pk2priv.dll";			/* Gemplus */
	const char *driverPath = "c:/program files/gemplus/gclib.dll";	/* Gemplus */
	const char *driverPath = "cryptoki.dll";		/* IBM */
	const char *driverPath = "csspkcs11.dll";		/* IBM */
	const char *driverPath = "ibmpkcss.dll";		/* IBM */
	const char *driverPath = "id2cbox.dll";			/* ID2 */
	const char *driverPath = "cknfast.dll";			/* nCipher */
	const char *driverPath = "/opt/nfast/toolkits/pkcs11/libcknfast.so";/* nCipher under Unix */
	const char *driverPath = "/usr/lib/libcknfast.so";	/* nCipher under Unix */
	const char *driverPath = "c:/program files/mozilla firefox/softokn3.dll";/* Netscape */
	const char *driverPath = "nxpkcs11.dll";		/* Nexus */
	const char *driverPath = "AuCryptoki2-0.dll";	/* Oberthur */
	const char *driverPath = "opensc-pkcs11.dll";	/* OpenSC */
	const char *driverPath = "micardoPKCS11.dll";	/* Orga Micardo */
	const char *driverPath = "cryptoki22.dll";		/* Rainbow HSM (for USB use Datakey dvr) */
	const char *driverPath = "p11card.dll";			/* Safelayer HSM (for USB use Datakey dvr) */
	const char *driverPath = "slbck.dll";			/* Schlumberger */
	const char *driverPath = "SetTokI.dll";			/* SeTec */
	const char *driverPath = "siecap11.dll";		/* Siemens */
	const char *driverPath = "smartp11.dll";		/* SmartTrust */
	const char *driverPath = "SpyPK11.dll";			/* Spyrus */
#endif /* 0 */
	const char *driverPath = "c:/program files/eracom/cprov sw/cryptoki.dll";	/* Eracom (old, OK) */
	int status;

	printf( "Updating cryptlib configuration to load PKCS #11 driver\n  "
			"'%s'\n  as default driver...", driverPath );

	/* Set the path for a PKCS #11 device driver.  We only enable one of
	   these at a time to speed the startup time */
	status = cryptSetAttributeString( CRYPT_UNUSED, 
									  CRYPT_OPTION_DEVICE_PKCS11_DVR01,
									  driverPath, strlen( driverPath ) );
	if( cryptStatusError( status ) )
		{
		printf( "\n\nError updating PKCS #11 device driver profile, "
				"status %d.\n", status );
		cleanupAndExit( EXIT_FAILURE );
		}

	/* Flush the updated options to disk */
	status = cryptSetAttribute( CRYPT_UNUSED, CRYPT_OPTION_CONFIGCHANGED, 
								FALSE );
	if( cryptStatusError( status ) )
		{
		printf( "\n\nError comitting device driver profile update to disk, "
				"status %d.\n", status );
		cleanupAndExit( EXIT_FAILURE );
		}

	puts( " done.\n" );
	cleanupAndExit( EXIT_SUCCESS );
	}
Пример #13
0
int
main(int argc, char **argv)
{
    int status;
    int c;
    rsComm_t rsComm;
    int runMode = IRODS_SERVER;
    int flagval = 0;
    char *logDir = NULL;
    char *tmpStr;
    int logFd;
    char *ruleExecId = NULL;
    int jobType = 0;

    ProcessType = RE_SERVER_PT;

#ifdef RUN_SERVER_AS_ROOT
#ifndef windows_platform
    if (initServiceUser() < 0) {
        exit (1);
    }
#endif
#endif

#ifndef _WIN32
    signal(SIGINT, signalExit);
    signal(SIGHUP, signalExit);
    signal(SIGTERM, signalExit);
    signal(SIGUSR1, signalExit);
    signal(SIGPIPE, rsPipSigalHandler);
    /* XXXXX switched to SIG_DFL for embedded python. child process 
     * went away. But probably have to call waitpid. 
     * signal(SIGCHLD, SIG_IGN); */
    signal(SIGCHLD, SIG_DFL);
#endif

    /* Handle option to log sql commands */
    tmpStr = getenv (SP_LOG_SQL);
    if (tmpStr != NULL) {
#ifdef IRODS_SYSLOG
       int j = atoi(tmpStr);
       rodsLogSqlReq(j);
#else
       rodsLogSqlReq(1);
#endif
    }

    /* Set the logging level */
    tmpStr = getenv (SP_LOG_LEVEL);
    if (tmpStr != NULL) {
       int i;
       i = atoi(tmpStr);
       rodsLogLevel(i);
    } else {
         rodsLogLevel(LOG_NOTICE); /* default */
    }

#ifdef IRODS_SYSLOG
/* Open a connection to syslog */
    openlog("rodsReServer",LOG_ODELAY|LOG_PID,LOG_DAEMON);
#endif

    while ((c=getopt(argc, argv,"sSvD:j:t:")) != EOF) {
        switch (c) {
	    case 's':
		runMode = SINGLE_PASS;
		break;
	    case 'S':
		runMode = STANDALONE_SERVER;
		break;
            case 'v':   /* verbose */
                flagval |= v_FLAG;
                break;
            case 'D':   /* user specified a log directory */
		logDir = strdup (optarg);
		break;
	    case 'j':
		runMode = SINGLE_PASS;
		ruleExecId = strdup (optarg);
		break;
            case 't':
                jobType = atoi (optarg);
                break;
            default:
                usage (argv[0]);
                exit (1);
        }
    }

    status = initRsComm (&rsComm);

    if (status < 0) {
        cleanupAndExit (status);
    }

    if ((logFd = logFileOpen (runMode, logDir, RULE_EXEC_LOGFILE)) < 0) {
        exit (1);
    }

    daemonize (runMode, logFd);

#ifdef RULE_ENGINE_N
    status = initAgent (RULE_ENGINE_INIT_CACHE, &rsComm);
#else
    status = initAgent (&rsComm);
#endif
    if (status < 0) {
        cleanupAndExit (status);
    }

    if (ruleExecId != NULL) {
	status = reServerSingleExec (&rsComm, ruleExecId, jobType);
	if (status >= 0) {
            exit (0);
        } else {
             exit (1);
        }
    } else {
        reServerMain (&rsComm);
    }
    cleanupAndExit (status);

    exit (0);
}
Пример #14
0
int
getFrameSync (dsd_opts * opts, dsd_state * state)
{
  /* detects frame sync and returns frame type
   *  0 = +P25p1
   *  1 = -P25p1
   *  2 = +X2-TDMA (non inverted signal data frame)
   *  3 = -X2-TDMA (inverted signal data frame)
   *  4 = +DMR (non inverted signal data frame)
   *  5 = -DMR (inverted signal data frame)
   *  6 = +NXDN (non inverted data frame)
   *  7 = -NXDN (inverted data frame)
   *  8 = +D-STAR
   *  9 = -D-STAR
   * 10 = +D-STAR_HD
   * 11 = -D-STAR_HD
   * 12 = +DMR (non inverted signal voice frame)
   * 13 = -DMR (inverted signal voice frame)
   * 14 = +X2-TDMA (non inverted signal voice frame)
   * 15 = -X2-TDMA (inverted signal voice frame)
   * 16 = +NXDN (non inverted voice frame)
   * 17 = -NXDN (inverted voice frame)
   */

  int i, t, dibit, sync, symbol, synctest_pos, lastt;
  char synctest[25];
  char *synctest_p;
  char synctest_buf[10240];
  int lmin, lmax, lidx;
  int lbuf[24], lbuf2[24];

  for (i = 18; i < 24; i++) {
      lbuf[i] = 0;
      lbuf2[i] = 0;
  }

  // detect frame sync
  t = 0;
  synctest[24] = 0;
  synctest_pos = 0;
  synctest_p = synctest_buf;
  sync = 0;
  lmin = 0;
  lmax = 0;
  lidx = 0;
  lastt = 0;

  while (sync == 0) {
      t++;
      symbol = getSymbol (opts, state, 0);

      lbuf[lidx] = symbol;
      state->sbuf[state->sidx] = symbol;
      if (lidx == 23) {
          lidx = 0;
      } else {
          lidx++;
      }

      if (state->sidx == (state->ssize - 1)) {
          state->sidx = 0;
      } else {
          state->sidx++;
      }

      if (lastt == 23) {
          lastt = 0;
          state->rf_mod = 2;
      } else {
          lastt++;
      }

      //determine dibit state
      if (symbol > 0) {
          dibit = 49;               // '1'
      } else {
          dibit = 51;               // '3'
      }

      *synctest_p = dibit;
      if (t >= 18) {
          for (i = 0; i < 24; i++) {
              lbuf2[i] = lbuf[i];
          }

          Shellsort_int (lbuf2, 24);
          lmin = (lbuf2[2] + lbuf2[3] + lbuf2[4]) / 3;
          lmax = (lbuf2[21] + lbuf2[20] + lbuf2[19]) / 3;
          if (opts->datascope && (lidx == 0)) {
            print_datascope(state, lbuf2, 24);
          }

          memcpy (synctest, (synctest_p - 23), 24);

          if ((memcmp (synctest, P25P1_SYNC, 24) == 0) || (memcmp (synctest, INV_P25P1_SYNC, 24) == 0)) {
            state->offset = synctest_pos;
            strcpy (state->ftype, "P25p1");
            if (synctest[0] == '1') {
                state->lastsynctype = 0;
            } else {
                state->lastsynctype = 1;
            }
            goto update_sync_and_return;
          }

          if ((memcmp (synctest, DMR_MS_DATA_SYNC, 24) == 0) || (memcmp (synctest, DMR_BS_DATA_SYNC, 24) == 0)) {
            state->offset = synctest_pos;
            state->dmrMsMode = (synctest[22] == '1');
            strcpy (state->ftype, "DMR  ");
            if (opts->inverted_dmr == 0) {
                // data frame
                if (state->lastsynctype != 4) {
                    state->firstframe = 1;
                }
                state->lastsynctype = 4;
            } else {
                // inverted voice frame
                if (state->lastsynctype != 13) {
                    state->firstframe = 1;
                }
                state->lastsynctype = 13;
            }
            goto update_sync_and_return;
          }

          if ((memcmp (synctest, DMR_MS_VOICE_SYNC, 24) == 0) || (memcmp (synctest, DMR_BS_VOICE_SYNC, 24) == 0)) {
            state->offset = synctest_pos;
            state->dmrMsMode = (synctest[22] == '3');
            strcpy (state->ftype, "DMR  ");
            if (opts->inverted_dmr == 0) {
                // voice frame
                if (state->lastsynctype != 12) {
                   state->firstframe = 1;
                }
                state->lastsynctype = 12;
            } else {
                // inverted data frame
                if (state->lastsynctype != 5) {
                    state->firstframe = 1;
                }
                state->lastsynctype = 5;
            }
            goto update_sync_and_return;
          }

          if ((memcmp (synctest, X2TDMA_BS_DATA_SYNC, 24) == 0) || (memcmp (synctest, X2TDMA_MS_DATA_SYNC, 24) == 0)) {
            state->offset = synctest_pos;
            state->dmrMsMode = (synctest[22] == '1');
            strcpy (state->ftype, "X2-TDMA ");
            if (opts->inverted_x2tdma == 0) {
                // data frame
                state->lastsynctype = 2;
            } else {
                // inverted voice frame
                if (state->lastsynctype != 15) {
                   state->firstframe = 1;
                }
                state->lastsynctype = 15;
            }
            goto update_sync_and_return;
          }

          if ((memcmp (synctest, X2TDMA_BS_VOICE_SYNC, 24) == 0) || (memcmp (synctest, X2TDMA_MS_VOICE_SYNC, 24) == 0)) {
            state->offset = synctest_pos;
            state->dmrMsMode = (synctest[22] == '3');
            strcpy (state->ftype, "X2-TDMA ");
            if (opts->inverted_x2tdma == 0) {
                // voice frame
                if (state->lastsynctype != 14) {
                   state->firstframe = 1;
                }
                state->lastsynctype = 14;
            } else {
                // inverted data frame
                state->lastsynctype = 3;
            }
            goto update_sync_and_return;
          }

          if ((memcmp (synctest+6, NXDN_BS_VOICE_SYNC, 18) == 0) ||
              (memcmp (synctest+6, NXDN_MS_VOICE_SYNC, 18) == 0) ||
              (memcmp (synctest+6, NXDN_BS_DATA_SYNC, 18) == 0)  ||
              (memcmp (synctest+6, NXDN_MS_DATA_SYNC, 18) == 0)) {
              if (synctest[21] == '1') {
                  state->lastsynctype = 6;
              } else {
                  state->lastsynctype = 16;
              }
              if ((state->lastsynctype == 6) || (state->lastsynctype == 16)) {
                  state->offset = synctest_pos;
                  strcpy (state->ftype, "NXDN96  ");
                  goto update_sync_and_return;
              }
          }
          if ((memcmp (synctest+6, INV_NXDN_BS_VOICE_SYNC, 18) == 0) || 
              (memcmp (synctest+6, INV_NXDN_MS_VOICE_SYNC, 18) == 0) ||
              (memcmp (synctest+6, INV_NXDN_BS_DATA_SYNC, 18) == 0) ||
              (memcmp (synctest+6, INV_NXDN_MS_DATA_SYNC, 18) == 0)) {
              if (synctest[21] == '3') {
                  state->lastsynctype = 7;
              } else {
                  state->lastsynctype = 17;
              }
              if ((state->lastsynctype == 7) || (state->lastsynctype == 17)) {
                  state->offset = synctest_pos;
                  strcpy (state->ftype, "NXDN96  ");
                  goto update_sync_and_return;
              }
          }

          if ((memcmp (synctest, DSTAR_SYNC, 24) == 0) || (memcmp (synctest, INV_DSTAR_SYNC, 24) == 0)) {
            state->offset = synctest_pos;
            strcpy (state->ftype, "D-STAR  ");
            if (synctest[0] == '3') {
                state->lastsynctype = 8;
            } else {
                state->lastsynctype = 9;
            }
            goto update_sync_and_return;
          }
          if ((memcmp (synctest, DSTAR_HD_SYNC, 24) == 0) || (memcmp (synctest, INV_DSTAR_HD_SYNC, 24) == 0)) {
            state->offset = synctest_pos;
            strcpy (state->ftype, "D-STARHD");
            if (synctest[0] == '1') {
                state->lastsynctype = 10;
            } else {
                state->lastsynctype = 11;
            }
            goto update_sync_and_return;
          }
      }

      if (exitflag == 1) {
          cleanupAndExit (opts, state);
      }

      if (synctest_pos < 10200) {
          synctest_pos++;
          synctest_p++;
      } else {
          // buffer reset
          synctest_pos = 0;
          synctest_p = synctest_buf;
          state->lastsynctype = -1;
      }

      if (state->lastsynctype != -1) {
          //if (synctest_pos >= 1800) {
          if (synctest_pos >= 9000) {
              if ((state->lastsynctype != -1) && !(opts->datascope)) {
                  printf ("Sync: no sync\n");
              }
              state->lastsynctype = -1;
#if 1
              state->max = 3000;
              state->min = -3000;
              state->umid = 1000;
              state->lmid = -1000;
              state->center = 0;
#endif
              return (-1);
          }
      }
  }

  return (-1);

update_sync_and_return:
   // recalibrate center/umid/lmid
   state->max = ((state->max) + (lmax)) / 2;
   state->min = ((state->min) + (lmin)) / 2;
   state->center = ((state->max) + (state->min)) / 2;
   state->umid = (((state->max) - state->center) * 5 / 8) + state->center;
   state->lmid = (((state->min) - state->center) * 5 / 8) + state->center;
   return state->lastsynctype;
}
Пример #15
0
/* #define SERVER_DEBUG 1   */
int
main( int, char ** ) {

    int status;
    rsComm_t rsComm;
    char *tmpStr;

    ProcessType = AGENT_PT;

    // capture server properties
    irods::server_properties& props = irods::server_properties::getInstance();
    irods::error result = props.capture_if_needed();
    if ( !result.ok() ) {
        irods::log( PASSMSG( "failed to read server configuration", result ) );
    }

#ifdef windows_platform
    iRODSNtAgentInit( argc, argv );
#endif

#ifndef windows_platform
    signal( SIGINT, signalExit );
    signal( SIGHUP, signalExit );
    signal( SIGTERM, signalExit );
    /* set to SIG_DFL as recommended by andy.salnikov so that system()
     * call returns real values instead of 1 */
    signal( SIGCHLD, SIG_DFL );
    signal( SIGUSR1, signalExit );
    signal( SIGPIPE, SIG_IGN );

    // register irods signal handlers
    register_handlers();
#endif

#ifndef windows_platform
#ifdef SERVER_DEBUG
    if ( isPath( "/tmp/rodsdebug" ) ) {
        sleep( 20 );
    }
#endif
#endif

    memset( &rsComm, 0, sizeof( rsComm ) );
    rsComm.thread_ctx = ( thread_context* )malloc( sizeof( thread_context ) );

    status = initRsCommWithStartupPack( &rsComm, NULL );

    // =-=-=-=-=-=-=-
    // manufacture a network object for comms
    irods::network_object_ptr net_obj;
    irods::error ret = irods::network_factory( &rsComm, net_obj );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
    }

    if ( status < 0 ) {
        sendVersion( net_obj, status, 0, NULL, 0 );
        cleanupAndExit( status );
    }

    /* Handle option to log sql commands */
    tmpStr = getenv( SP_LOG_SQL );
    if ( tmpStr != NULL ) {
#ifdef SYSLOG
        int j = atoi( tmpStr );
        rodsLogSqlReq( j );
#else
        rodsLogSqlReq( 1 );
#endif
    }

    /* Set the logging level */
    tmpStr = getenv( SP_LOG_LEVEL );
    if ( tmpStr != NULL ) {
        int i;
        i = atoi( tmpStr );
        rodsLogLevel( i );
    }
    else {
        rodsLogLevel( LOG_NOTICE ); /* default */
    }

#ifdef SYSLOG
    /* Open a connection to syslog */
    openlog( "rodsAgent", LOG_ODELAY | LOG_PID, LOG_DAEMON );
#endif
    status = getRodsEnv( &rsComm.myEnv );

    if ( status < 0 ) {
        rodsLog( LOG_ERROR, "agentMain :: getRodsEnv failed" );
        sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 );
        cleanupAndExit( status );
    }

    ret = setRECacheSaltFromEnv();
    if ( !ret.ok() ) {
        rodsLog( LOG_ERROR, "rodsAgent::main: Failed to set RE cache mutex name\n%s", ret.result().c_str() );
        exit( 1 );
    }

    // =-=-=-=-=-=-=-
    // load server side pluggable api entries
    irods::api_entry_table&  RsApiTable   = irods::get_server_api_table();
    irods::pack_entry_table& ApiPackTable = irods::get_pack_table();
    ret = irods::init_api_table(
              RsApiTable,
              ApiPackTable,
              false );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        return 1;
    }

    // =-=-=-=-=-=-=-
    // load client side pluggable api entries
    irods::api_entry_table&  RcApiTable = irods::get_client_api_table();
    ret = irods::init_api_table(
              RcApiTable,
              ApiPackTable,
              true );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        return 1;
    }




#if RODS_CAT
    if ( strstr( rsComm.myEnv.rodsDebug, "CAT" ) != NULL ) {
        chlDebug( rsComm.myEnv.rodsDebug );
    }
#endif

    status = initAgent( RULE_ENGINE_TRY_CACHE, &rsComm );

    if ( status < 0 ) {
        rodsLog( LOG_ERROR, "agentMain :: initAgent failed: %d", status );
        sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 );
        cleanupAndExit( status );
    }

    /* move configConnectControl behind initAgent for now. need zoneName if
     * the user does not specify one in the input */
    initConnectControl();

    if ( rsComm.clientUser.userName[0] != '\0' ) {
        status = chkAllowedUser( rsComm.clientUser.userName,
                                 rsComm.clientUser.rodsZone );

        if ( status < 0 ) {
            sendVersion( net_obj, status, 0, NULL, 0 );
            cleanupAndExit( status );
        }
    }

    // =-=-=-=-=-=-=-
    // handle negotiations with the client regarding TLS if requested
    // this scope block makes valgrind happy
    {
        std::string neg_results;
        ret = irods::client_server_negotiation_for_server( net_obj, neg_results );
        if ( !ret.ok() || neg_results == irods::CS_NEG_FAILURE ) {
            irods::log( PASS( ret ) );
            // =-=-=-=-=-=-=-
            // send a 'we failed to negotiate' message here??
            // or use the error stack rule engine thingie
            irods::log( PASS( ret ) );
            sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 );
            cleanupAndExit( ret.code() );

        }
        else {
            // =-=-=-=-=-=-=-
            // copy negotiation results to comm for action by network objects
            snprintf( rsComm.negotiation_results, sizeof( rsComm.negotiation_results ), "%s", neg_results.c_str() );
            //rsComm.ssl_do_accept = 1;

        }
    }

    /* send the server version and atatus as part of the protocol. Put
     * rsComm.reconnPort as the status */
    ret = sendVersion( net_obj, status, rsComm.reconnPort,
                       rsComm.reconnAddr, rsComm.cookie );

    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 );
        cleanupAndExit( status );
    }

    logAgentProc( &rsComm );

    // call initialization for network plugin as negotiated
    irods::network_object_ptr new_net_obj;
    ret = irods::network_factory( &rsComm, new_net_obj );
    if ( !ret.ok() ) {
        return ret.code();
    }

    ret = sockAgentStart( new_net_obj );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        return ret.code();
    }

    new_net_obj->to_server( &rsComm );
    status = agentMain( &rsComm );

    // call initialization for network plugin as negotiated
    ret = sockAgentStop( new_net_obj );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        return ret.code();
    }

    new_net_obj->to_server( &rsComm );
    cleanup();
    free( rsComm.thread_ctx );
    free( rsComm.auth_scheme );
    rodsLog( LOG_NOTICE, "Agent exiting with status = %d", status );
    return status;
}
Пример #16
0
int
getSymbol (dsd_opts * opts, dsd_state * state, int have_sync)
{
  short sample;
  int i, sum, symbol, count;
  ssize_t result;

  sum = 0;
  count = 0;
  for (i = 0; i < state->samplesPerSymbol; i++)
    {
      // timing control
      if ((i == 0) && (have_sync == 0))
        {
          if (state->samplesPerSymbol == 20)
            {
              if ((state->jitter >= 7) && (state->jitter <= 10))
                {
                  i--;
                }
              else if ((state->jitter >= 11) && (state->jitter <= 14))
                {
                  i++;
                }
            }
          else if (state->rf_mod == 1)
            {
              if ((state->jitter >= 0) && (state->jitter < state->symbolCenter))
                {
                  i++;          // fall back
                }
              else if ((state->jitter > state->symbolCenter) && (state->jitter < 10))
                {
                  i--;          // catch up
                }
            }
          else if (state->rf_mod == 2)
            {
              if ((state->jitter >= state->symbolCenter - 1) && (state->jitter <= state->symbolCenter))
                {
                  i--;
                }
              else if ((state->jitter >= state->symbolCenter + 1) && (state->jitter <= state->symbolCenter + 2))
                {
                  i++;
                }
            }
          else if (state->rf_mod == 0)
            {
              if ((state->jitter > 0) && (state->jitter <= state->symbolCenter))
                {
                  i--;          // catch up
                }
              else if ((state->jitter > state->symbolCenter) && (state->jitter < state->samplesPerSymbol))
                {
                  i++;          // fall back
                }
            }
          state->jitter = -1;
        }

      // Read the new sample from the input
      if(opts->audio_in_type == 0) {
          if (opts->audio_in_fd == -1)
            {
              while (state->input_length == 0)
                {
                  // If the buffer is empty, wait for more samples to arrive.
                  if (pthread_cond_wait(&state->input_ready, &state->input_mutex))
                    {
                      printf("getSymbol -> Error waiting for condition\n");
                    }
                }
              // Get the next sample from the buffer, converting from float to short.
              sample = (short) (state->input_samples[state->input_offset++] * 32768);
              if (state->input_offset == state->input_length)
                {
                  int i;

                  // We've reached the end of the buffer.  Wait for more next time.
                  state->input_length = 0;

                  if (pthread_mutex_lock(&state->output_mutex))
                    {
                      printf("Unable to lock mutex\n");
                    }

                  state->output_num_samples = state->output_offset;
                  if (state->output_num_samples > state->output_length) {
                    state->output_num_samples = state->output_length;
                  }
                  for (i = 0; i < state->output_length - state->output_num_samples; i++)
                    {
                      state->output_samples[i] = 0;
                    }
                  for (; i < state->output_length; i++)
                    {
                      state->output_samples[i] = state->output_buffer[i - (state->output_length - state->output_num_samples)] / 32768.0;
                    }
                  state->output_offset -= state->output_num_samples;
                  for (i = 0; i < state->output_offset; i++)
                    {
                      state->output_buffer[i] = state->output_buffer[i + state->output_num_samples];
                    }
                  state->output_finished = 1;

                  // Wake up general_work
                  if (pthread_cond_signal(&state->output_ready))
                    {
                      printf("Unable to signal\n");
                    }

                  if (pthread_mutex_unlock(&state->output_mutex))
                    {
                      printf("Unable to unlock mutex\n");
                    }
                }
            }
          else
            {
              result = read (opts->audio_in_fd, &sample, 2);
            }
      }
      else if (opts->audio_in_type == 1) {
          result = sf_read_short(opts->audio_in_file, &sample, 1);
          if(result == 0) {
              cleanupAndExit (opts, state);
          }
      }
	  else
	  {
#ifdef USE_PORTAUDIO
		PaError err = Pa_ReadStream( opts->audio_in_pa_stream, &sample, 1 );
		if( err != paNoError )
		{
    			fprintf( stderr, "An error occured while using the portaudio input stream\n" );
    			fprintf( stderr, "Error number: %d\n", err );
    			fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
		}
#endif
	  }

#ifdef TRACE_DSD
      state->debug_sample_index++;
#endif

      // printf("res: %zd\n, offset: %lld", result, sf_seek(opts->audio_in_file, 0, SEEK_CUR));
      if (opts->use_cosine_filter)
        {
          if (state->lastsynctype >= 10 && state->lastsynctype <= 13)
              sample = dmr_filter(sample);
          else if (state->lastsynctype == 8 || state->lastsynctype == 9 ||
                 state->lastsynctype == 16 || state->lastsynctype == 17)
            {
              if(state->samplesPerSymbol == 20)
                {
                  sample = nxdn_filter(sample);
                }
              else // the 12.5KHz NXDN filter is the same as the DMR filter
                {
                  sample = dmr_filter(sample);
                }
            }
        }

      if ((sample > state->max) && (have_sync == 1) && (state->rf_mod == 0))
        {
          sample = state->max;
        }
      else if ((sample < state->min) && (have_sync == 1) && (state->rf_mod == 0))
        {
          sample = state->min;
        }

      if (sample > state->center)
        {
          if (state->lastsample < state->center)
            {
              state->numflips += 1;
            }
          if (sample > (state->maxref * 1.25))
            {
              if (state->lastsample < (state->maxref * 1.25))
                {
                  state->numflips += 1;
                }
              if ((state->jitter < 0) && (state->rf_mod == 1))
                {               // first spike out of place
                  state->jitter = i;
                }
              if ((opts->symboltiming == 1) && (have_sync == 0) && (state->lastsynctype != -1))
                {
                  printf ("O");
                }
            }
          else
            {
              if ((opts->symboltiming == 1) && (have_sync == 0) && (state->lastsynctype != -1))
                {
                  printf ("+");
                }
              if ((state->jitter < 0) && (state->lastsample < state->center) && (state->rf_mod != 1))
                {               // first transition edge
                  state->jitter = i;
                }
            }
        }
      else
        {                       // sample < 0
          if (state->lastsample > state->center)
            {
              state->numflips += 1;
            }
          if (sample < (state->minref * 1.25))
            {
              if (state->lastsample > (state->minref * 1.25))
                {
                  state->numflips += 1;
                }
              if ((state->jitter < 0) && (state->rf_mod == 1))
                {               // first spike out of place
                  state->jitter = i;
                }
              if ((opts->symboltiming == 1) && (have_sync == 0) && (state->lastsynctype != -1))
                {
                  printf ("X");
                }
            }
          else
            {
              if ((opts->symboltiming == 1) && (have_sync == 0) && (state->lastsynctype != -1))
                {
                  printf ("-");
                }
              if ((state->jitter < 0) && (state->lastsample > state->center) && (state->rf_mod != 1))
                {               // first transition edge
                  state->jitter = i;
                }
            }
        }
      if (state->samplesPerSymbol == 20)
        {
          if ((i >= 9) && (i <= 11))
            {
              sum += sample;
              count++;
            }
        }
      if (state->samplesPerSymbol == 5)
        {
          if (i == 2)
            {
              sum += sample;
              count++;
            }
        }
      else
        {
          if (state->rf_mod == 0)
            {
              // 0: C4FM modulation

              if ((i >= state->symbolCenter - 1) && (i <= state->symbolCenter + 2))
                {
                  sum += sample;
                  count++;
                }

#ifdef TRACE_DSD
              if (i == state->symbolCenter - 1) {
                  state->debug_sample_left_edge = state->debug_sample_index - 1;
              }
              if (i == state->symbolCenter + 2) {
                  state->debug_sample_right_edge = state->debug_sample_index - 1;
              }
#endif
            }
          else
            {
              // 1: QPSK modulation
              // 2: GFSK modulation
              // Note: this has been changed to use an additional symbol to the left
              // On the p25_raw_unencrypted.flac it is evident that the timing
              // comes one sample too late.
              // This change makes a significant improvement in the BER, at least for
              // this file.
              //if ((i == state->symbolCenter) || (i == state->symbolCenter + 1))
              if ((i == state->symbolCenter - 1) || (i == state->symbolCenter + 1))
                {
                  sum += sample;
                  count++;
                }

#ifdef TRACE_DSD
              //if (i == state->symbolCenter) {
              if (i == state->symbolCenter - 1) {
                  state->debug_sample_left_edge = state->debug_sample_index - 1;
              }
              if (i == state->symbolCenter + 1) {
                  state->debug_sample_right_edge = state->debug_sample_index - 1;
              }
#endif
            }
        }


      state->lastsample = sample;
    }   // for

  symbol = (sum / count);

  if ((opts->symboltiming == 1) && (have_sync == 0) && (state->lastsynctype != -1))
    {
      if (state->jitter >= 0)
        {
          printf (" %i\n", state->jitter);
        }
      else
        {
          printf ("\n");
        }
    }

#ifdef TRACE_DSD
  if (state->samplesPerSymbol == 10) {
      float left, right;
      if (state->debug_label_file == NULL) {
          state->debug_label_file = fopen ("pp_label.txt", "w");
      }
      left = state->debug_sample_left_edge / SAMPLE_RATE_IN;
      right = state->debug_sample_right_edge / SAMPLE_RATE_IN;
      if (state->debug_prefix != '\0') {
          if (state->debug_prefix == 'I') {
              fprintf(state->debug_label_file, "%f\t%f\t%c%c %i\n", left, right, state->debug_prefix, state->debug_prefix_2, symbol);
          } else {
              fprintf(state->debug_label_file, "%f\t%f\t%c %i\n", left, right, state->debug_prefix, symbol);
          }
      } else {
          fprintf(state->debug_label_file, "%f\t%f\t%i\n", left, right, symbol);
      }
  }
#endif


  state->symbolcnt++;
  return (symbol);
}