@@ -934,7 +934,6 @@ MTP_CMD_HANDLER(MTP_OP_GET_OBJECT)
934
934
}
935
935
net_buf_add_mem (buf , ctx -> filebuf , read );
936
936
937
- ctx -> cmd = MTP_OP_GET_OBJECT ;
938
937
ctx -> filestate .total_size = filesize ;
939
938
ctx -> filestate .transferred = read ;
940
939
DEV_TO_HOST_SET_PENDING_PACKET (ctx , continue_get_object );
@@ -986,7 +985,6 @@ MTP_CMD_HANDLER(MTP_OP_SEND_OBJECT_INFO)
986
985
fs_obj -> storage_id = dest_storage_id ;
987
986
988
987
LOG_DBG ("New ObjID: 0x%08x" , fs_obj -> ID );
989
- ctx -> cmd = MTP_OP_SEND_OBJECT ;
990
988
} else {
991
989
LOG_ERR ("No file handle avaiable %u" ,
992
990
storage [dest_storage_id ].files_count );
@@ -1123,6 +1121,7 @@ static int continue_send_object(struct mtp_context* ctx, struct net_buf *buf_in)
1123
1121
fs_write (& ctx -> filestate .file , buf_in -> data , buf_in -> len );
1124
1122
LOG_DBG ("EXTRA: Data len: %u out of %u" , ctx -> filestate .transferred ,
1125
1123
ctx -> filestate .total_size );
1124
+
1126
1125
if (ctx -> filestate .transferred >= ctx -> filestate .total_size ) {
1127
1126
fs_close (& ctx -> filestate .file );
1128
1127
LOG_DBG ("Sending Confirmation after reciving data (Total len: %u)" ,
@@ -1241,16 +1240,15 @@ int mtp_commands_handler(struct mtp_context* ctx, struct net_buf *buf_in, struct
1241
1240
if (ret >= 0 ) {
1242
1241
if (ret == 1 ) {
1243
1242
ctx -> pending_fn (ctx , buf_resp );
1244
- return buf_resp -> len ;
1245
1243
}
1246
- return 0 ;
1244
+ return buf_resp -> len ;
1247
1245
} else {
1248
1246
LOG_ERR ("Failed to handle extra data" );
1249
1247
return - EINVAL ;
1250
1248
}
1251
1249
}
1252
1250
1253
- ctx -> cmd = mtp_command -> hdr .code ;
1251
+ ctx -> op_code = mtp_command -> hdr .code ;
1254
1252
LOG_DBG (GREEN "[%s]" RESET , mtp_code_to_string (mtp_command -> hdr .code ));
1255
1253
1256
1254
switch (mtp_command -> hdr .code ) {
@@ -1306,15 +1304,14 @@ int mtp_commands_handler(struct mtp_context* ctx, struct net_buf *buf_in, struct
1306
1304
return buf_resp -> len ;
1307
1305
}
1308
1306
1309
- int mtp_control_handler (struct mtp_context * ctx , uint8_t request , struct net_buf * buf )
1307
+ int mtp_control_to_host (struct mtp_context * ctx , uint8_t request , struct net_buf * const buf )
1310
1308
{
1311
1309
struct mtp_device_status_t dev_status ;
1312
- static bool canceled = false;
1313
1310
switch (request )
1314
1311
{
1315
1312
case MTP_REQUEST_GET_DEVICE_STATUS :
1316
1313
LOG_WRN ("MTP_REQUEST_GET_DEVICE_STATUS" );
1317
- if (canceled ){
1314
+ if (ctx -> op_canceled ){
1318
1315
dev_status .len = 6 ;
1319
1316
dev_status .code = MTP_RESP_TRANSACTION_CANCELLED ;
1320
1317
dev_status .epIn = 0x81 ;
@@ -1325,16 +1322,29 @@ int mtp_control_handler(struct mtp_context* ctx, uint8_t request, struct net_buf
1325
1322
dev_status .code = MTP_RESP_OK ;
1326
1323
net_buf_add_mem (buf , & dev_status , dev_status .len );
1327
1324
}
1328
- canceled = false;
1325
+
1326
+ ctx -> op_canceled = false;
1327
+ break ;
1328
+ default :
1329
+ LOG_ERR ("Unknown Host request 0x%x!" , request );
1329
1330
break ;
1330
1331
1332
+ }
1333
+
1334
+ return 0 ;
1335
+ }
1336
+
1337
+ int mtp_control_to_dev (struct mtp_context * ctx , uint8_t request , const struct net_buf * const buf )
1338
+ {
1339
+ switch (request )
1340
+ {
1331
1341
case MTP_REQUEST_CANCEL :
1332
1342
LOG_WRN ("Closing incomplete file %s" , ctx -> filestate .filepath );
1333
1343
if (strlen (ctx -> filestate .filepath ) > 0 ) {
1334
1344
fs_close (& ctx -> filestate .file );
1335
1345
1336
1346
/* Delete the opened file only when downloading from Host */
1337
- if (ctx -> cmd == MTP_OP_SEND_OBJECT ) {
1347
+ if (ctx -> op_code == MTP_OP_SEND_OBJECT ) {
1338
1348
fs_unlink (ctx -> filestate .filepath );
1339
1349
}
1340
1350
@@ -1344,7 +1354,7 @@ int mtp_control_handler(struct mtp_context* ctx, uint8_t request, struct net_buf
1344
1354
DEV_TO_HOST_SET_PENDING_PACKET (ctx , NULL );
1345
1355
HOST_TO_DEV_SET_CONT_DATA_HANDLER (ctx , NULL );
1346
1356
1347
- canceled = true;
1357
+ ctx -> op_canceled = true;
1348
1358
break ;
1349
1359
1350
1360
case MTP_REQUEST_DEVICE_RESET :
@@ -1353,7 +1363,7 @@ int mtp_control_handler(struct mtp_context* ctx, uint8_t request, struct net_buf
1353
1363
break ;
1354
1364
1355
1365
default :
1356
- LOG_ERR ("Unknown request 0x%x!" , request );
1366
+ LOG_ERR ("Unknown Dev request 0x%x!" , request );
1357
1367
break ;
1358
1368
}
1359
1369
@@ -1389,6 +1399,10 @@ static void mtp_reset(struct mtp_context* ctx)
1389
1399
storage [i ].files_count = 0 ;
1390
1400
}
1391
1401
ctx -> session_opened = false;
1402
+ ctx -> op_code = 0 ;
1403
+ ctx -> op_canceled = false;
1404
+ HOST_TO_DEV_SET_CONT_DATA_HANDLER (ctx , NULL );
1405
+ DEV_TO_HOST_SET_PENDING_PACKET (ctx , NULL );
1392
1406
}
1393
1407
1394
1408
int mtp_init (struct mtp_context * ctx , const char * manufacturer , const char * model , const char * device_version ,
0 commit comments