Esempio n. 1
0
int
get_psk_key(struct dtls_context_t *ctx, 
	    const session_t *session, 
	    const unsigned char *id, size_t id_len, 
	    const dtls_psk_key_t **result) {

  static const dtls_psk_key_t psk = {
    .id = (unsigned char *)"Client_identity", 
    .id_length = 15,
    .key = (unsigned char *)"secretPSK", 
    .key_length = 9
  };

  *result = &psk;
  return 0;
}

PROCESS(udp_server_process, "UDP server process");
AUTOSTART_PROCESSES(&udp_server_process);
/*---------------------------------------------------------------------------*/
static void
dtls_handle_read(dtls_context_t *ctx) {
  session_t session;

  if(uip_newdata()) {
    uip_ipaddr_copy(&session.addr, &UIP_IP_BUF->srcipaddr);
    session.port = UIP_UDP_BUF->srcport;
    session.size = sizeof(session.addr) + sizeof(session.port);
    
    dtls_handle_message(ctx, &session, uip_appdata, uip_datalen());
  }
}
Esempio n. 2
0
/*
 * sysc_io_allow(dest, flags)
 *
 * (Implementation of the "io_allow" system call)
 *
 * Allows a thread to access on a certain I/O resource
 * managed by the kernel. This system call may be only
 * called by root processes.
 *
 * Parameters:
 *	dest	SID of the affected process
 *	flags	The I/O operations that should be allowed:
 *			IO_ALLOW_IRQ	Allow the handling of IRQs
 *			IO_ALLOW_PORTS	Allow the access on the I/O-Ports
 *
 */
void sysc_io_allow(sid_t dest, unsigned flags)
{
	/* Is the current process a root process? */
	if (!current_p[PRCTAB_IS_ROOT])
	{
		SET_ERROR(ERR_NOT_ROOT);
		return;
	}
	
	/* Does the destination SID define a valid process? */
	if (!kinfo_isproc(dest))
	{
		SET_ERROR(ERR_INVALID_SID);
		return;
	}
	
	/* Proceed only, if the flags are valid */
	if (    (flags & IO_ALLOW_IRQ)
	     || (flags & IO_ALLOW_PORTS)
	   )
	{
		/* Add the flags */
		PROCESS(dest, PRCTAB_IO_ACCESS_RIGHTS) |= flags;
		
		return;
	}
	
	/* Invalid flags */
	SET_ERROR(ERR_INVALID_ARGUMENT);
	return;
}
Esempio n. 3
0
int main (int argc, char *argv[])
{
  UI.DisplayHeader (HEADER1 NAME);
  COMMAND command (argc, argv);    // Распарсить команду
  if (command.ok)                  // Если парсинг был удачен и можно выполнить команду
    PROCESS (&command, &UI);       //   Выполнить разобранную команду
  printf (command.ok? (command.list_cmd()? "" : "All OK\n") : "Error(s) found\n");
  return command.ok? EXIT_SUCCESS : FREEARC_EXIT_ERROR;
}
Esempio n. 4
0
int
get_key(struct dtls_context_t *ctx, 
	const session_t *session, 
	const unsigned char *id, size_t id_len, 
	const dtls_key_t **result) {

  static const dtls_key_t psk = {
    .type = DTLS_KEY_PSK,
    .key.psk.id = (unsigned char *)"Client_identity", 
    .key.psk.id_length = 15,
    .key.psk.key = (unsigned char *)"secretPSK", 
    .key.psk.key_length = 9
  };
   
  *result = &psk;
  return 0;
}

