Commit graph

130 commits

Author SHA1 Message Date
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
5f0479762b ucm: macro - make argument names shorter
It seems that the use the macro name as the variable prefix is too large.
Use just two underscores as prefix for the macro arguments to make
macro definitions more readable.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-19 11:27:40 +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
c3a5d32ac3 ucm: add support for verb variants
The bellow configuration example creates two verbs ("HiFi" and "HiFi 7+1")
with different playback channels for the "Speaker" device.

	SectionUseCase."HiFi" {
	        File "HiFi.conf"
       		Variant."HiFi" {
			Comment "Default"
		}
		Variant."HiFi 7+1" {
			Comment "HiFi 7.1"
        	}
	}

	SectionDevice."Speaker" {
		Value {
			PlaybackChannels 2
		}
		Variant."HiFi 7+1".Value {
			PlaybackChannels 8
		}
	}

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-18 13:10:35 +02:00
Jaroslav Kysela
b45fbeee34 ucm: move macros and evali substitution to Syntax 6
There should be printed an error when the new configuration
blocks are used with the older alsa-lib.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-18 08:52:50 +02:00
Jaroslav Kysela
55340cf96a ucm: macro - add deep call protection (recursion)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-17 19:25:28 +02:00
Jaroslav Kysela
80ac6f9866 ucm: macro call inplace evaluate inside macro
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-17 19:21:22 +02:00
Jaroslav Kysela
70e2ed50a3 ucm: macro - fix the error message, print id
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-17 18:19:44 +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
d6adde0e32 ucm: top-level path - set directory from symlink
It is useful to read the top-level symlink and set the configuration
directory according this symlink for the relative paths.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-12-13 14:40:58 +01:00
Jaroslav Kysela
ea5481296f ucm: fix DeviceModifier parser
The bellow commit caused regression for the SectionModifier parser. Revert
the single line change.

Fixes: 251bc204 ("ucm: implement RenameDevice and RemoveDevice verb management")

Fixes: https://github.com/alsa-project/alsa-lib/issues/167
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-11-07 18:41:43 +01: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
76d1aa0cd7 configure: check if eaccess() is available
To fix the build error on Android:
  src/ucm/parser.c:2521:7: error: implicit declaration of function 'eaccess' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
                if (eaccess(filename, R_OK))
                    ^
  src/ucm/parser.c:2521:7: note: did you mean 'access'?

Signed-off-by: Chih-Wei Huang <cwhuang@linux.org.tw>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-14 10:10:58 +02:00
Jaroslav Kysela
e213309060 ucm: fix possible memory leak in parse_verb_file()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-03 07:30:27 +02:00
Jaroslav Kysela
225d3aecb6 ucm: libconfig - merge not override items
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-18 11:30:21 +02:00
Jaroslav Kysela
b2b3658fb9 ucm: libconfig parser - fix memory leaks
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-18 11:30:21 +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
d9658b7509 ucm: parse LibraryConfig also in the toplevel file
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-13 18:28:20 +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
Jaroslav Kysela
22dfb4bc20 ucm: limit the master config scan to conf.virt.d
The composition of the list of valid UCM cards is a bit
tricky. Scan only ucm2/conf.virt.d tree.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-22 11:47:52 +02:00
Jaroslav Kysela
f93a28730a ucm: ucm_filename() - avoid double //
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-13 17:20:01 +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
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
56c11293e3 ucm: warn about unknown sequence commands
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-11 09:26:07 +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
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
Jaroslav Kysela
0d232d714a ucm: fix two error messages
- add missing argument to error msg in if_eval_regex_match()
- print correct error value in uc_mgr_config_load_file()

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-02-03 11:57:49 +01:00
Jaroslav Kysela
437b5b3aae ucm: fix possible memory leak in parse_verb_file()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-01-07 17:32:11 +01: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
61749cf400 ucm: substitute the comment string also in the main configuration file
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-06 10:43:38 +02:00
Jaroslav Kysela
e80f35611d ucm: Handle 'Error' keyword in the master file
With the conditional blocks, it may be useful to terminate
the hardware detection from the configuration. Introduce
'Error' keyword for the master UCM configuration file.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-06 10:23:25 +02:00
Jaroslav Kysela
30d12e930c ucm: fix parse_get_safe_name() - safe name must be checked after substitution
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-07-03 14:48:18 +02:00
Jaroslav Kysela
730481ec2f ucm: simplify get_by_card() in parser.c
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-22 09:05:24 +02:00
Jaroslav Kysela
6eb78d41a1 ucm: fix use-after-free in parse_component_seq()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-08 18:17:23 +02:00
Jaroslav Kysela
9b5fde5054 ucm: remove strict: in ${OpenName} substitution
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-08 09:17:57 +02:00
Jaroslav Kysela
e1777ee1a1 ucm: fix the error path in parse_toplevel_path()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-08 09:09:39 +02:00
Jaroslav Kysela
eee879d381 ucm: implement CardIdByName substitution
The syntax is ${CardIdByName:CARDNAME[#INDEX]}.

The CARDNAME is the ALSA's soundcard name (short form).
The INDEX is the instance (0 = first, 1 = second etc.).

Example: ${CardIdByName:HDA Intel PCH}
(which is identical to ${CardIdByName:HDA Intel PCH#0})

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-03 17:17:11 +02:00
Jaroslav Kysela
3feea064dd ucm: substitute arguments in sequences only for syntax 3+
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-27 15:20:03 +02:00
Jaroslav Kysela
82d86df37f ucm: substitute RenameDevice and DeleteDevice lists
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-27 15:13:55 +02:00
Jaroslav Kysela
8d26f25ad3 ucm: substitute Comment in Transition and Device
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-27 15:04:31 +02:00
Jaroslav Kysela
8d90c4746b ucm: substitute verb name and file field
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-27 14:47:08 +02:00
Jaroslav Kysela
df498d89c7 ucm: substitute component sequence string
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-27 14:12:12 +02:00
Jaroslav Kysela
991990cdf2 ucm: substitute device strings in the device lists
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-27 14:04:13 +02:00
Jaroslav Kysela
529154fe7f ucm: substitute device / modifier names, too
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-27 13:53:10 +02:00
Jaroslav Kysela
1b0e77909d ucm: implement the toplevel ucm configuration file parser
There is a big issue to validate all possible configuration paths.
Let create ucm2/ucm.conf file which describe the lookups. It may
be also customized later to follow the kernel-side development.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-27 12:24:46 +02:00
Jaroslav Kysela
690cdab6b4 ucm: Define/DefineRegex is supported in Syntax 3
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-26 16:11:34 +02:00
Jaroslav Kysela
f688817e2c ucm: handle strict: prefix correctly for the UCM card name
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-26 16:11:32 +02:00