Commit 27bfeea1 authored by Nicolas Goualard's avatar Nicolas Goualard Committed by Benjamin Cabé
Browse files

mcumgr: fs_mgmt: Add a hook on download/upload complete.



Added a hook on the FS group that notify applications when a
 file download/upload has completed.

Signed-off-by: default avatarNicolas Goualard <nicolas.goualard@sfr.fr>
parent d784adbc
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -21,10 +21,10 @@ extern "C" {

/** The type of operation that is being requested for a given file access callback. */
enum fs_mgmt_file_access_types {
	/** Access to read file (file upload). */
	/** Access to read file (file download). */
	FS_MGMT_FILE_ACCESS_READ,

	/** Access to write file (file download). */
	/** Access to write file (file upload). */
	FS_MGMT_FILE_ACCESS_WRITE,

	/** Access to get status of file. */
+3 −0
Original line number Diff line number Diff line
@@ -156,6 +156,9 @@ enum fs_mgmt_group_events {
	/** Callback when a file has been accessed, data is fs_mgmt_file_access(). */
	MGMT_EVT_OP_FS_MGMT_FILE_ACCESS		= MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_FS, 0),

	/** Callback when a file upload/download is finished, data is fs_mgmt_file_access(). */
	MGMT_EVT_OP_FS_MGMT_FILE_ACCESS_DONE	= MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_FS, 1),

	/** Used to enable all fs_mgmt_group events. */
	MGMT_EVT_OP_FS_MGMT_ALL			= MGMT_DEF_EVT_OP_ALL(MGMT_EVT_GRP_FS),
};
+30 −0
Original line number Diff line number Diff line
@@ -190,9 +190,39 @@ static bool fs_mgmt_file_rsp(zcbor_state_t *zse, int rc, uint64_t off)
static void fs_mgmt_upload_download_finish_check(void)
{
	if (fs_mgmt_ctxt.len > 0 && fs_mgmt_ctxt.off >= fs_mgmt_ctxt.len) {
#if defined(CONFIG_MCUMGR_GRP_FS_FILE_ACCESS_HOOK)
		char path[CONFIG_MCUMGR_GRP_FS_PATH_LEN + 1];
		struct fs_mgmt_file_access file_access_data = {
			.filename = path,
		};
		int32_t err_rc;
		uint16_t err_group;

		strcpy(path, fs_mgmt_ctxt.path);

		switch (fs_mgmt_ctxt.state) {
		case STATE_DOWNLOAD:
			file_access_data.access = FS_MGMT_FILE_ACCESS_READ;
			break;

		case STATE_UPLOAD:
			file_access_data.access = FS_MGMT_FILE_ACCESS_WRITE;
			break;

		default:
			break;
		}
#endif

		/* File upload/download has finished, clean up */
		k_work_cancel_delayable(&fs_mgmt_ctxt.file_close_work);
		fs_mgmt_cleanup();

#if defined(CONFIG_MCUMGR_GRP_FS_FILE_ACCESS_HOOK)
		/* Warn application that file download/upload is done. */
		(void)mgmt_callback_notify(MGMT_EVT_OP_FS_MGMT_FILE_ACCESS_DONE, &file_access_data,
					   sizeof(file_access_data), &err_rc, &err_group);
#endif
	} else {
		k_work_reschedule(&fs_mgmt_ctxt.file_close_work, FILE_CLOSE_IDLE_TIME);
	}