PROCESS(udp_server_process, "UDP server process");
AUTOSTART_PROCESSES(&udp_server_process);
/*---------------------------------------------------------------------------*/
static void
dtls_handle_read(dtls_context_t *ctx) {
  static session_t session;

  if(uip_newdata()) {
    uip_ipaddr_copy(&session.addr, &UIP_IP_BUF->srcipaddr);
    session.port = UIP_UDP_BUF->srcport;
    session.size = sizeof(session.addr) + sizeof(session.port);

    ((char *)uip_appdata)[uip_datalen()] = 0;
    PRINTF("Client received message from ");
    PRINT6ADDR(&session.addr);
    PRINTF(":%d\n", uip_ntohs(session.port));

    dtls_handle_message(ctx, &session, uip_appdata, uip_datalen());
  }
}
/*---------------------------------------------------------------------------*/
static void
print_local_addresses(void)
{
  int i;
  uint8_t state;

  PRINTF("Client IPv6 addresses: ");
  for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
    state = uip_ds6_if.addr_list[i].state;
    if(uip_ds6_if.addr_list[i].isused &&
       (state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
      PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
      PRINTF("\n");
    }
  }
}
Esempio n. 5
0
/*
 * sysc_chg_root(proc, op)
 *
 * (Implementation of the "chg_root" system call)
 *
 * Switches a process to root or non-root mode. This system
 * call is restricted to root-mode processes only. 
 *
 * Parameters:
 *	proc	SID of the affected
 *	op	The wanted operation:
 *			CHGROOT_LEAVE		0	Leave Root-Mode
 *			CHGROOT_ENTER		1	Enter Root-Mode
 *
 */
void sysc_chg_root(sid_t proc, int op)
{
	/* Only root processes are allowed to change the root state */
	if (current_p[PRCTAB_IS_ROOT] != 1)
	{
		SET_ERROR(ERR_ACCESS_DENIED);
		return;
	}

	/* Valid process SID? */
	if (!kinfo_isproc(proc))
	{
		SET_ERROR(ERR_INVALID_SID);
		return;
	}
	
	/* Valid operation type? */
	if ((op != CHGROOT_ENTER) && (op != CHGROOT_LEAVE))
	{
		return;
	}
	
	/* Set */
	PROCESS(proc, PRCTAB_IS_ROOT) = op;
	
	/* Set I/O access rights */
	if (op == CHGROOT_ENTER) 
	{
		/* Set rights */
		PROCESS(proc, PRCTAB_IO_ACCESS_RIGHTS) |=    IO_ALLOW_IRQ
							   | IO_ALLOW_PORTS;	
	}
	 else 
	{
		/* Remove rights */
		PROCESS(proc, PRCTAB_IO_ACCESS_RIGHTS) &= (~(   IO_ALLOW_IRQ
							      | IO_ALLOW_PORTS
							  ));
	}
						   
	return;
}
Esempio n. 6
0
  bool RT_process(int count, const FAUSTFLOAT* input0, FAUSTFLOAT* output0) {
    const int iSlow0 = iHslider0;

    const int anding = buffer_size-1;

    if (can_pipe_instead){

      // Must do this, even if there has been no delay earlier. If we don't do this, there will be clicks when turning on the delay.
      for(int i = 0 ; i < count ; i++){
        fVec0[(IOTA & anding)] = input0[i];
        IOTA++;
      }

      //   if (input0 != output0)
      //  memcpy(output0, input0, sizeof(float)*count);
      
      return false;
    }

#define M(N) } else if (buffer_size==N) { PROCESS((N-1))

    if (false) {
      return false;
    M(2);
    M(4);    
    M(8);
    M(16);
    M(32);
    M(64);
    M(128);
    M(256);
    M(512);
    M(1024);
    M(2048);
    M(4096);
    M(8192);
    M(16384);
    M(32768);
    M(65536);
    M(131072);
    M(262144);
    M(524288);
    } else
      PROCESS(anding);

    return true;
  }
Esempio n. 7
0
  void RT_process(int count, FAUSTFLOAT* input0, FAUSTFLOAT* output0) {
    const int iSlow0 = iHslider0;

    const int anding = buffer_size-1;
    
    if (can_pipe_instead){
      for(int i = 0 ; i < count ; i++){
        fVec0[(IOTA & anding)] = input0[i];
        IOTA++;
      }
      
      if (input0 != output0)
        memcpy(output0, input0, sizeof(float)*count);
      
      return;
    }

#define M(N) } else if (buffer_size==N) { PROCESS((N-1))

    if (false) {
      return;
    M(2);
    M(4);    
    M(8);
    M(16);
    M(32);
    M(64);
    M(128);
    M(256);
    M(512);
    M(1024);
    M(2048);
    M(4096);
    M(8192);
    M(16384);
    M(32768);
    M(65536);
    M(131072);
    M(262144);
    M(524288);
    } else
      PROCESS(anding);
  }
