Commit graph

125 commits

Author SHA1 Message Date
Jaroslav Kysela
70f4c95df5 ucm: remove @@LibraryVersion and @@SyntaxVersion variables
It seems that version checking is more complicated:

Syntax is one-way settlement from the configuration files.
It cannot be conditional.

The library version string is hard to check with regex.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2025-03-21 11:26:32 +01:00
Jaroslav Kysela
e9e3c01ff7 ucm: format @@SyntaxVersion to 4 digits
It is better for regex matching.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2025-03-19 12:20:27 +01:00
Jaroslav Kysela
12f6790910 ucm: add @@LibraryVersion and @@SyntaxVersion variables
It may be useful to check the current syntax version (and maybe
library version) when new features are added.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2025-03-19 11:54:50 +01:00
Jaroslav Kysela
8883943995 ucm: main - remove cast to pointer from integer of different size warning
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-09-01 16:50:51 +02:00
borine
cde0e819f7 doxygen: ucm: silence warnings
Removes duplicate documentation blocks and fixes 'not documented' warnings

From: borine@github
Link: https://github.com/alsa-project/alsa-lib/pull/340
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-09-01 16:12:10 +02:00
borine
9505cfdb46 doxygen: fix broken parameter name tags
From: borine@github
Link: https://github.com/alsa-project/alsa-lib/pull/340
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-09-01 16:10:55 +02:00
Jaroslav Kysela
496c4e031b ucm: fix geti() macro - return zero on success
Fixes: c083417b ("ucm: simplify and fix the previous patch (geti)")
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-01-15 18:57:56 +01:00
Jaroslav Kysela
c083417b72 ucm: simplify and fix the previous patch (geti)
Use macro to maintain only one code. The status may be 0 or 1 - handle
both values correctly.

Also, fix the possible memory leak in snd_use_case_geti() - string
str should be freed even when the error is returned.

Fixes: 436cd5b6 ("ucm: add existence checks to geti calls")
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-01-15 18:37:40 +01:00
Curtis Malainey
436cd5b6d0 ucm: add existence checks to geti calls
Right now in snd_use_case_geti you cannot tell if the item being queried
exists or not when being checked. This also means the only way to check
for the existence of something in the client of the library is to
iterate over the list of mods/devs even if we know exactly the name we
are looking for. We have functions that do exactly this internally so
lets return this information in a logical fashion through geti.

Also clean up some trailing white space nearby.

