static CamReturn send_simple (CamResourceManager * mgr, CamSLSession * session, guint tag) { guint8 *buffer; guint offset; guint buffer_size; CamReturn ret; cam_al_calc_buffer_size (CAM_AL_APPLICATION (mgr)->al, 0, &buffer_size, &offset); buffer = g_malloc (buffer_size); ret = cam_al_application_write (CAM_AL_APPLICATION (mgr), session, tag, buffer, buffer_size, 0); g_free (buffer); return ret; }
static CamReturn send_profile_reply (CamResourceManager * mgr, CamSLSession * session) { CamReturn ret; guint8 *buffer; guint8 *apdu_body; guint buffer_size; guint offset; GList *resource_ids; guint resource_ids_size; GList *walk; resource_ids = cam_al_get_resource_ids (CAM_AL_APPLICATION (mgr)->al); resource_ids_size = g_list_length (resource_ids) * 4; cam_al_calc_buffer_size (CAM_AL_APPLICATION (mgr)->al, resource_ids_size, &buffer_size, &offset); buffer = g_malloc (buffer_size); apdu_body = buffer + offset; for (walk = resource_ids; walk != NULL; walk = walk->next) { GST_WRITE_UINT32_BE (apdu_body, GPOINTER_TO_UINT (walk->data)); apdu_body += 4; } g_list_free (resource_ids); GST_DEBUG ("sending profile reply"); ret = cam_al_application_write (CAM_AL_APPLICATION (mgr), session, TAG_PROFILE_REPLY, buffer, buffer_size, resource_ids_size); g_free (buffer); return ret; }
CamResourceManager * cam_resource_manager_new () { CamALApplication *application; CamResourceManager *mgr; mgr = g_new0 (CamResourceManager, 1); application = CAM_AL_APPLICATION (mgr); _cam_al_application_init (application); application->resource_id = CAM_AL_RESOURCE_MANAGER_ID; application->session_request = session_request_impl; application->open = open_impl; application->close = close_impl; application->data = data_impl; return mgr; }
CamApplicationInfo * cam_application_info_new (void) { CamApplicationInfo *info; CamALApplication *application; info = g_new0 (CamApplicationInfo, 1); application = CAM_AL_APPLICATION (info); _cam_al_application_init (application); application->resource_id = CAM_AL_APPLICATION_INFO_ID; application->session_request = session_request_impl; application->open = open_impl; application->close = close_impl; application->data = data_impl; return info; }
void cam_resource_manager_destroy (CamResourceManager * mgr) { _cam_al_application_destroy (CAM_AL_APPLICATION (mgr)); g_free (mgr); }
void cam_application_info_destroy (CamApplicationInfo * info) { _cam_al_application_destroy (CAM_AL_APPLICATION (info)); g_free (info); }
gboolean cam_device_open (CamDevice * device, const char *filename) { ca_caps_t ca_caps; int ret; int i; int count = 10; g_return_val_if_fail (device != NULL, FALSE); g_return_val_if_fail (device->state == CAM_DEVICE_STATE_CLOSED, FALSE); g_return_val_if_fail (filename != NULL, FALSE); GST_INFO ("opening ca device %s", filename); ret = open (filename, O_RDWR); if (ret == -1) { GST_ERROR ("can't open ca device: %s", strerror (errno)); return FALSE; } GST_DEBUG ("Successfully opened device %s", filename); device->fd = ret; ret = ioctl (device->fd, CA_RESET); g_usleep (G_USEC_PER_SEC / 10); while (TRUE) { /* get the capabilities of the CA */ ret = ioctl (device->fd, CA_GET_CAP, &ca_caps); if (ret == -1) { GST_ERROR ("CA_GET_CAP ioctl failed: %s", strerror (errno)); reset_state (device); return FALSE; } if (ca_caps.slot_num > 0) break; if (!count) { GST_ERROR ("CA_GET_CAP succeeded but not slots"); reset_state (device); return FALSE; } count--; g_usleep (G_USEC_PER_SEC / 5); } device->tl = cam_tl_new (device->fd); device->sl = cam_sl_new (device->tl); device->al = cam_al_new (device->sl); device->mgr = cam_resource_manager_new (); cam_al_install (device->al, CAM_AL_APPLICATION (device->mgr)); device->info = cam_application_info_new (); cam_al_install (device->al, CAM_AL_APPLICATION (device->info)); device->cas = cam_conditional_access_new (); cam_al_install (device->al, CAM_AL_APPLICATION (device->cas)); /* open a connection to each slot */ for (i = 0; i < ca_caps.slot_num; ++i) { CamTLConnection *connection; ret = cam_tl_create_connection (device->tl, i, &connection); if (CAM_FAILED (ret)) { /* just ignore the slot, error out later only if no connection has been * established */ GST_WARNING ("connection to slot %d failed, error: %d", i, ret); continue; } } if (g_hash_table_size (device->tl->connections) == 0) { GST_ERROR ("couldn't connect to any slot"); reset_state (device); return FALSE; } device->state = CAM_DEVICE_STATE_OPEN; device->filename = g_strdup (filename); /* poll each connection to initiate the protocol */ cam_tl_read_all (device->tl, TRUE); return TRUE; }