Esempio n. 8
0
/* Parameter functions named here as ssh pk group (standing for
   ssh public key group). Function to generate the pk group object. This
   is needed in the power up tests. Note that this does NOT perform the
   group consistency test (the function ssh_crypto_test_pk_group) */
SshCryptoStatus
ssh_pk_group_object_generate(SshPkGroupObject *group_ret,
                             const char *group_type, ...)
{

  SshCryptoStatus status;
  unsigned int i;
  const SshPkAction *action;
  SshPkGroupObject pk_group;
  void *context = NULL;
  SshPkFormat format;
  const char *name, *r;
  char consumed[128], *tmp;
  va_list ap;

  /* Get the key type (i.e. strip the scheme information from group_type). */
  if ((tmp = ssh_pk_get_key_type(group_type)) == NULL)
    return SSH_CRYPTO_NO_MEMORY;

  for (i = 0;
       ssh_pk_type_slots[i] != NULL && ssh_pk_type_slots[i]->name;
       i++)
    {
      if (strcmp(ssh_pk_type_slots[i]->name, tmp) != 0)
        continue;
      ssh_free(tmp);
      tmp = NULL;

      /* Type matches i.e. we've found our key type, so continue with
         finding schemes and parameters. */

      /* Allocate group context. */
      if ((pk_group = ssh_malloc(sizeof(*pk_group))) == NULL)
        return SSH_CRYPTO_NO_MEMORY;

      pk_group->type = ssh_pk_type_slots[i];
      pk_group->diffie_hellman = NULL;

      status = (*pk_group->type->pk_group_action_init)(&context);
      if (status != SSH_CRYPTO_OK)
        {
          ssh_free(pk_group);
          return status;
        }

      /* Run through all preselected schemes in the group_type. */
      status = ssh_pk_group_set_scheme_from_key_name(pk_group, group_type);

      if (status != SSH_CRYPTO_OK)
        {
          if (pk_group != NULL)
            {
              (*pk_group->type->pk_group_action_free)(context);
              ssh_free(pk_group);
            }
          return status;
        }

      /* Start reading the vararg list. */
      consumed[0] = '\000';
      while (TRUE)
        {
          va_start(ap, group_type);
          PROCESS(ap, consumed);

          format = va_arg(ap, SshPkFormat);
          strcat(consumed, "i");
          if (format == SSH_PKF_END)
            break;

          /* If the va list contains scheme parameters, we need to
             set the scheme again. */
          if (format == SSH_PKF_SIGN || format == SSH_PKF_ENCRYPT ||
              format == SSH_PKF_DH)
            {
              name = va_arg(ap, const char *);
              strcat(consumed, "p");
              status = ssh_pk_group_set_scheme(pk_group, format, name);

              if (status != SSH_CRYPTO_OK)
                {
                  (*pk_group->type->pk_group_action_free)(context);
                  ssh_free(pk_group);
                  va_end(ap);
                  return status;
                }
              va_end(ap);
              continue;
            }

          /* Search name from command lists. */
          action = ssh_pk_find_action(pk_group->type->action_list,
                                      format, SSH_PK_ACTION_FLAG_PK_GROUP);
          if (!action)
            {
              /* Free the action context. */
              (*pk_group->type->pk_group_action_free)(context);
              ssh_free(pk_group);
              va_end(ap);
              return SSH_CRYPTO_UNSUPPORTED_IDENTIFIER;
            }

          /* Supported only scheme selection and special operations. */
          switch (action->flags & SSH_PK_ACTION_FLAG_GET_PUT)
            {
            case SSH_PK_ACTION_FLAG_GET_PUT:
              r = (*action->action_put)(context, ap, NULL, format);

              if (r == NULL)
                {
                  (*pk_group->type->pk_group_action_free)(context);
                  ssh_free(pk_group);
                  va_end(ap);
                  return SSH_CRYPTO_INTERNAL_ERROR;
                }
              else
                strcat(consumed, r);
              break;
            default:
              ssh_fatal("ssh_pk_group_generate: internal error.");
              break;
            }
          va_end(ap);
        }

      /* Make the key and remove context. (One could incorporate making
         and freeing, however this way things seem to work also). */
      status =
        (*pk_group->type->pk_group_action_make)(context, &pk_group->context);
      (*pk_group->type->pk_group_action_free)(context);

      /* Quit unhappily. */
      if (status != SSH_CRYPTO_OK)
        {
          ssh_free(pk_group);
          va_end(ap);
          return status;
        }

      /* Set the address of the group into its context. */
      if (pk_group->type->set_key_pointer_to_context)
        {
          status =
            (*pk_group->type->set_key_pointer_to_context)(pk_group,
                                                          pk_group->context);
          if (status != SSH_CRYPTO_OK)
            {
              ssh_free(pk_group);
              va_end(ap);
              return status;
            }
        }

      /* Quit happily. */
      *group_ret = pk_group;
      va_end(ap);

      return SSH_CRYPTO_OK;
    }
Esempio n. 9
0
static int
trythisone(grouprec *group, int ne, int n)
{
    int i,k;
    boolean accept;
#ifdef PROCESS
    graph g[WORDSIZE];
#endif

    first = TRUE;

    ++gd_ngen;
    nix = ne;
    newgroupsize = 1;
    ntgroup = FALSE;

    if (!group || groupsize == 1)
        accept = TRUE;
    else if (lastrejok && !ismax(lastreject,n))
        accept = FALSE;
    else if (lastrejok && groupsize == 2)
        accept = TRUE;
    else
    {
        newgroupsize = 1;
        ntgroup = FALSE;
        if (allgroup2(group,testmax) == 0)
            accept = TRUE;
        else
            accept = FALSE;
    }

    if (accept)
    {

#ifdef GROUPTEST
        if (groupsize % newgroupsize != 0)
                        gt_abort("group size error\n");
        totallab += groupsize/newgroupsize;
#endif

        if (Vswitch && !ntisol && !ntgroup) return MAXNE+1;

        ++dg_nout;

#ifdef PROCESS
	EMPTYSET(g,n);
	for (i = -1; (i = nextelement(x,me,i)) >= 0; )
        {
            k = i >> 1;
            if (i & 1) g[v1[k]] |= bit[v0[k]];
            else       g[v0[k]] |= bit[v1[k]];
        }
	PROCESS(outfile,g,n);
#endif

        if (outfile)
        {
            fprintf(outfile,"%d %d",n,ne);
            if (Gswitch) fprintf(outfile," %lu",newgroupsize);
    
            for (i = -1; (i = nextelement(x,me,i)) >= 0; )
            {
                k = i >> 1;
                if (i & 1) fprintf(outfile," %d %d",v1[k],v0[k]);
                else       fprintf(outfile," %d %d",v0[k],v1[k]);
            }
            fprintf(outfile,"\n");
        }
        return MAXNE+1;
    }
    else
        return rejectlevel;
Esempio n. 10
0
void ColorBalanceEngine::run()
{
	while(1)
	{
		input_lock.lock("ColorBalanceEngine::run");
		if(last_frame)
		{
			output_lock.unlock();
			return;
		}

#define PROCESS(yuvtorgb,  \
	rgbtoyuv,  \
	r_lookup,  \
	g_lookup,  \
	b_lookup,  \
	type,  \
	max,  \
	components,  \
	do_yuv) \
{ \
	int i, j, k; \
	int y, cb, cr, r, g, b, r_n, g_n, b_n; \
    float h, s, v, h_old, s_old, r_f, g_f, b_f; \
	type **input_rows, **output_rows; \
	input_rows = (type**)input->get_rows(); \
	output_rows = (type**)output->get_rows(); \
 \
	for(j = row_start; j < row_end; j++) \
	{ \
		for(k = 0; k < input->get_w() * components; k += components) \
		{ \
			if(do_yuv) \
			{ \
				y = input_rows[j][k]; \
				cb = input_rows[j][k + 1]; \
				cr = input_rows[j][k + 2]; \
				yuvtorgb(r, g, b, y, cb, cr); \
			} \
			else \
			{ \
            	r = input_rows[j][k]; \
            	g = input_rows[j][k + 1]; \
            	b = input_rows[j][k + 2]; \
			} \
 \
            r = CLAMP(r, 0, max-1); g = CLAMP(g, 0, max-1); b = CLAMP(b, 0, max-1); \
            r_n = plugin->r_lookup[r]; \
            g_n = plugin->g_lookup[g]; \
            b_n = plugin->b_lookup[b]; \
 \
			if(plugin->config.preserve) \
            { \
				HSV::rgb_to_hsv((float)r_n, (float)g_n, (float)b_n, h, s, v); \
				HSV::rgb_to_hsv((float)r, (float)g, (float)b, h_old, s_old, v); \
                HSV::hsv_to_rgb(r_f, g_f, b_f, h, s, v); \
                r = (type)r_f; \
                g = (type)g_f; \
                b = (type)b_f; \
			} \
            else \
            { \
                r = r_n; \
                g = g_n; \
                b = b_n; \
			} \
 \
			if(do_yuv) \
			{ \
				rgbtoyuv(CLAMP(r, 0, max), CLAMP(g, 0, max), CLAMP(b, 0, max), y, cb, cr); \
                output_rows[j][k] = y; \
                output_rows[j][k + 1] = cb; \
                output_rows[j][k + 2] = cr; \
			} \
			else \
			{ \
                output_rows[j][k] = CLAMP(r, 0, max); \
                output_rows[j][k + 1] = CLAMP(g, 0, max); \
                output_rows[j][k + 2] = CLAMP(b, 0, max); \
			} \
		} \
	} \
}

#define PROCESS_F(components) \
{ \
	int i, j, k; \
	float y, cb, cr, r, g, b, r_n, g_n, b_n; \
    float h, s, v, h_old, s_old, r_f, g_f, b_f; \
	float **input_rows, **output_rows; \
	input_rows = (float**)input->get_rows(); \
	output_rows = (float**)output->get_rows(); \
	cyan_f = plugin->calculate_transfer(plugin->config.cyan); \
	magenta_f = plugin->calculate_transfer(plugin->config.magenta); \
	yellow_f = plugin->calculate_transfer(plugin->config.yellow); \
 \
	for(j = row_start; j < row_end; j++) \
	{ \
		for(k = 0; k < input->get_w() * components; k += components) \
		{ \
            r = input_rows[j][k]; \
            g = input_rows[j][k + 1]; \
            b = input_rows[j][k + 2]; \
 \
            r_n = r * cyan_f; \
            g_n = g * magenta_f; \
            b_n = b * yellow_f; \
 \
			if(plugin->config.preserve) \
            { \
				HSV::rgb_to_hsv(r_n, g_n, b_n, h, s, v); \
				HSV::rgb_to_hsv(r, g, b, h_old, s_old, v); \
                HSV::hsv_to_rgb(r_f, g_f, b_f, h, s, v); \
                r = (float)r_f; \
                g = (float)g_f; \
                b = (float)b_f; \
			} \
            else \
            { \
                r = r_n; \
                g = g_n; \
                b = b_n; \
			} \
 \
            output_rows[j][k] = r; \
            output_rows[j][k + 1] = g; \
            output_rows[j][k + 2] = b; \
		} \
	} \
}

		switch(input->get_color_model())
		{
			case BC_RGB888:
				PROCESS(yuv.yuv_to_rgb_8, 
					yuv.rgb_to_yuv_8, 
					r_lookup_8, 
					g_lookup_8, 
					b_lookup_8, 
					unsigned char, 
					0xff, 
					3,
					0);
				break;

			case BC_RGB_FLOAT:
				PROCESS_F(3);
				break;

			case BC_YUV888:
				PROCESS(yuv.yuv_to_rgb_8, 
					yuv.rgb_to_yuv_8, 
					r_lookup_8, 
					g_lookup_8, 
					b_lookup_8, 
					unsigned char, 
					0xff, 
					3,
					1);
				break;
			
			case BC_RGBA_FLOAT:
				PROCESS_F(4);
				break;

			case BC_RGBA8888:
				PROCESS(yuv.yuv_to_rgb_8, 
					yuv.rgb_to_yuv_8, 
					r_lookup_8, 
					g_lookup_8, 
					b_lookup_8, 
					unsigned char, 
					0xff, 
					4,
					0);
				break;

			case BC_YUVA8888:
				PROCESS(yuv.yuv_to_rgb_8, 
					yuv.rgb_to_yuv_8, 
					r_lookup_8, 
					g_lookup_8, 
					b_lookup_8, 
					unsigned char, 
					0xff, 
					4,
					1);
				break;
			
			case BC_YUV161616:
				PROCESS(yuv.yuv_to_rgb_16, 
					yuv.rgb_to_yuv_16, 
					r_lookup_16, 
					g_lookup_16, 
					b_lookup_16, 
					u_int16_t, 
					0xffff, 
					3,
					1);
				break;

			case BC_YUVA16161616:
				PROCESS(yuv.yuv_to_rgb_16, 
					yuv.rgb_to_yuv_16, 
					r_lookup_16, 
					g_lookup_16, 
					b_lookup_16, 
					u_int16_t, 
					0xffff, 
					4,
					1);
				break;
		}

		
		
		output_lock.unlock();
	}
}
Esempio n. 11
0
      for (k = 0, p1 = p0; k < sys_inchannels; k++, p1 += DEFDACBLKSIZE) { \
        *p1 = *inBuffer++ _x; \
      } \
    } \
    memset(sys_soundout, 0, sys_outchannels*DEFDACBLKSIZE*sizeof(t_sample)); \
    sched_tick(sys_time + sys_time_per_dsp_tick); \
    for (j = 0, p0 = sys_soundout; j < DEFDACBLKSIZE; j++, p0++) { \
      for (k = 0, p1 = p0; k < sys_outchannels; k++, p1 += DEFDACBLKSIZE) { \
        *outBuffer++ = *p1 _y; \
      } \
    } \
  } \
  return 0;