Signed-off-by: Curtis Malainey <cujomalainey@chromium.org>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-01-15 17:57:13 +01:00
Jaroslav Kysela
d25ddafaa7 ucm: fix possible memory leak in execute_sysw()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-01-05 15:42:31 +01:00
Jaroslav Kysela
e29413a220 ucm: execute_sysw - fix possible use-after-free
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-12-07 14:51:32 +01:00
Jaroslav Kysela
8b64f22459 ucm: clarify set_defaults calls
- do full reset in snd_use_case_mgr_reload

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-11-15 17:28:39 +01:00
Jaroslav Kysela
1b436862ed ucm: fix enhanced ID parsing in snd_use_case_parse_ctl_elem_id()
Reported-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-11-02 15:01:58 +01:00
Jaroslav Kysela
d80616c0c1 ucm: add NULL check for card_name in open
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-07-08 22:00:34 +02:00
Jaroslav Kysela
fc86eafa08 ucm: fix few memory-leaks in the error paths
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-07-08 21:56:57 +02:00
Jaroslav Kysela
0418fd32c7 ucm: fix the reload call (snd_use_case_mgr_reload)
Handle the local configuration and macros trees properly.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-27 14:28:23 +02:00
Jaroslav Kysela
4119e33d28 ucm: implement disdevall sequence command
It is useful to run all disable sequences for all
UCM devices in a verb to ensure the valid, expected
initial state.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-24 16:28:23 +02:00
Jaroslav Kysela
edec439a0c ucm: Use LFS calls (stat, scandir)
Continue the work in commit ba86ac55 ("conf: Use LFS calls when reading
config files") and fix the UCM code, too.

Fixes: https://github.com/alsa-project/alsa-lib/pull/223
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-20 09:55:03 +02:00
Jaroslav Kysela
87034d6fc6 ucm: main - fix the compilation error (signess)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-20 09:23:17 +02:00
Jaroslav Kysela
4b66e5fbce ucm: implement enadev2 and disdev2 sequence commands
It may be useful to call the sequences from devices from
the verb sequences or another device sequences.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-19 10:08:50 +02:00
Jaroslav Kysela
11ec9e497e ucm: allow passing variables through ucm open string
It is useful to pass information like application capabilities
to the UCM configuration parser. Those variables are prefixed
with '@' for the configuration files.

An example:

   "<<<v1='a b c',x=12>>>hw:1"

Variables can substituted in the configuration:

   "${var:@v1}" -> "a b c"
   "${var:@x}" -> 12

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-16 14:17:31 +02:00
Jaroslav Kysela
d7d5c724ed ucm: implement MacroDefine and Macro subtree evaluation
The arguments are set as temporary variables as /MACRO_NAME/_/ARGUMENT_NAME/.

Example:

  # define new macro MyMacro with arguments ctl_name and ctl_value
  DefineMacro.MyMacro {
    BootSequence [
      cset "name='${var:MyMacro_ctl_name}' ${var:MyMacro_ctl_value}"
    ]
  }

  # instantiate macro for Speaker control (short version)
  Macro.headphone.MyMacro "ctl_name='Speaker Switch',ctl_value=off"

  # instantiate macro for Mic control (second version)
  Macro.mic.MyMacro {
	ctl_name "Mic Switch"
	ctl_value "off"
  }

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-13 17:25:29 +02:00
Jaroslav Kysela
23198a72cd ucm: suppress the no device (no UCM card) errors on request
It seems that users are confused when the UCM configuration
is not ready for the particular hardware. Actually, we don't
allow a fine grained message classification in alsa-lib and
UCM API. Allow suppression of this specific type of messages
on the application request (typically alsactl).

BugLink: https://github.com/alsa-project/alsa-utils/issues/111
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-10-28 11:52:08 +02:00
Chih-Wei Huang
01960fa856 ucm: include sys/wait.h to fix build on Android
src/ucm/main.c:788:8: error: implicit declaration of function 'WIFSIGNALED' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
                        if (WIFSIGNALED(err)) {
                            ^
    src/ucm/main.c:790:10: error: implicit declaration of function 'WIFEXITED' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
                        } if (WIFEXITED(err)) {
                              ^
    src/ucm/main.c:791:34: error: implicit declaration of function 'WEXITSTATUS' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
                                if (ignore_error == false && WEXITSTATUS(err) != 0) {

Signed-off-by: Chih-Wei Huang <cwhuang@linux.org.tw>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-14 10:10:02 +02:00
Jaroslav Kysela
200d18cda7 ucm: fix error path in execute_cfgsave()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-02 19:51:13 +02:00
Jaroslav Kysela
9621d0bff2 ucm: fix _alibpref string (add '.' delimiter to the end)
Fixes: 0e4ba2ea ("ucm: add _alibpref to get the private device prefix")
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-02 11:21:54 +02:00
Jaroslav Kysela
0e4ba2ea8c ucm: add _alibpref to get the private device prefix
It may be useful to get the device prefix for the local configuration.

Link: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/1251
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-02 11:09:46 +02:00
Jaroslav Kysela
3fd1de5cbe ucm: recognize first '-' character as ignore error for exec/shell
It may be useful to ignore the returned errors (like modprobe etc).

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-18 16:37:17 +02:00
Jaroslav Kysela
0ee4642a69 ucm: cfg-save - allow to save the sub-tree including root keys
The leading '+' in the keys specification add the key prefix
(sub-tree root identification) to the saved configuration.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-18 12:33:43 +02:00
Jaroslav Kysela
5e7c507152 ucm: add cfg-save command
Allow to save whole (or partial) local UCM alsa library configuration
to a file.

Syntax (saves key1.key2 sub-tree):

	Sequence [
		cfg-save "/tmp/my-file.conf:key1.key2"
	]

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-17 16:49:46 +02:00
Jaroslav Kysela
f821f09727 ucm: fix memory leak in execute_cset()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-14 12:49:14 +02:00
Jaroslav Kysela
590df3a5b1 ucm: add exec sequence command
This change renames the original exec command to shell which
is more appropriate. Implement a light version of the exec
command which calls directly the specified executable without
the shell interaction (man 3 system).

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-12 08:32:45 +02:00
Hans de Goede
06543e06e9 ucm: Fix sysw sequence command not working when requesting to ignore errors
When the user requests to ignore sysfs write errors by prefixing
the path with a '-' then we need to skip the '-' when building the
actual path otherwise the write will never work.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-04 10:36:22 +02:00
Jaroslav Kysela
447a676ee5 ucm: add missing uc_mgr_card_close() call to snd_use_case_mgr_open()
Handle the error path correctly.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-15 16:58:29 +02:00
Jaroslav Kysela
8e097fd14a ucm: rewrite device value only when the local config exists
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-15 11:38:39 +02:00
Jaroslav Kysela
c83ddd8e56 ucm: return error if fixedboot_list is empty
The application should know, that there is no special
initialization sequence. It's counterpart for
"ucm: return error if boot_list is empty".

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-13 19:13:20 +02:00
Hui Wang
2368a95b8f ucm: return error if boot_list is empty
If bootlist is empty, that means there is no BootSequence defined
in the ucm for this sound card, let set_boot_user() return error,
then alsactl could have chance to use non-ucm ways to initialize the
sound card.

BugLink: https://github.com/alsa-project/alsa-lib/pull/94
Signed-off-by: Hui Wang <hui.wang@canonical.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-13 19:12:35 +02:00
Jaroslav Kysela
7e4390137a ucm: handle better the system() call
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-13 17:14:30 +02:00
Jaroslav Kysela
8f5779eb3f ucm: add LibraryConfig support
This commit allows to define private alsa-lib's configuration. When
the configuration is present, the device values ("PlaybackCTL",
"CaptureCTL", "PlaybackMixer", "CaptureMixer", "CapturePCM")
are prefixed with '_ucmHEXA.' string where HEXA is replaced by the
unique hexadecimal number identifying the opened ucm manager handle.

    Syntax 4

    LibraryConfig.a_label.SubstiConfig {
            # substituted library configuration like:
            usr_share_dir "${ConfLibDir}"
    }

    LibraryConfig.b_label.Config {
            # non-substituted library configuration like:
            usr_share_dir "/usr/share/alsa"
    }

    The File counterparts:

    LibraryConfig.c_label.SubstiFile "/some/path"
    LibraryConfig.d_label.File "/some/path"

Note that for files the contents is substituted on the request,
but the file name is always substituted (useful for ${ConfDir} etc.).

The private configuration is not saved or preserved. It's life time
belongs to the opened ucm manager handle.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-13 17:14:28 +02:00
Jaroslav Kysela
3cfbacdc34 ucm: add ctl-remove sequence command to delete controls from UCM
Syntax:

   ctl-remove "name='ABCD'"

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-29 11:31:08 +02:00
Jaroslav Kysela
02423dc970 ucm: add cset-new sequence command to create new controls from UCM
This command create a new control using ID, description and value.

Syntax:

    cset-new "name='ABCD',index=2 type=boolean,count=2 on,on"
    cset-new "name='Enum' type=enum,labels='L1;L2;L3' 'L2'"

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-29 11:00:25 +02:00
Jaroslav Kysela
b0b9e4b88d ucm: move __snd_ctl_ascii_elem_id_parse prototype to control_local.h
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-25 20:40:22 +01:00
Jaroslav Kysela
0afa61e8f0 ucm: rename sysset to sysw
Fixes: 1c6fb202 ("ucm: implement sysset sequence command")
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-23 11:40:30 +01:00
Jaroslav Kysela
1c6fb20232 ucm: implement sysset sequence command
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-11 09:26:07 +01:00
Jaroslav Kysela
2b418648cf ucm: ucm_main.c - cosmetic tab cleanups
This file is problematic for the git's tab checker.
The unexpand tool is used to convert initial spaces
to tabs.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-11 09:26:07 +01:00
Jaroslav Kysela
9c194a0ba7 ucm: add _fboot / FixedBootSequence
Actually, the BootSequence is executed only when the driver controls
(identifiers or value types) are changed. It may be handy to have
also a sequence which is executed at _each_ boot without any condition.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-11 09:25:52 +01:00
Alex Henrie
0f4821ec17 ucm: fix bad frees in get_list0 and get_list20
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2020-12-27 09:21:55 +01:00
Jaroslav Kysela
d77fb47318 ucm: handle correctly Linked configuration
BugLink: https://github.com/alsa-project/alsa-ucm-conf/issues/54
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-19 10:52:13 +02:00
Jaroslav Kysela
2b217b7010 ucm: rename once_list to boot_list
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-06 10:47:11 +02:00
Jaroslav Kysela
22d5ca8b6b ucm: add a check for the empty configuration
Return an error if the UCM configuration is empty (no verbs
or no boot sequence).

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-06 10:43:13 +02:00