static void keyboard_task(void *par) { uint8_t keyb_last,code; keyb_last = 0; code = 0; I2C_RandWrite(KEYBCTRL_ADDR,KBREG_CTRL,1,&keyb_last,1); while (!GPIO_ReadInputDataBit(KBD_IRQn_PORT,KBD_IRQn_PIN)) { keyboard_stroke(); vTaskDelay(kDec/2); } xSemaphoreTake(xSemaKeybo,0); NVIC_EnableIRQ(KBD_IRQn_EXTI_IRQn); for (;;) { keyboard_irq_eve(portMAX_DELAY); if (I2C_RandRead(KEYBCTRL_ADDR,KBREG_MASK,1,&code,1)) { Dprintf(DBGLVL_Keyboard,"keyboard: code=%02X",code); keyboard_stroke(); if (code) { keyb_last = key_decode(code); Dprintf(DBGLVL_Keyboard,"keyboard: %02X",keyb_last); if (keyb_last) { COM_Printf("\r\n*KEYB: %02X,\"%c\"\r\n",code,keyb_last); if (!keyboard_irq_eve(KEYPRESSED_TIME)) { // still pressed key_putstroke(keyb_last,0); //BuzzerSet(BUZTYPE_TOCK); } else { // released keyboard_stroke(); Dprintf(DBGLVL_Keyboard,"keyboard: invalid pressure time"); continue; // already released } } keyboard_waitrelease(); key_putstroke(keyb_last | KEY_RELEASED,0); Dprintf(DBGLVL_Keyboard,"keyboard: released"); } } } }
static int parse_class_attribute (const char *name, const char *start, const char *end, P11KitUri *uri) { CK_OBJECT_CLASS klass = 0; CK_ATTRIBUTE attr; char *value; assert (start <= end); if (strcmp ("objecttype", name) != 0 && strcmp ("object-type", name) != 0) return 0; value = key_decode (start, end); if (value == NULL) return P11_KIT_URI_NO_MEMORY; if (strcmp (value, "cert") == 0) klass = CKO_CERTIFICATE; else if (strcmp (value, "public") == 0) klass = CKO_PUBLIC_KEY; else if (strcmp (value, "private") == 0) klass = CKO_PRIVATE_KEY; else if (strcmp (value, "secretkey") == 0) klass = CKO_SECRET_KEY; else if (strcmp (value, "secret-key") == 0) klass = CKO_SECRET_KEY; else if (strcmp (value, "data") == 0) klass = CKO_DATA; else { free (value); uri->unrecognized = 1; return 1; } free (value); attr.pValue = malloc (sizeof (klass)); if (attr.pValue == NULL) return P11_KIT_URI_NO_MEMORY; memcpy (attr.pValue, &klass, sizeof (klass)); attr.ulValueLen = sizeof (klass); attr.type = CKA_CLASS; uri_take_attribute (uri, &attr); return 1; }
/******************************************************************************* * Obsluha klavesnice *******************************************************************************/ int keyboard_idle() { char ch; int random_num; ch = key_decode(read_word_keyboard_4x4()); if (ch != last_ch) { last_ch = ch; if (ch != 0) { char_cnt++; } } return 0; }
/******************************************************************************* * Obsluha klavesnice *******************************************************************************/ int keyboard_idle() { char ch; ch = key_decode(read_word_keyboard_4x4()); if (ch != last_ch) { last_ch = ch; if (ch != 0) { if (ch == '*') { stopwatch_reset(); } else if (ch == '#' && isrunning) { stopwatch_stop(); } else if (ch == '#' && !isrunning && (t == t0)) { stopwatch_start(); } } } return 0; }
/** * p11_kit_uri_parse: * @string: The string to parse * @uri_type: The type of URI that is expected * @uri: The blank URI to parse the values into * * Parse a PKCS\#11 URI string. * * PKCS\#11 URIs can represent tokens, objects or modules. The uri_type argument * allows the caller to specify what type of URI is expected and the sorts of * things the URI should match. %P11_KIT_URI_FOR_ANY can be used to parse a URI * for any context. It's then up to the caller to make sense of the way that * it is used. * * If the PKCS\#11 URI contains unrecognized URI parts or parts not applicable * to the specified context, then the unrecognized flag will be set. This will * prevent the URI from matching using the various match functions. * * Returns: %P11_KIT_URI_OK if the URI was parsed successfully. * %P11_KIT_URI_BAD_SCHEME if this was not a PKCS\#11 URI. * %P11_KIT_URI_BAD_SYNTAX if the URI syntax was bad. * %P11_KIT_URI_NO_MEMORY if memory allocation failed. * %P11_KIT_URI_BAD_VERSION if a version number was bad. * %P11_KIT_URI_BAD_ENCODING if the URI encoding was invalid. */ int p11_kit_uri_parse (const char *string, P11KitUriType uri_type, P11KitUri *uri) { const char *spos, *epos; char *key = NULL; int ret; int i; assert (string); assert (uri); epos = strchr (string, ':'); if (epos == NULL) return P11_KIT_URI_BAD_SCHEME; key = key_decode (string, epos); ret = strcmp (key, P11_KIT_URI_SCHEME); free (key); if (ret != 0) return P11_KIT_URI_BAD_SCHEME; string = epos + 1; ret = -1; /* Clear everything out */ memset (&uri->module, 0, sizeof (uri->module)); memset (&uri->token, 0, sizeof (uri->token)); for (i = 0; i < uri->n_attributes; ++i) { free (uri->attributes[i].pValue); memset (&uri->attributes[i], 0, sizeof (CK_ATTRIBUTE)); } uri->n_attributes = 0; uri->module.libraryVersion.major = (CK_BYTE)-1; uri->module.libraryVersion.minor = (CK_BYTE)-1; uri->unrecognized = 0; free (uri->pin_source); uri->pin_source = NULL; for (;;) { spos = strchr (string, ';'); if (spos == NULL) { spos = string + strlen (string); assert (*spos == '\0'); if (spos == string) break; } epos = strchr (string, '='); if (epos == NULL || spos == string || epos == string || epos >= spos) return P11_KIT_URI_BAD_SYNTAX; key = key_decode (string, epos); if (key == NULL) return P11_KIT_URI_NO_MEMORY; epos++; ret = 0; if ((uri_type & P11_KIT_URI_FOR_OBJECT) == P11_KIT_URI_FOR_OBJECT) ret = parse_string_attribute (key, epos, spos, uri); if (ret == 0 && (uri_type & P11_KIT_URI_FOR_OBJECT) == P11_KIT_URI_FOR_OBJECT) ret = parse_class_attribute (key, epos, spos, uri); if (ret == 0 && (uri_type & P11_KIT_URI_FOR_TOKEN) == P11_KIT_URI_FOR_TOKEN) ret = parse_token_info (key, epos, spos, uri); if (ret == 0 && (uri_type & P11_KIT_URI_FOR_MODULE) == P11_KIT_URI_FOR_MODULE) ret = parse_module_info (key, epos, spos, uri); if (ret == 0 && (uri_type & P11_KIT_URI_FOR_MODULE_WITH_VERSION) == P11_KIT_URI_FOR_MODULE_WITH_VERSION) ret = parse_module_version_info (key, epos, spos, uri); if (ret == 0) ret = parse_extra_info (key, epos, spos, uri); free (key); if (ret < 0) return ret; if (ret == 0) uri->unrecognized = 1; if (*spos == '\0') break; string = spos + 1; } return P11_KIT_URI_OK; }