int libpd_process_short(int ticks, const short *inBuffer, short *outBuffer) {
  PROCESS(* short_to_sample, * sample_to_short)
}

int libpd_process_float(int ticks, const float *inBuffer, float *outBuffer) {
  PROCESS(,)
}

int libpd_process_double(int ticks, const double *inBuffer, double *outBuffer) {
  PROCESS(,)
}
 
#define GETARRAY \
  t_garray *garray = (t_garray *) pd_findbyclass(gensym(name), garray_class); \
  if (!garray) return -1; \

int libpd_arraysize(const char *name) {
Esempio n. 12
0
/*---------------------------------------------------------------------------*/
void
httpd_appcall(void *state)
{
#if DEBUGLOGIC
  struct httpd_state *s;   //Enter here for debugging with output directed to TCPBUF
  s = sg = (struct httpd_state *)memb_alloc(&conns);  //put ram watch on sg
  if (1) {
#else
  struct httpd_state *s = (struct httpd_state *)state;

  if(uip_closed() || uip_aborted() || uip_timedout()) {
    if(s != NULL) {
      s->script = NULL;
      memb_free(&conns, s);
    }
  } else if(uip_connected()) {
    s = (struct httpd_state *)memb_alloc(&conns);
    if(s == NULL) {
      uip_abort();
      webserver_log_file(&uip_conn->ripaddr, "reset (no memory block)");
      return;
    }
#endif
    tcp_markconn(uip_conn, s);
    PSOCK_INIT(&s->sin, (uint8_t *)s->inputbuf, sizeof(s->inputbuf) - 1);
    PSOCK_INIT(&s->sout, (uint8_t *)s->inputbuf, sizeof(s->inputbuf) - 1);
    PT_INIT(&s->outputpt);
    s->script = NULL;
    s->state = STATE_WAITING;
    timer_set(&s->timer, CLOCK_SECOND * 10);
    handle_connection(s);
  } else if(s != NULL) {
    if(uip_poll()) {
      if(timer_expired(&s->timer)) {
        uip_abort();
        s->script = NULL;
        memb_free(&conns, s);
        webserver_log_file(&uip_conn->ripaddr, "reset (timeout)");
      }
    } else {
      timer_restart(&s->timer);
    }
    handle_connection(s);
  } else {
    uip_abort();
  }
}
/*---------------------------------------------------------------------------*/
PROCESS(httpd_process, "httpd");
PROCESS_THREAD(httpd_process, ev, data)
{
  PROCESS_BEGIN();

  httpd_init();

  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
    httpd_appcall(data);
  }

  PROCESS_END();
}