Esempio n. 1
0
/**************************************************************************************************
	AXFR_REPLY
	Sends one reply to the client.
**************************************************************************************************/
static void
axfr_reply(TASK *t) {
  char len[2] = { 0, 0 }, *l = len;

  build_reply(t, 0);
  DNS_PUT16(l, t->replylen);
  axfr_write(t, len, SIZE16);
  axfr_write(t, t->reply, t->replylen);
  total_octets += SIZE16 + t->replylen;
  total_records++;

  /* Reset the pertinent parts of the task reply data */
  rrlist_free(&t->an);
  rrlist_free(&t->ns);
  rrlist_free(&t->ar);

  RELEASE(t->reply);
  t->replylen = 0;

  name_forget(t);

  RELEASE(t->rdata);
  t->rdlen = 0;

  /* Nuke question data */
  t->qdcount = 0;
  t->qdlen = 0;
}
Esempio n. 2
0
void
doreply(struct con *cp)
{
	build_reply(cp);
}
Esempio n. 3
0
static void twi_callback(uint8_t buffer_size, volatile uint8_t input_buffer_length, const volatile uint8_t *input_buffer,
						uint8_t volatile *output_buffer_length, volatile uint8_t *output_buffer)
{
	uint8_t input;
	uint8_t	command;
	uint8_t	io;

	if(input_buffer_length < 1)
		return(build_reply(output_buffer_length, output_buffer, 0, 1, 0, 0));

	input	= input_buffer[0];
	command	= input & 0xf8;
	io		= input & 0x07;

	switch(command)
	{
		case(0x00):	// short / no-io
		{
			switch(io)
			{
				case(0x00):	// identify
				{
					static const uint8_t replystring[] =
					{
						0x4a, 0xfb,
						0x06, 0x01, 0x00,
						't', '8', '6', '1', 'a'
					};

					return(build_reply(output_buffer_length, output_buffer, input, 0, sizeof(replystring), replystring));
				}

				case(0x01):	// 0x02 read ADC
				{
					uint8_t value;

					value = ADCW;

					if(ADCSRA & _BV(ADSC))	// conversion not ready
						return(build_reply(output_buffer_length, output_buffer, input, 5, 0, 0));

					adc_stop();

					uint8_t replystring[2];

					replystring[0] = (value & 0xff00) >> 8;
					replystring[1] = (value & 0x00ff) >> 0;

					return(build_reply(output_buffer_length, output_buffer, input, 0, sizeof(replystring), replystring));
				}

				case(0x02): // 0x02 DEBUG read timer0 counter
				{
					uint8_t value = timer0_get_counter();
					return(build_reply(output_buffer_length, output_buffer, input, 0, 1, &value));
				}

				case(0x03): // 0x03 DEBUG read timer1 counter
				{
					uint16_t value = pwm_timer1_get_counter();
					uint8_t rv[2];

					rv[0] = (value & 0xff00) >> 8;
					rv[1] = (value & 0x00ff) >> 0;

					return(build_reply(output_buffer_length, output_buffer, input, 0, sizeof(rv), rv));
				}

				case(0x04): // 0x04 DEBUG read timer1 max
				{
					uint16_t value = pwm_timer1_get_max();
					uint8_t rv[2];

					rv[0] = (value & 0xff00) >> 8;
					rv[1] = (value & 0x00ff) >> 0;

					return(build_reply(output_buffer_length, output_buffer, input, 0, sizeof(rv), rv));
				}

				case(0x05): // 0x05 read timer1 prescaler
				{
					uint8_t value = pwm_timer1_status();

					return(build_reply(output_buffer_length, output_buffer, input, 0, sizeof(value), &value));
				}

				case(0x06): // 0x06 DEBUG read timer0 entry / exit counter values
				{
					uint8_t value[2];

					value[0] = timer0_debug_1;
					value[1] = timer0_debug_2;

					return(build_reply(output_buffer_length, output_buffer, input, 0, sizeof(value), value));
				}

				case(0x07): // extended command
				{
					return(build_reply(output_buffer_length, output_buffer, input, 7, 0, 0));
				}

				default:
				{
					return(build_reply(output_buffer_length, output_buffer, input, 7, 0, 0));
				}
			}

			break;
		}

		case(0x10):	// 0x10 read counter
		case(0x20): // 0x20 read / reset counter
		{
			if(io >= COUNTER_PORTS)
				return(build_reply(output_buffer_length, output_buffer, input, 3, 0, 0));

			uint32_t counter = counters_meta[io].counter;

			if(command == 0x20)
				counters_meta[io].counter = 0;

			uint8_t replystring[4];

			replystring[0] = (counter & 0xff000000) >> 24;
			replystring[1] = (counter & 0x00ff0000) >> 16;
			replystring[2] = (counter & 0x0000ff00) >> 8;
			replystring[3] = (counter & 0x000000ff) >> 0;

			return(build_reply(output_buffer_length, output_buffer, input, 0, sizeof(replystring), replystring));
		}

		case(0x30):	//	read input
		{
			uint8_t value;

			if(io >= INPUT_PORTS)
				return(build_reply(output_buffer_length, output_buffer, input, 3, 0, 0));

			value = !!(*input_ports[io].port & (1 << input_ports[io].bit));

			return(build_reply(output_buffer_length, output_buffer, input, 0, 1, &value));
		}

		case(0x40):	//	write output / softpwm
		{
			if(input_buffer_length < 2)
				return(build_reply(output_buffer_length, output_buffer, input, 4, 0, 0));

			if(io >= OUTPUT_PORTS)
				return(build_reply(output_buffer_length, output_buffer, input, 3, 0, 0));

			softpwm_meta[io].duty = input_buffer[1];
			update_static_softpwm_ports();
			timer0_start();

			return(build_reply(output_buffer_length, output_buffer, input, 0, sizeof(softpwm_meta), (uint8_t *)softpwm_meta));
		}

		case(0x50):	// read output / softpwm
		{
			if(io >= OUTPUT_PORTS)
				return(build_reply(output_buffer_length, output_buffer, input, 3, 0, 0));

			duty = softpwm_meta[io].duty;

			return(build_reply(output_buffer_length, output_buffer, input, 0, sizeof(duty), &duty));
		}

		case(0x60): // write softpwm mode
		{
			if(input_buffer_length < 2)
				return(build_reply(output_buffer_length, output_buffer, input, 4, 0, 0));

			if(io >= OUTPUT_PORTS)
				return(build_reply(output_buffer_length, output_buffer, input, 3, 0, 0));

			uint8_t mode = input_buffer[1];

			if(mode > 3)
				return(build_reply(output_buffer_length, output_buffer, input, 3, 0, 0));

			softpwm_meta[io].pwm_mode = input_buffer[1];

			return(build_reply(output_buffer_length, output_buffer, input, 0, sizeof(softpwm_meta), (uint8_t *)softpwm_meta));
		}

		case(0x70):	// read softpwm mode
		{
			if(io >= OUTPUT_PORTS)
				return(build_reply(output_buffer_length, output_buffer, input, 3, 0, 0));

			uint8_t mode;

			mode = softpwm_meta[io].pwm_mode;

			return(build_reply(output_buffer_length, output_buffer, input, 0, sizeof(mode), &mode));
		}

		case(0x80): // write pwm
		{
			if(input_buffer_length < 3)
				return(build_reply(output_buffer_length, output_buffer, input, 4, 0, 0));

			if(io >= PWM_PORTS)
				return(build_reply(output_buffer_length, output_buffer, input, 3, 0, 0));

			uint16_t value;

			value = input_buffer[1];
			value <<= 8;
			value |= input_buffer[2];

			pwm_timer1_set_pwm(io, value);

			return(build_reply(output_buffer_length, output_buffer, input, 0, 0, 0));
		}

		case(0x90): // read pwm
		{
			if(io >= PWM_PORTS)
				return(build_reply(output_buffer_length, output_buffer, input, 3, 0, 0));

			uint16_t value = pwm_timer1_get_pwm(io);
			uint8_t reply[2];

			reply[0] = (value & 0xff00) >> 8;
			reply[1] = (value & 0x00ff) >> 0;

			return(build_reply(output_buffer_length, output_buffer, input, 0, sizeof(reply), reply));
		}

		case(0xa0): // write pwm mode
		{
			if(input_buffer_length < 2)
				return(build_reply(output_buffer_length, output_buffer, input, 4, 0, 0));

			if(io >= PWM_PORTS)
				return(build_reply(output_buffer_length, output_buffer, input, 3, 0, 0));

			uint8_t mode = input_buffer[1];

			if(mode > 3)
				return(build_reply(output_buffer_length, output_buffer, input, 3, 0, 0));

			pwm_meta[io].pwm_mode = input_buffer[1];

			return(build_reply(output_buffer_length, output_buffer, input, 0, sizeof(pwm_meta), (uint8_t *)pwm_meta));
		}

		case(0xb0):	// read pwm mode
		{
			if(io >= PWM_PORTS)
				return(build_reply(output_buffer_length, output_buffer, input, 3, 0, 0));

			uint8_t mode;

			mode = pwm_meta[io].pwm_mode;

			return(build_reply(output_buffer_length, output_buffer, input, 0, sizeof(mode), &mode));
		}

		case(0xc0):	// start adc conversion
		{
			if(io > 1)
				return(build_reply(output_buffer_length, output_buffer, input, 3, 0, 0));

			adc_start(io);
			return(build_reply(output_buffer_length, output_buffer, input, 0, 0, 0));
		}

		case(0xf0):	// twi stats
		{
			uint8_t		replystring[2];
			uint16_t	stats;

			switch(io)
			{
				case(0x00):	//	disable
				{
					usi_twi_enable_stats(0);
					return(build_reply(output_buffer_length, output_buffer, input, 0, 0, 0));
				}

				case(0x01):	//	enable
				{
					usi_twi_enable_stats(1);
					return(build_reply(output_buffer_length, output_buffer, input, 0, 0, 0));
				}

				case(0x02):	//	read start conditions
				{
					stats = usi_twi_stats_start_conditions();
					break;
				}

				case(0x03):	//	read stop conditions
				{
					stats = usi_twi_stats_stop_conditions();
					break;
				}

				case(0x04):	//	read error conditions
				{
					stats = usi_twi_stats_error_conditions();
					break;
				}

				case(0x05):	//	read overflow conditions
				{
					stats = usi_twi_stats_overflow_conditions();
					break;
				}

				case(0x06):	//	read local frames
				{
					stats = usi_twi_stats_local_frames();
					break;
				}

				case(0x07):	//	read idle calls
				{
					stats = usi_twi_stats_idle_calls();
					break;
				}
			}

			replystring[0] = (stats & 0xff00) >> 8;
			replystring[1] = (stats & 0x00ff) >> 0;

			return(build_reply(output_buffer_length, output_buffer, input, 0, sizeof(replystring), replystring));
		}
		default:
		{
			return(build_reply(output_buffer_length, output_buffer, input, 2, 0, 0));
		}
	}

	return(build_reply(output_buffer_length, output_buffer, input, 2, 0, 0));
}