static void send_ca_pmt (CamSwClient * client, GstStructure * pmt, guint8 list_management, guint8 cmd_id) { guint8 *buffer; guint buffer_size; guint8 *ca_pmt; guint ca_pmt_size; guint length_field_len; guint header_len; ca_pmt = cam_build_ca_pmt (pmt, list_management, cmd_id, &ca_pmt_size); length_field_len = cam_calc_length_field_size (ca_pmt_size); header_len = 3 + length_field_len; buffer_size = header_len + ca_pmt_size; buffer = g_malloc0 (buffer_size); memcpy (buffer + header_len, ca_pmt, ca_pmt_size); /* ca_pmt resource_id */ buffer[0] = 0x9F; buffer[1] = 0x80; buffer[2] = 0x32; cam_write_length_field (&buffer[3], ca_pmt_size); if (write (client->sock, buffer, buffer_size) == -1) { GST_WARNING ("write failed when sending pmt with errno: %d", errno); } g_free (ca_pmt); g_free (buffer); }
/* write the header of a TPDU * NOTE: this function assumes that the buffer is large enough to contain the * complete TPDU (see cam_tl_calc_buffer_size ()) and that enough space has been * left from the beginning of the buffer to write the TPDU header. */ static CamReturn cam_tl_connection_write_tpdu (CamTLConnection * connection, guint8 tag, guint8 * buffer, guint buffer_size, guint body_length) { int sret; CamTL *tl = connection->tl; guint8 length_field_len; /* slot number */ buffer[0] = connection->slot; /* connection number */ buffer[1] = connection->id; /* tag */ buffer[2] = tag; /* length can take 1 to 4 bytes */ length_field_len = cam_write_length_field (&buffer[3], body_length); buffer[3 + length_field_len] = connection->id; GST_DEBUG ("writing TPDU %x (%s) connection %d (size:%d)", buffer[2], tag_get_name (buffer[2]), connection->id, buffer_size); //cam_gst_util_dump_mem (buffer, buffer_size); sret = write (tl->fd, buffer, buffer_size); if (sret == -1) { GST_ERROR ("error witing TPDU (%d): %s", errno, g_strerror (errno)); return CAM_RETURN_TRANSPORT_ERROR; } tl->expected_tpdus += 1; GST_DEBUG ("Sucess writing tpdu 0x%x (%s)", buffer[2], tag_get_name (buffer[2])); return CAM_RETURN_OK; }