Skip to content

Instantly share code, notes, and snippets.

@jriguera
Last active May 30, 2020 22:36
Show Gist options
  • Save jriguera/badd55e27e814a16e204 to your computer and use it in GitHub Desktop.
Save jriguera/badd55e27e814a16e204 to your computer and use it in GitHub Desktop.
NCID on raspberry pi (arch linux)
# Install compile requirements
pacman -S gcc make
# Install lib requirements for ncid
pacman -S libpcap
# Download
curl http://heanet.dl.sourceforge.net/project/ncid/ncid/1.2/ncid-1.2-src.tar.gz -o ncid-1.2-src.tar.gz
# Compile
tar -zxvf ncid-1.2-src.tar.gz
cd ncid
make local
make install
# Setup systemd unit service
cat <<EOF >/etc/systemd/system/ncidd.service
[Unit]
Description=NCID server
After=network.target
[Service]
Type=forking
Environment=prog=ncidd
PIDFile=/var/run/ncidd.pid
ExecStart=/usr/local/sbin/ncidd --pidfile /var/run/ncidd.pid -C /etc/ncid/ncidd.conf
ExecReload=/usr/bin/pkill --signal SIGHUP ncidd
ExecStop=/usr/bin/pkill ncidd
RestartSec=1min
Restart=always
StartLimitInterval=5min
StartLimitBurst=4
[Install]
WantedBy=multi-user.target
EOF
# Enable and start the service
systemctl enable ncidd
systemctl start ncidd
# Create links
ln -s /usr/local/etc/ncid /etc/ncid
ln -s /usr/local/etc/logrotate.d/ncid /etc/logrotate.d/ncid
# Setup configuration file
cat <<EOF > /etc/ncid/ncidd.conf
# NCID - Network CallerID Server Config File
# File last changed: Sep 20, 2015
################################
# Definitions and Line formats #
################################
# lines can be blank, or start with the words: send, set #
#
# A line is divided into words, separated by spaces
#
# A word is either a string of non-blank characters, everything
# between double quotes, or an equal sign.
#
# SEND LINE FORMAT:
# send DATATYPE [DATATYPE] ...
# where DATATYPE = cidlog, cidinfo
#
# SET LINE FORMAT:
# set ITEM = VALUE [ITEM = VALUE] ...
# where ITEM = announce, audiofmt, blacklist, cidalias, cidlog,
# cidlogmax, cidname, datalog, gencid,
# hangup, ignore1, initcid, initstr,
# lineid, lockfile, nomodem, noname,
# noserial, pickup, pidfile, port, send,
# ttyclocal, ttyport, ttyspeed,
# verbose, whitelist
##########################
# Log file verbose level #
##########################
# Set the verbose level
# The default value is 1, the range is 1-7
# verbose levels 8 and 9 are only for the command line
set verbose = 3
############################
# Log and Info for Clients #
############################
# Send the call log to a client when connected
# The default is not to send the call log file
send cidlog
# Send call info (LINE and RING) to a client at each ring
# The default is not to send the call info line
send cidinfo
#####################
# NCID Network Port #
#####################
# The default TCP/IP port is 3333
# set port = 3334
set port = 3333
############################
# PID, Alias and Log Files #
############################
# Set pidfile to /var/run/ncidd.pid in rc and init scripts
# The default is no PID file
set pidfile = /var/run/ncidd.pid
# If NCID is installed into
# /usr: The default CID alias file: /etc/ncid/ncidd.alias
# /usr/local: The default CID alias file: /usr/local/etc/ncid/ncidd.alias
# set cidalias = /usr/etc/ncid/ncidd.alias
set cidalias = /etc/ncid/ncidd.alias
# An alias that includes a telephone number depends on the number
# received from a call. In the US, a leading 1 is not always part
# of the telephone number. For instance, Vonage always includes
# the 1 on incoming calls but on outgoing calls the 1 is optional.
# If the ignore1 option is set, a leading 1 is not included in an
# alias definition.
# ignore1 = 0 default: the leading 1 may or may not be in a call
# ignore1 = 1 ignore the leading 1 if it is in a call
set ignore1 = 0
# The default CID call log file: /var/log/cidcall.log
# (also make the change in /etc/logrotate.d/ncidd
# and also /etc/ncid/ncidrotate.conf)
set cidlog = /var/log/cidcall.log
# Set the maximum size in bytes for the CID log file
# The default is 110,000 bytes and the maximum is 100,000,000
# Do not include commas when setting cidlogmax
# set cidlogmax = 500000
# The default tty data log file: /var/log/ciddata.log
# the log file must exist, ncidd will not create it
# (also make the change in /etc/logrotate.d/ncidd
# and also /etc/ncid/ncidrotate.conf)
set datalog = /var/log/ciddata.log
############################
# Telephone Line Indicator #
############################
# Set the line indicator if you want it displayed for the modem.
# or if you have more than one telephone line. The default value
# for lineid is '-' and is not displayed. Setting it to any other
# value will display it.
#
# You can set lineid to 'POTS' (Plain Old Telephone Service) to
# have it displayed or the last 4 digits of your number if you
# have more than one telephone line.
# lineid default: -
# set lineid = POTS
################################
# Generate a generic Caller ID #
################################
# Generate a generic Caller ID at ring 2 if one is not received
# from the modem either because the telco is not sending it or
# because the modem does not support it. This feature requires
# the modem to indicate each time the modem rings.
# gencid = 0 never generate a generic Caller ID
# gencid = 1 default: generate a generic Caller ID when needed
set gencid = 0
#############################
# CID NAME sent or not sent #
#############################
# If your Telco does not send a name with the Caller ID, you can
# configure ncidd to receive a CID without a name so it does not
# need to wait until ring 2 to determine that no name was sent.
# WARNING: if this option is set and a name is sent, it is ignored
# cidnoname = 0 default: CID does contain a name
# cidnoname = 1 CID does not contain a name
set cidnoname = 1
#########################
# Automatic Call Hangup #
#########################
# The automatic call hangup requires a modem to hangup the call,
# but works if ncidd is using either a modem or gateway to obtain
# the Caller ID information.
#
# hangup = 0 Default: do not terminate a call
# set hangup = 0
#
##################################################################
# Set hangup to a 1 if you would like ncidd to terminate a
# call that has its name or number in a blacklist file but
# not in a whitelist file.
#
# hangup = 1 terminate the call
set hangup = 1
##################################################################
# Set hangup to a 2 if you would like ncidd to pickup and generate
# FAX tones before terminating a call that has its name or number
# in a blacklist file but not in a whitelist file. Not all modems
# support FAX. If FAX is not supported the server will switch to
# "hangup = 1" and generate a warning in the server log file.
#
# hangup = 2 generate FAX tones, then terminate the call
#set hangup = 2
# Modems that support FAX normally in require a pickup command before
# sending the FAX command to start the FAX tones. Some older modems
# will not generate FAX tones if a pickup command is sent. If no FAX
# tones are heard, do not send the pickup command.
#
# pickup = 1 Default: send the pickup command
# pickup = 0 do not send the pickup command
set pickup = 0
# If NCID is installed into
# /usr: The default blacklist file: /etc/ncid/ncidd.blacklist
# /usr/local: The default blacklist file: /usr/local/etc/ncid/ncidd.blacklist
set blacklist = /etc/ncid/ncidd.blacklist
# If NCID is installed into
# /usr: The default whitelist file: /etc/ncid/ncidd.whitelist
# /usr/local: The default whitelist file: /usr/local/etc/ncid/ncidd.whitelist
set whitelist = /etc/ncid/ncidd.whitelist
# The blacklist and whitelist files normally use simple expressions
# to match on a Caller ID but full regular expressions can be used
# https://en.wikipedia.org/wiki/Regular_expression
# regex = 0 Default: do not use regular expressions
# regex = 1 use regular expressions
set regex = 1
##################################################################
# Set hangup to a 3 if you would like to play an announcement
# before terminating a call that has its name or number
# in a blacklist file but not in a whitelist file. Not all modems
# support VOICE. If VOICE is not supported the server will switch
# to "hangup = 1" and generate a warning in the server log file.
#
# hangup = 3 play an announcement then terminate the call
#set hangup = 3
# If NCID is installed into /usr
# Default announce file: /usr/share/ncid/NumberDisconnected.rmd
# If NCID is installed into /usr/local
# Default announce file: /usr/local/share/ncid/NumberDisconnected.rmd
#
# The default announce file: 8-bit unsigned PCM at a 8000 Hz sample rate
set announce = /usr/local/share/ncid/happy.wav
# Set the audio data format to one of the Modem Sampling Methods
# returned by the modem command: AT+VSM=?
#
# The default announce file expects:
# Manufacturer: CONEXANT
# Modem Identifier: CX93001-EIS_V0.2013-V92
# NOTE: only CX93001 is important the rest of the line can change
# Modem Sampling Method: 130,"UNSIGNED PCM",8,0,8000,0,0
# Modem Sampling Method slected: 130
#
# The default announce file will also work with:
# Manufacturer: U.S. Robotics
# Modem Identifier: U.S. Robotics 56K FAX USB V1.2.23
# NOTE: the version must be v1.2.23 or later
# Modem audio data formats: 128,"8-BIT LINEAR",(7200,8000,11025)
# Modem audio data format slected: 128,8000
#
# default: audiofmt = "AT+VSM=130" # CONEXANT
# set audiofmt = "AT+VSM=128,8000" # U.S. Robotics
set audiofmt = "AT+VSM=129"
#######################
# Serial or No Serial #
#######################
# Normally a serial device is required to capture CID information.
# If you are using one or more gateways and do not have a serial
# device, set noserial to 1.
# If noserial is set to 1 and hangup is set to 0, the TTY Configuration,
# Modem, and Modem Initialization set commands are not used.
# NETWORK AND NO SERIAL: noserial = 1 (do not use a serial port)
# SERIAL AND NETWORK: noserial = 0 (default - use a serial port)
# set noserial = 1
###################################################################
## NOTE: if noserial is set to 1 and hangup is set to 0, nothing ##
## needs to be configured beyond this point. ##
###################################################################
#####################
# TTY Configuration #
#####################
## Required if noserial is set to 0 or hangup is set to 1
# The default tty port: /dev/modem (general build)
# /dev/com1 (cygwin build )
# /def/ttyACM0 (fedora, redhat, ubuntu builds)
# set ttyport = /dev/cu.modem # default Mac OS X internal modem
# set ttyport = /dev/cu.usbmodem246802461 # Mac OS X USB modem (DualComm, Zoom)
# set ttyport = /dev/ttyS0 # Linux Serial Port 0
set ttyport = /dev/ttyACM0 # Linux USB modem 0
# The default tty port speed: 115200
# The tty speed can be one of: 115200, 38400, 19200, 9600, 4800
# set ttyspeed = 4800 # NetCallerID port speed
# set ttyspeed = 9600 # TCI serial device port speed
# Ignore tty control signals for internal modems and 3 wire serial cables
# Disable tty control signals: ttyclocal = 1
# Enable tty control signals: ttyclocal = 0 (default)
set ttyclocal = 1
# The lockfile name is generated automatically for the following distributions
# when tty port is /dev/modem:
# Fedora : /var/lock/lockdev/LCK..modem
# FreeBSD: /var/spool/lock/LCK..modem
# Mac : /var/spool/uucp/LCK..modem
# Ubuntu : /var/lock/LCK..modem
#
# The default lockfile name when not build to a distribution
# and the tty port is /dev/modem:
# Default: /var/lock/LCK..modem
#
# You can also set the lockfile manually for a OS not distributed
# when tty port is /dev/modem:
# Debian : /var/lock/LCK..modem
#
# set lockfile = /var/lock/lockdev/LCK..ttyS0
set lockfile = /var/lock/LCK..ttyACM0
#####################
# Modem or No Modem #
#####################
# Obtain CallerID from a CID device or a modem
# The NetCallerID device is not a modem
# DEVICE: nomodem = 1 (do not send AT commands)
# MODEM: nomodem = 0 (default - send AT commands)
# set nomodem = 1
########################
# Modem Initialization #
########################
# initstr is required if noserial is set to 0 and nomodem is set to 0
# or hangup is set to 1
# see http://www.modemhelp.org for help with init strings
# The default modem initialization is: "AT Z S0=0 E1 V1 Q0"
# set initstr = "ATE1V1Q0"
#
# If minicom can talk to the modem but ncidd fails, use the Minicom init string
# Minicom initialization string is "AT S7=45 S0=0 L1 V1 X4 &c1 E1 Q0"
# set initstr = "ATS7=45S0=0L1V1X4&c1E1Q0"
#
# Alternate modem initialization string
# set initstr = "AT&FE1V1Q0+VIP"
# Modem initialization string for the Mac Motorola UbiSoft modem
# set initstr = "AT+FCLASS=8;+VCID=1" # default Mac OS X internal modem
# Modem initialization string for the US Robotics 5637, v.92 56k USB modem
# set initstr = "ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0"
# The U.S.Robotics USR5631 56K Faxmodem has a +GCI command to set the
# country code to adjust parameters for a particular telephone network
# (perhaps other modems do also). See the following on how to set +GCI
# Addon strings to set modem for Distinctive Ring:
# http://www.modemsite.com/56k/dring.asp
#
# 3Com/USR/TI chipset: ATS41=1
# Reported Ring Codes: RING A, RING B, RING C
# Rockwell/Conexant chipset: AT-SDR=7
# Reported Ring Codes: RING 1, RING 2, RING 3
# Also reported DROF/DRON messages instead of ring codes
# Lucent/Agere chipset: AT+VDR=1,0
# Reported DROF/DRON messages: DRON=5 DROF=11, DRON=5 DROF=34
#
# Example adds 3Com DR to the default modem initialization
# set initstr = "ATE1V1Q0S41=1"
# initcid is not required if noserial is set to 0 and hangup is set to 1
# The default for ncidd is to try two CID strings to setup
# CallerID: "AT+VCID=1" and if that fails: "AT#CID=1".
# set initcid = "AT#CID=1"
#
# Alternate CID strings to try if default does not work:
# set initcid = "AT+FCLASS=8;+VCID=1"
# set initcid = "AT-STE=1;+VCID=1"
# set initcid = "AT-STE=1;#CID=1"
# CID init string to skip sending any CID string to modem
# Useful if NCID is used only as a visual call indicator
# set initcid = ""
#
# CID string for the Conexant Systems (Rockwell) when using
# Distinctive Ring and missing calls that give a DDN_NMBR
# instead of NMBR:
# set initcid = "AT+VDR=1,0;E1V1Q0S24=0"
#
# CID init string for a particular country (example shows B5 for the US
# See the incomplete Country Code lists at
# http://ncid.sourceforge.net/doc/NCID_Documentation.html#modems_top
# set initcid = "ATE1V1Q0+GCI=A0"
# Modem: http://www.banggood.com/Wholesale-2-Ports-USB-56K-External-Dial-Up-Data-Voice-Fax-Modem-V9092-Win7-3264-Bit-XP-p-49497.html
# Info: ID 0572:1340 Conexant Systems (Rockwell), Inc.
# Docs: http://ncid.sourceforge.net/doc/NCID_Documentation.html#modems_top
#set initcid = "AT+VCID=1;+GCI=?;+MS?"
set initcid = "ATE1V1Q0+GCI=A0;+VCID=1"
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment