示例#1
0
void ApmConfig::setupHelper2()	// we use the acpi helper to do software suspend
{
	unsigned long len, crc;
	QString helper = KStandardDirs::findExe("klaptop_acpi_helper");
	checkcrc(helper.latin1(), len, crc);
	if (len != file_len || crc != file_crc) {
		QString str(i18n("The %1 application does not seem to have "
					"the same size or checksum as when it was compiled we do NOT recommend "
					"you proceed with making it setuid-root without further investigation").arg(helper));
		int rc = KMessageBox::warningContinueCancel(0, str, i18n("KLaptopDaemon"), i18n("Run Nevertheless"));
		if (rc != KMessageBox::Continue) 
			return;
	}

	QString kdesu = KStandardDirs::findExe("kdesu");
	if (!kdesu.isEmpty()) {
		int rc = KMessageBox::warningContinueCancel(0,
				i18n("You will need to supply a root password "
					"to allow the privileges of the klaptop_acpi_helper to change."),
				i18n("KLaptopDaemon"), KStdGuiItem::cont(),
				"");
		if (rc == KMessageBox::Continue) {
			KProcess proc;
			proc << kdesu;
			proc << "-u";
			proc << "root";
			proc <<  "chown root "+helper+"; chmod +s "+helper;
			proc.start(KProcess::Block);	// run it sync so has_acpi below sees the results
		}
	} else {
		KMessageBox::sorry(0, i18n("The Software Suspend helper cannot be enabled because kdesu cannot be found.  Please make sure that it is installed correctly."),
				i18n("KLaptopDaemon"));
	}
	laptop_portable::software_suspend_set_mask(enablesoftwaresuspend);
    	bool can_enable = laptop_portable::has_software_suspend(2);	// is helper ready
    	enableSoftwareSuspendHibernate->setEnabled(can_enable);
	wake_laptop_daemon();
}
示例#2
0
int check_imagefile(char *fname)
{
	if(checkcrc(fname)==0) return 1;
	return 0;
}
示例#3
0
int main(void)
{
	serial_init(E_BAUD_4800);	
	serial_install_interrupts(E_FLAGS_SERIAL_RX_INTERRUPT);
	serial_flush();

	while(1) {
		char str[32] = {0x00};
		memset(str, 0x00, sizeof(str));

#if TEST_TYPE == TEST_SIMPLE
#warning Building Test Simple

		strcpy(buffer, "123456789");
	   	snprintf(str, sizeof(str), "CRC: %04x\n", 
				checkcrc((unsigned char *)buffer, strlen(buffer)));
		serial_poll_send(str, strlen(str));

#elif TEST_TYPE == TEST_RECEIVE
#warning Building Test Receive

		unsigned char size = 0x00;
		uint16_t crc = 0x0000;

		if (0 >= (size = slip_recv((unsigned char *)buffer, 128)))
			continue;

		memcpy(&crc, &buffer[size - 2], 2);
		memset(&buffer[size - 2], 0x00, 2);

	   	snprintf(str, sizeof(str), "RECV [%04x], CRC: %04x\r\n", 
				crc,
				checkcrc((unsigned char *)buffer, size));
		serial_poll_send(str, strlen(str));

#elif TEST_TYPE == TEST_VERIFY
#warning Building Test Verify

		unsigned char size = 0x00;

		if (0 >= (size = slip_recv((unsigned char *)buffer, 128)))
			continue;

	   	snprintf(str, sizeof(str), "Verification: [%s]\r\n", 
				slip_verify_crc16(buffer, size, size - 2) ?
				"positive" : "negative");

		serial_poll_send(str, strlen(str));

#elif TEST_TYPE == TEST_SEND
#warning Building Test Send

		strcpy(buffer, "123456789");
		slip_append_crc16((unsigned char *)buffer, strlen(buffer));
		serial_poll_send(buffer, 11);
		serial_poll_send("\n",1);

#else
#error Uknown test type
#endif
		_delay_ms(200);
	}

	return 0;
}
示例#4
0
static int
receive (byte * buf, int length, int expected)
{
  int tries = 0;
  int n, total, i;
  byte *ptr;


  while (1)
    {


      ptr = buf;
      i = length;
      total = 0;

      while (waitforinput (fd))
        {

          n = read (fd, ptr, i);

          if (n > 0)
            {
              ptr += n;
              i -= n;
              total += n;

              if (checkcrc (buf, total) && (total == expected))
                {
#ifdef DEBUG
                  fprintf (stderr, "Read %d bytes as expected\n", total);
#endif
                  return total;

                }

            }
        }

#ifdef DEBUG
      fprintf (stderr, "Read %d byes of %d bytes expected\n", total, expected);
#endif

      /*Ok didn't match expected - two posibities */
      /*1st we missed packet/crcerror */
      /*2nd this is the last packet */

      tries++;


      if ((total == 1) && (tries == 2) && (expected == SDSC_BLOCKSIZE))
        {
#ifdef DEBUG
          fprintf (stderr, "Detected EOF condition\n");
#endif
          return total;
        }

      if (tries == SDSC_RETRIES)
        {
#ifdef DEBUG
          fprintf (stderr, "Giving up\n");
#endif
          return 0;
        }

#ifdef DEBUG
      fprintf (stderr, "Retrying\n");
#endif
      sendcommand (SDSC_RETRANSMIT);


    }

}