void RedClient::on_connect() { AutoRef<ConnectedEvent> event(new ConnectedEvent()); push_event(*event); _migrate.add_channel(new MigChannel(SPICE_CHANNEL_MAIN, 0, get_common_caps(), get_caps())); }
static GUPnPDLNAStringValue backend_get_mime (GUPnPDLNAImageInformation *self) { GUPnPDLNAGstImageInformation* gst_info = GUPNP_DLNA_GST_IMAGE_INFORMATION (self); return gupnp_dlna_gst_get_mime (get_caps (gst_info)); }
const char *get_cap(const char *const fname, const char *cap) { if ((cap == NULL) || (fname == NULL)) return NULL; const char **cv = get_caps(fname); if (cv == NULL) return NULL; const char **p = cv; size_t len = strlen(cap); while (p && *p && strlen(*p)) { if (strncasecmp(*p, cap, len) == 0) { const char *result = strdup(*p + len + 1); // skip over '=' free(cv); return result; } } free(cv); return NULL; }
static void handle_method_call (GDBusConnection * connection, const gchar * sender, const gchar * object_path, const gchar * interface_name, const gchar * method_name, GVariant * parameters, GDBusMethodInvocation * invocation, gpointer user_data) { g_printf ("Inside Handle Method(%s) Call \n", method_name); if (g_strcmp0 (method_name, "HelloWorld") == 0) { const gchar *greeting; gchar *response; g_variant_get (parameters, "(&s)", &greeting); response = g_strdup_printf ("You typed '%s', !!! ", greeting); g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", response)); //g_print ("Sending %s -> to the client ", response); } else if (0 == g_strcmp0(method_name, "GetCaps")) { GVariantBuilder* vBuilder = g_variant_builder_new("a{sas}"); if (get_caps(vBuilder)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(a{sas})", vBuilder)); } } else if (0 == g_strcmp0(method_name, "GetVersion")) { GVariantBuilder* vBuilder = g_variant_builder_new("a{ss}"); if (get_version(vBuilder)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(a{ss})", vBuilder)); } } else if (0 == g_strcmp0(method_name, "setPropList")) { GVariantIter* proplistiter; g_variant_get(parameters, "(a{ss})", &proplistiter); g_dbus_method_invocation_return_value(invocation, g_variant_new("(b)", set_prop_list(proplistiter))); } else if (0 == g_strcmp0(method_name, "setProp")) { gchar* propName; gchar* propValue; g_variant_get(parameters, "(ss)", &propName, &propValue); g_dbus_method_invocation_return_value(invocation, g_variant_new("(b)", set_prop(propName, propValue))); } }
int rtapi_get_tags(const char *mod_name) { char modpath[PATH_MAX]; int result = 0, n = 0; char *cp1 = ""; flavor_ptr flavor = default_flavor(); if (kernel_threads(flavor)) { if (module_path(modpath, mod_name) < 0) { perror("module_path"); return -1; } } else { if (get_rtapi_config(modpath,"RTLIB_DIR",PATH_MAX) != 0) { perror("cant get RTLIB_DIR ?\n"); return -1; } strcat(modpath,"/"); strcat(modpath, flavor->name); strcat(modpath,"/"); strcat(modpath,mod_name); strcat(modpath, flavor->mod_ext); } const char **caps = get_caps(modpath); char **p = (char **)caps; while (p && *p && strlen(*p)) { cp1 = *p++; if (strncmp(cp1,"HAL=", 4) == 0) { n = strtol(&cp1[4], NULL, 10); result |= n ; } } free(caps); return result; }
static int guess_device_class(struct udev_device *dev) { int devclass = 0; struct udev_device *pdev; unsigned long bitmask_ev[NBITS(EV_MAX)]; unsigned long bitmask_abs[NBITS(ABS_MAX)]; unsigned long bitmask_key[NBITS(KEY_MAX)]; unsigned long bitmask_rel[NBITS(REL_MAX)]; unsigned long keyboard_mask; /* walk up the parental chain until we find the real input device; the * argument is very likely a subdevice of this, like eventN */ pdev = dev; while (pdev && !_this->udev_device_get_sysattr_value(pdev, "capabilities/ev")) { pdev = _this->udev_device_get_parent_with_subsystem_devtype(pdev, "input", NULL); } if (!pdev) { return 0; } get_caps(dev, pdev, "capabilities/ev", bitmask_ev, SDL_arraysize(bitmask_ev)); get_caps(dev, pdev, "capabilities/abs", bitmask_abs, SDL_arraysize(bitmask_abs)); get_caps(dev, pdev, "capabilities/rel", bitmask_rel, SDL_arraysize(bitmask_rel)); get_caps(dev, pdev, "capabilities/key", bitmask_key, SDL_arraysize(bitmask_key)); if (test_bit(EV_ABS, bitmask_ev) && test_bit(ABS_X, bitmask_abs) && test_bit(ABS_Y, bitmask_abs)) { if (test_bit(BTN_STYLUS, bitmask_key) || test_bit(BTN_TOOL_PEN, bitmask_key)) { ; /* ID_INPUT_TABLET */ } else if (test_bit(BTN_TOOL_FINGER, bitmask_key) && !test_bit(BTN_TOOL_PEN, bitmask_key)) { ; /* ID_INPUT_TOUCHPAD */ } else if (test_bit(BTN_MOUSE, bitmask_key)) { devclass |= SDL_UDEV_DEVICE_MOUSE; /* ID_INPUT_MOUSE */ } else if (test_bit(BTN_TOUCH, bitmask_key)) { ; /* ID_INPUT_TOUCHSCREEN */ } if (test_bit(BTN_TRIGGER, bitmask_key) || test_bit(BTN_A, bitmask_key) || test_bit(BTN_1, bitmask_key) || test_bit(ABS_RX, bitmask_abs) || test_bit(ABS_RY, bitmask_abs) || test_bit(ABS_RZ, bitmask_abs) || test_bit(ABS_THROTTLE, bitmask_abs) || test_bit(ABS_RUDDER, bitmask_abs) || test_bit(ABS_WHEEL, bitmask_abs) || test_bit(ABS_GAS, bitmask_abs) || test_bit(ABS_BRAKE, bitmask_abs)) { devclass |= SDL_UDEV_DEVICE_JOYSTICK; /* ID_INPUT_JOYSTICK */ } } if (test_bit(EV_REL, bitmask_ev) && test_bit(REL_X, bitmask_rel) && test_bit(REL_Y, bitmask_rel) && test_bit(BTN_MOUSE, bitmask_key)) { devclass |= SDL_UDEV_DEVICE_MOUSE; /* ID_INPUT_MOUSE */ } /* the first 32 bits are ESC, numbers, and Q to D; if we have any of * those, consider it a keyboard device; do not test KEY_RESERVED, though */ keyboard_mask = 0xFFFFFFFE; if ((bitmask_key[0] & keyboard_mask) != 0) devclass |= SDL_UDEV_DEVICE_KEYBOARD; /* ID_INPUT_KEYBOARD */ return devclass; }
/** * gst_vaapi_decoder_get_caps: * @decoder: a #GstVaapiDecoder * * Retrieves the @decoder caps. The decoder owns the returned caps, so * use gst_caps_ref() whenever necessary. * * Return value: the @decoder caps */ GstCaps * gst_vaapi_decoder_get_caps (GstVaapiDecoder * decoder) { return get_caps (decoder); }
void RedChannelBase::link(uint32_t connection_id, const std::string& password, int protocol) { SpiceLinkHeader header; SpiceLinkMess link_mess; SpiceLinkReply* reply; uint32_t link_res; uint32_t i; EVP_PKEY *pubkey; int nRSASize; BIO *bioKey; RSA *rsa; uint8_t *buffer, *p; uint32_t expected_major; header.magic = SPICE_MAGIC; header.size = sizeof(link_mess); if (protocol == 1) { /* protocol 1 == major 1, old 0.4 protocol, last active minor */ expected_major = header.major_version = 1; header.minor_version = 3; } else if (protocol == 2) { /* protocol 2 == current */ expected_major = header.major_version = SPICE_VERSION_MAJOR; header.minor_version = SPICE_VERSION_MINOR; } else { THROW("unsupported protocol version specified"); } link_mess.connection_id = connection_id; link_mess.channel_type = _type; link_mess.channel_id = _id; link_mess.num_common_caps = get_common_caps().size(); link_mess.num_channel_caps = get_caps().size(); link_mess.caps_offset = sizeof(link_mess); header.size += (link_mess.num_common_caps + link_mess.num_channel_caps) * sizeof(uint32_t); buffer = new uint8_t[sizeof(header) + sizeof(link_mess) + _common_caps.size() * sizeof(uint32_t) + _caps.size() * sizeof(uint32_t)]; p = buffer; memcpy(p, (uint8_t*)&header, sizeof(header)); p += sizeof(header); memcpy(p, (uint8_t*)&link_mess, sizeof(link_mess)); p += sizeof(link_mess); for (i = 0; i < _common_caps.size(); i++) { *(uint32_t *)p = _common_caps[i]; p += sizeof(uint32_t); } for (i = 0; i < _caps.size(); i++) { *(uint32_t *)p = _caps[i]; p += sizeof(uint32_t); } send(buffer, p - buffer); delete [] buffer; recive((uint8_t*)&header, sizeof(header)); if (header.magic != SPICE_MAGIC) { THROW_ERR(SPICEC_ERROR_CODE_CONNECT_FAILED, "bad magic"); } if (header.major_version != expected_major) { THROW_ERR(SPICEC_ERROR_CODE_VERSION_MISMATCH, "version mismatch: expect %u got %u", expected_major, header.major_version); } _remote_major = header.major_version; _remote_minor = header.minor_version; AutoArray<uint8_t> reply_buf(new uint8_t[header.size]); recive(reply_buf.get(), header.size); reply = (SpiceLinkReply *)reply_buf.get(); if (reply->error != SPICE_LINK_ERR_OK) { THROW_ERR(SPICEC_ERROR_CODE_CONNECT_FAILED, "connect error %u - %s", reply->error, spice_link_error_string(reply->error)); } uint32_t num_caps = reply->num_channel_caps + reply->num_common_caps; if ((uint8_t *)(reply + 1) > reply_buf.get() + header.size || (uint8_t *)reply + reply->caps_offset + num_caps * sizeof(uint32_t) > reply_buf.get() + header.size) { THROW_ERR(SPICEC_ERROR_CODE_CONNECT_FAILED, "access violation"); } uint32_t *caps = (uint32_t *)((uint8_t *)reply + reply->caps_offset); _remote_common_caps.clear(); for (i = 0; i < reply->num_common_caps; i++, caps++) { _remote_common_caps.resize(i + 1); _remote_common_caps[i] = *caps; } _remote_caps.clear(); for (i = 0; i < reply->num_channel_caps; i++, caps++) { _remote_caps.resize(i + 1); _remote_caps[i] = *caps; } bioKey = BIO_new(BIO_s_mem()); if (bioKey != NULL) { BIO_write(bioKey, reply->pub_key, SPICE_TICKET_PUBKEY_BYTES); pubkey = d2i_PUBKEY_bio(bioKey, NULL); rsa = pubkey->pkey.rsa; nRSASize = RSA_size(rsa); AutoArray<unsigned char> bufEncrypted(new unsigned char[nRSASize]); /* The use of RSA encryption limit the potential maximum password length. for RSA_PKCS1_OAEP_PADDING it is RSA_size(rsa) - 41. */ if (RSA_public_encrypt(password.length() + 1, (unsigned char *)password.c_str(), (uint8_t *)bufEncrypted.get(), rsa, RSA_PKCS1_OAEP_PADDING) > 0) { send((uint8_t*)bufEncrypted.get(), nRSASize); } else { THROW("could not encrypt password"); } memset(bufEncrypted.get(), 0, nRSASize); } else { THROW("Could not initiate BIO"); } BIO_free(bioKey); recive((uint8_t*)&link_res, sizeof(link_res)); if (link_res != SPICE_LINK_ERR_OK) { int error_code = (link_res == SPICE_LINK_ERR_PERMISSION_DENIED) ? SPICEC_ERROR_CODE_CONNECT_FAILED : SPICEC_ERROR_CODE_CONNECT_FAILED; THROW_ERR(error_code, "connect failed %u", link_res); } }
/** * Send a keymaster command to sep, and waits for a response * @param cmd_buffer : Pointer to command buffer * @param buffer_length : Number of command bytes * @param rsp_buffer : Pointer to response buffer * @param rsp_length : Upon input, size of response buffer * Upon return, actual size of response * @return SEP_KEYMASTER_CMD_SUCCESS if command was sent and * response received; non zero value if there was a failure */ sep_keymaster_return_t sep_keymaster_send_cmd(const uint8_t * cmd_buffer, uint32_t cmd_length, uint8_t * rsp_buffer, uint32_t * rsp_length) { sep_keymaster_return_t result = SEP_KEYMASTER_FAILURE; uint8_t *request = NULL; uint8_t *response = NULL; uint32_t fw_request_len = 0; MEI_HANDLE *mei_handle = NULL; //Redirect logger output to logcat txei_log_set_dest(TXEI_LOG_DEST_ANDROID, NULL, NULL); //Validate input parameters if (!(cmd_buffer != NULL && rsp_buffer != NULL && rsp_length != NULL)) { result = SEP_KEYMASTER_BAD_PARAMETER; goto exit; } //Command buffer should contain at least a command id and length field if (cmd_length < sizeof(intel_keymaster_firmware_cmd_t)) { result = SEP_KEYMASTER_BAD_PARAMETER; goto exit; } //Response buffer should at least have intel_keymaster_firmware_rsp_t bytes if (*rsp_length < sizeof(intel_keymaster_firmware_rsp_t)) { result = SEP_KEYMASTER_RSP_BUFFER_TOO_SMALL; goto exit; } //If capabilities have not been obtained before, do so now if (!caps_obtained) { result = get_caps(); if (result != SEP_KEYMASTER_SUCCESS) { LOGERR("Obtaining capabilites failed. Bailing"); goto exit; } caps_obtained = 1; } #define LOGGING #ifdef LOGGING { #define KEYMASTER_NUM_CMDS 8 char *cmd_name[KEYMASTER_NUM_CMDS] = { "Invalid command", "KEYMASTER_CMD_GENERATE_KEYPAIR", "KEYMASTER_CMD_IMPORT_KEYPAIR", "KEYMASTER_CMD_GET_KEYPAIR_PUBLIC", "KEYMASTER_CMD_DELETE_KEYPAIR", "KEYMASTER_CMD_DELETE_ALL", "KEYMASTER_CMD_SIGN_DATA", "KEYMASTER_CMD_VERIFY_DATA" }; if (*(uint32_t *) cmd_buffer < KEYMASTER_NUM_CMDS) { LOGINFO("%s", cmd_name[*(uint32_t *) cmd_buffer]); } else { LOGERR("unknown command"); } } #endif //Translate the command buffer intel_keymaster_firmware_cmd_t *lib_cmd = (intel_keymaster_firmware_cmd_t *) cmd_buffer; result = generate_cmd_buf(lib_cmd, &request, &fw_request_len); if (result != SEP_KEYMASTER_SUCCESS) { LOGERR("Generating command buffer failed"); goto exit; } if (fw_request_len > MAX_HECI_MSG_SIZE) { LOGERR("Command buffer is too big\n"); result = SEP_KEYMASTER_CMD_BUFFER_TOO_BIG; goto exit; } //Allocate the response buffer //Caller allocated a response buffer that includes a header (= sizeof(intel_keymaster_firmware_rsp_t)) and data (= *rsp_length - sizeof(header)) //So the total data we can pass back is approx. (*rsp_length - sizeof(header)) bytes long uint32_t fw_response_length = sizeof(ANDROID_HECI_AGENT_RESP_HEADER) + *rsp_length - sizeof(intel_keymaster_firmware_rsp_t); //TODO: Is this check sufficient? response = (uint8_t *) malloc(fw_response_length); if (!response) { result = SEP_KEYMASTER_OUT_OF_MEMORY; goto exit; } memset(response, 0, fw_response_length); //print_buf("Request Data", request, ((ANDROID_HECI_AGENT_REQ_HEADER *)request)->InputSize + sizeof(ANDROID_HECI_AGENT_REQ_HEADER)); result = send_req_to_fw(request, fw_request_len, response, fw_response_length); if (result != SEP_KEYMASTER_SUCCESS) { LOGERR("Failed to send request to the MEI driver"); goto exit; } //print_buf("Response Data", response, ((ANDROID_HECI_AGENT_RESP_HEADER *)response)->OutputSize + sizeof(ANDROID_HECI_AGENT_RESP_HEADER)); //For now cast response to type ANDROID_HECI_AGENT_RESP_HEADER to get the value of fields in the header ANDROID_HECI_AGENT_RESP_HEADER *fw_rsp_hdr = (ANDROID_HECI_AGENT_RESP_HEADER *) response; //Set the correct command id. We have to do this irrespective of the status of the command. intel_keymaster_firmware_rsp_t *firmware_rsp = (intel_keymaster_firmware_rsp_t *) rsp_buffer; result = set_response_cmd_id(fw_rsp_hdr->ResponseCode, &firmware_rsp->rsp_id); if (result != SEP_KEYMASTER_SUCCESS) { LOGERR("Setting the response command id failed\n"); goto exit; } //Set the status of the command and length in the response to the caller. //If it was successful, additionally return the data //Also set response length result = set_response_status_and_data(response, firmware_rsp, rsp_length, *rsp_length); if (result != SEP_KEYMASTER_SUCCESS) { LOGERR("Setting the status and data failed\n"); goto exit; } //Finally, everything looks good result = SEP_KEYMASTER_SUCCESS; exit: if (request) { free(request); request = NULL; } if (response) { free(response); response = NULL; } return result; }
int main(int argc, char **argv) { int shmid; int i,j; char in_str[16]; process_arguments(argc, argv); /* open the camera device */ if( (camera_fd = open(psz_video_dev, O_RDWR)) < 0 ) { char error_buf[256]; sprintf(error_buf, "open() %s", psz_video_dev); perror(error_buf); exit(-1); } get_caps(); get_format(); if( b_verbose ) printf("Device opened.\n"); if( b_verbose ) { printf("Video device:\t\t%s\n", psz_video_dev); print_caps(); print_format(); printf("Ouput directory:\t%s\n", psz_output_dir); printf("Image format:\t\t%s\n",str_formats[e_outfmt]); printf("\n"); printf("Opening device %s\n", psz_video_dev); if( b_named_filename ) { printf("Ouput filename:\t%s\n", psz_output_filename); } else if( b_named_pipe ) { printf("Using named pipe %s\n", psz_named_pipe); } if( b_shared_mem ) printf("Using shared memory. key = %i\n", shared_mem_key); } if( b_printinfo ) { printf("Device info:\n"); print_caps(); print_format(); close(camera_fd); exit(EXIT_SUCCESS); } (void)signal(SIGINT, exit_program); if( b_shared_mem && b_named_pipe ) { printf("WARNING: shared memory and named pipe can't be used together. Use more instances of camshot. Defaulting to named pipe.\n"); b_shared_mem = 0; } if( b_named_pipe ) { int ret_val = mkfifo(psz_named_pipe, 0666); if ((ret_val == -1) && (errno != EEXIST)) { perror("Error creating the named pipe"); exit(EXIT_FAILURE); } } if( req_width && req_height ) { if( b_verbose ) printf("Trying to set resolution to %ux%u.\n", req_width, req_height); if( set_width_height(req_width,req_height) == -1 ) printf("Unable to set the desired resolution.\n"); else if( b_verbose ) printf("Resolution set to %ux%u\n", req_width, req_height); } else { get_format(); req_width = camera_format.fmt.pix.width; req_height = camera_format.fmt.pix.height; } if( b_shared_mem ) { if((shmid = shmget(shared_mem_key, req_width*req_height*3, IPC_CREAT | 0666)) < 0) { perror("Error getting shared memory id"); exit(EXIT_FAILURE); } if((p_shm = (uint8_t *)shmat(shmid, NULL, 0)) == (void *) -1) { perror("Error getting shared memory ptr"); exit(EXIT_FAILURE); } shm_sem = semget((key_t)shared_mem_key, 1, IPC_CREAT | 0666); sem_set(&shm_sem); if( b_verbose ) printf("Shared memory ID: %i\nSemaphore ID: %i\n", shmid, shm_sem); } total_buffers = req_mmap_buffers(2); /* start the capture */ streaming_on(); /* let the camera self adjust by 'ignoring' 200 complete buffer queues */ printf("Letting the camera automaticaly adjust the picture:"); for(i=0; i<AUTO_ADJUST_TURNS; i++) { for(j=0; j<total_buffers; j++) { int ready_buf = dequeue_buffer(); /* don't queue the last buffers */ if( i<AUTO_ADJUST_TURNS-1 ) queue_buffer(ready_buf); } printf("."); fflush(stdout); } printf("Done.\n"); if( b_shared_mem || b_named_pipe ) { pthread_create(&stream_thread, NULL, &stream_func, NULL); while(1) { pthread_join(stream_thread, NULL); } } else { pthread_create(&capture_thread, NULL, &capture_func, NULL); } if( b_named_filename ) { usleep(200000); pthread_mutex_lock(&cond_mutex); pthread_cond_signal(&condition); pthread_mutex_unlock(&cond_mutex); usleep(200000); exit_program(SIGINT); fflush(stdout); return 0; } while( in_str[0] != 'q' ) { printf("Command (h for help): "); fflush(stdout); if( fgets(in_str, 16, stdin) == NULL ) { printf("Got NULL! Try again.\n"); continue; } switch(in_str[0]) { case 'x': pthread_mutex_lock(&cond_mutex); pthread_cond_signal(&condition); pthread_mutex_unlock(&cond_mutex); break; case 'h': printf("\nCommands:\n"); printf("\tx\tCapture a picture from camera.\n"); printf("\th\tPrints this help.\n"); printf("\tq\tQuits the program.\n"); printf("\n"); break; case 'q': case '\n': break; default: fprintf(stderr, "Unknown command %c\n", in_str[0]); break; } } /* Clean up */ exit_program(SIGINT); return 0; }