Skip to content

Commit

Permalink
yeet ptp_update_data_length
Browse files Browse the repository at this point in the history
  • Loading branch information
petabyt committed Oct 4, 2023
1 parent 30f8abb commit 9a13a16
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
29 changes: 8 additions & 21 deletions src/packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,14 @@ int ptp_new_data_packet(struct PtpRuntime *r, struct PtpCommand *cmd, void *data
cmd->param_length = 0;

int length = ptpusb_bulk_packet(r, cmd, PTP_PACKET_TYPE_DATA);
memcpy(ptp_get_payload(r), data, data_length);
ptp_update_data_length(r, length + data_length);
return length;

struct PtpBulkContainer *c = (struct PtpBulkContainer *)(r->data);
c->length += data_length;

// Data packets are always 12 bytes (no parameters)
memcpy(r->data + 12, data, data_length);

return length + data_length;
}

// Generate a IP or USB style command packet (both are pretty similar)
Expand All @@ -196,24 +201,6 @@ int ptp_new_cmd_packet(struct PtpRuntime *r, struct PtpCommand *cmd) {
}
}

// Update the length of the data packet after creation
// TODO: This is a bad function, should be deleted
void ptp_update_data_length(struct PtpRuntime *r, int length) {
if (r->connection_type == PTP_IP) {
struct PtpIpHeader *de = (struct PtpIpHeader*)(r->data);
if (de->type != PTPIP_DATA_PACKET_END) {
// TODO: camlib_fatal
ptp_panic("ptp_update_data_length(): didn't get data end packet");
}

// Update the packet length for the end packet
de->length = 12 + length;
} else {
struct PtpBulkContainer *bulk = (struct PtpBulkContainer*)(r->data);
bulk->length = length;
}
}

// Get data start packet, then data end packet, then response packet
static struct PtpIpResponseContainer *ptpip_get_response_packet(struct PtpRuntime *r) {
struct PtpIpStartDataPacket *ds = (struct PtpIpStartDataPacket*)(r->data);
Expand Down
2 changes: 1 addition & 1 deletion src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ int ptp_generic_send_data(struct PtpRuntime *r, struct PtpCommand *cmd, void *da
} else {
// Single data packet
plength = ptp_new_data_packet(r, cmd, data, length);
if (ptp_send_bulk_packets(r, plength + length) != plength + length) {
if (ptp_send_bulk_packets(r, plength) != plength + length) {
ptp_mutex_unlock(r);
return PTP_IO_ERR;
}
Expand Down

0 comments on commit 9a13a16

Please sign in to comment.